Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flow/connectors/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func GetTableSchemaForTable(tm *protos.TableMapping, columns []driver.ColumnType
qkind = types.QValueKindArrayBoolean
case "Array(Date)":
qkind = types.QValueKindArrayDate
case "JSON":
case "JSON", "Nullable(JSON)":
qkind = types.QValueKindJSON
default:
if strings.Contains(column.DatabaseTypeName(), "Decimal") {
Expand Down
26 changes: 16 additions & 10 deletions flow/connectors/clickhouse/normalize_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,25 @@ func (t *NormalizeQueryGenerator) BuildQuery(ctx context.Context) (string, error
peerdb_clickhouse.QuoteIdentifier(dstColName),
)
}
case "JSON", "Nullable(JSON)":
fmt.Fprintf(&projection,
"JSONExtractString(_peerdb_data, %s)::JSON AS %s,",
peerdb_clickhouse.QuoteLiteral(colName),
peerdb_clickhouse.QuoteIdentifier(dstColName),
)
if t.enablePrimaryUpdate {
fmt.Fprintf(&projectionUpdate,
"JSONExtractString(_peerdb_match_data, %s)::JSON AS %s,",
case "JSON", "Nullable(JSON)":
stringType := strings.Replace(clickHouseType, "JSON", "String", 1)

fmt.Fprintf(&projection,
"JSONExtract(_peerdb_data, %s, '%s')::%s AS %s,",
peerdb_clickhouse.QuoteLiteral(colName),
stringType,
clickHouseType,
peerdb_clickhouse.QuoteIdentifier(dstColName),
)
}
if t.enablePrimaryUpdate {
fmt.Fprintf(&projectionUpdate,
"JSONExtract(_peerdb_match_data, %s, '%s')::%s AS %s,",
peerdb_clickhouse.QuoteLiteral(colName),
stringType,
clickHouseType,
peerdb_clickhouse.QuoteIdentifier(dstColName),
)
}

default:
projLen := projection.Len()
Expand Down
4 changes: 4 additions & 0 deletions flow/connectors/clickhouse/table_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func jsonFieldExpressionConverter(
return sourceFieldIdentifier, nil
}

if field.Nullable {
return fmt.Sprintf("CAST(%s, 'Nullable(JSON)')", sourceFieldIdentifier), nil
}

return fmt.Sprintf("CAST(%s, 'JSON')", sourceFieldIdentifier), nil
}

Expand Down
Loading