From 3e281de2bfeea9a238a0e353896688adb123d085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Fri, 25 Oct 2024 22:12:04 +0000 Subject: [PATCH] set allow_nullable_key = 1 when PEERDB_NULLABLE true (#2191) in response to errors like ``` code: 44, message: Sorting key contains nullable columns, but merge tree setting allow_nullable_key is disabled ``` --- flow/connectors/clickhouse/normalize.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/flow/connectors/clickhouse/normalize.go b/flow/connectors/clickhouse/normalize.go index 94009cd37a..9a03775544 100644 --- a/flow/connectors/clickhouse/normalize.go +++ b/flow/connectors/clickhouse/normalize.go @@ -55,6 +55,7 @@ func (c *ClickHouseConnector) SetupNormalizedTable( } normalizedTableCreateSQL, err := generateCreateTableSQLForNormalizedTable( + ctx, config, tableIdentifier, tableSchema, @@ -77,6 +78,7 @@ func getColName(overrides map[string]string, name string) string { } func generateCreateTableSQLForNormalizedTable( + ctx context.Context, config *protos.SetupNormalizedTableBatchInput, tableIdentifier string, tableSchema *protos.TableSchema, @@ -178,6 +180,12 @@ func generateCreateTableSQLForNormalizedTable( stmtBuilder.WriteString(") ") } + if nullable, err := peerdbenv.PeerDBNullable(ctx, config.Env); err != nil { + return "", err + } else if nullable { + stmtBuilder.WriteString(" SETTINGS allow_nullable_key = 1") + } + return stmtBuilder.String(), nil }