Skip to content

Commit e63b71d

Browse files
authored
engines: ReplicatedReplacingMergeTree, ReplicatedMergeTree (#2949)
1 parent 49ffca1 commit e63b71d

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

flow/connectors/clickhouse/normalize.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

flow/shared/clickhouse/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"go.temporal.io/sdk/log"
1313
)
1414

15-
var acceptableTableEngines = []string{"ReplacingMergeTree", "MergeTree", "Null"}
15+
var acceptableTableEngines = []string{"ReplacingMergeTree", "MergeTree", "ReplicatedReplacingMergeTree", "ReplicatedMergeTree", "Null"}
1616

1717
func CheckIfClickHouseCloudHasSharedMergeTreeEnabled(ctx context.Context, logger log.Logger,
1818
conn clickhouse.Conn,

protos/flow.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ enum TableEngine {
251251
CH_ENGINE_REPLACING_MERGE_TREE = 0;
252252
CH_ENGINE_MERGE_TREE = 1;
253253
CH_ENGINE_NULL = 2;
254+
CH_ENGINE_REPLICATED_REPLACING_MERGE_TREE = 3;
255+
CH_ENGINE_REPLICATED_MERGE_TREE = 4;
254256
}
255257

256258
// protos for qrep

ui/app/mirrors/create/cdc/schemabox.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ export default function SchemaBox({
245245
const engineOptions = [
246246
{ value: 'CH_ENGINE_REPLACING_MERGE_TREE', label: 'ReplacingMergeTree' },
247247
{ value: 'CH_ENGINE_MERGE_TREE', label: 'MergeTree' },
248+
{
249+
value: 'CH_ENGINE_REPLICATED_REPLACING_MERGE_TREE',
250+
label: 'ReplicatedReplacingMergeTree',
251+
},
252+
{ value: 'CH_ENGINE_REPLICATED_MERGE_TREE', label: 'ReplicatedMergeTree' },
248253
{ value: 'CH_ENGINE_NULL', label: 'Null' },
249254
];
250255

0 commit comments

Comments
 (0)