@@ -159,14 +159,29 @@ func generateCreateTableSQLForNormalizedTable(
159159 }
160160
161161 var engine string
162- if tableMapping == nil {
162+ tmEngine := protos .TableEngine_CH_ENGINE_REPLACING_MERGE_TREE
163+ if tableMapping != nil {
164+ tmEngine = tableMapping .Engine
165+ }
166+ switch tmEngine {
167+ case protos .TableEngine_CH_ENGINE_REPLACING_MERGE_TREE :
163168 engine = fmt .Sprintf ("ReplacingMergeTree(%s)" , peerdb_clickhouse .QuoteIdentifier (versionColName ))
164- } else if tableMapping . Engine == protos .TableEngine_CH_ENGINE_MERGE_TREE {
169+ case protos .TableEngine_CH_ENGINE_MERGE_TREE :
165170 engine = "MergeTree()"
166- } else if tableMapping .Engine == protos .TableEngine_CH_ENGINE_NULL {
171+ case protos .TableEngine_CH_ENGINE_REPLICATED_REPLACING_MERGE_TREE :
172+ engine = fmt .Sprintf (
173+ "ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/{database}/%s','{replica}',%s)" ,
174+ peerdb_clickhouse .EscapeStr (tableIdentifier ),
175+ peerdb_clickhouse .QuoteIdentifier (versionColName ),
176+ )
177+ case protos .TableEngine_CH_ENGINE_REPLICATED_MERGE_TREE :
178+ engine = fmt .Sprintf (
179+ "ReplicatedMergeTree('/clickhouse/tables/{shard}/{database}/%s','{replica}',%s)" ,
180+ peerdb_clickhouse .EscapeStr (tableIdentifier ),
181+ peerdb_clickhouse .QuoteIdentifier (versionColName ),
182+ )
183+ case protos .TableEngine_CH_ENGINE_NULL :
167184 engine = "Null"
168- } else {
169- engine = fmt .Sprintf ("ReplacingMergeTree(%s)" , peerdb_clickhouse .QuoteIdentifier (versionColName ))
170185 }
171186
172187 // add sign and version columns
@@ -179,7 +194,7 @@ func generateCreateTableSQLForNormalizedTable(
179194 orderByColumns = append ([]string {sourceSchemaColName }, orderByColumns ... )
180195 }
181196
182- if tableMapping == nil || tableMapping . Engine != protos .TableEngine_CH_ENGINE_NULL {
197+ if tmEngine != protos .TableEngine_CH_ENGINE_NULL {
183198 if len (orderByColumns ) > 0 {
184199 orderByStr := strings .Join (orderByColumns , "," )
185200
0 commit comments