Skip to content

Commit

Permalink
set allow_nullable_key = 1 when PEERDB_NULLABLE true (#2191)
Browse files Browse the repository at this point in the history
in response to errors like
```
code: 44, message: Sorting key contains nullable columns, but merge tree setting allow_nullable_key is disabled
```
  • Loading branch information
serprex authored Oct 25, 2024
1 parent 323bb69 commit 3e281de
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flow/connectors/clickhouse/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (c *ClickHouseConnector) SetupNormalizedTable(
}

normalizedTableCreateSQL, err := generateCreateTableSQLForNormalizedTable(
ctx,
config,
tableIdentifier,
tableSchema,
Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 3e281de

Please sign in to comment.