@@ -2434,3 +2434,52 @@ func (s ClickHouseSuite) Test_PartitionBy() {
24342434 env .Cancel (s .t .Context ())
24352435 e2e .RequireEnvCanceled (s .t , env )
24362436}
2437+
2438+ func (s ClickHouseSuite ) Test_PartitionByExpr () {
2439+ srcTableName := "test_partition_by_expr"
2440+ srcFullName := s .attachSchemaSuffix (srcTableName )
2441+ dstTableName := "test_partition_by_expr"
2442+
2443+ require .NoError (s .t , s .source .Exec (s .t .Context (),
2444+ fmt .Sprintf (`CREATE TABLE IF NOT EXISTS %s (id INT PRIMARY KEY, num INT, val TEXT NOT NULL)` , srcFullName )))
2445+
2446+ connectionGen := e2e.FlowConnectionGenerationConfig {
2447+ FlowJobName : s .attachSuffix ("clickhouse_partition_by" ),
2448+ TableMappings : []* protos.TableMapping {{
2449+ SourceTableIdentifier : srcFullName ,
2450+ DestinationTableIdentifier : dstTableName ,
2451+ PartitionByExpr : "num%2,val" ,
2452+ Columns : []* protos.ColumnSetting {
2453+ {SourceName : "id" , NullableEnabled : true },
2454+ {SourceName : "num" , NullableEnabled : true },
2455+ {SourceName : "val" , NullableEnabled : true },
2456+ },
2457+ }},
2458+ Destination : s .Peer ().Name ,
2459+ }
2460+
2461+ flowConnConfig := connectionGen .GenerateFlowConnectionConfigs (s )
2462+ tc := e2e .NewTemporalClient (s .t )
2463+ env := e2e .ExecutePeerflow (s .t , tc , flowConnConfig )
2464+ e2e .SetupCDCFlowStatusQuery (s .t , env , flowConnConfig )
2465+
2466+ e2e .EnvWaitForEqualTablesWithNames (env , s , "table setup" , srcTableName , dstTableName , "id" )
2467+
2468+ var partitionKey string
2469+ ch , err := connclickhouse .Connect (s .t .Context (), nil , s .Peer ().GetClickhouseConfig ())
2470+ require .NoError (s .t , err )
2471+ var dstTableSuffix string
2472+ if s .cluster {
2473+ dstTableSuffix = "_shard"
2474+ }
2475+ require .NoError (s .t ,
2476+ ch .QueryRow (s .t .Context (),
2477+ "select partition_key from system.tables where name=" + clickhouse .QuoteLiteral (dstTableName + dstTableSuffix ),
2478+ ).Scan (& partitionKey ),
2479+ )
2480+ require .NoError (s .t , ch .Close ())
2481+ require .Equal (s .t , "(num % 2, val)" , partitionKey )
2482+
2483+ env .Cancel (s .t .Context ())
2484+ e2e .RequireEnvCanceled (s .t , env )
2485+ }
0 commit comments