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 @@ -446,7 +446,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
15 changes: 14 additions & 1 deletion flow/connectors/clickhouse/normalize_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (t *NormalizeQueryGenerator) BuildQuery(ctx context.Context) (string, error
peerdb_clickhouse.QuoteIdentifier(dstColName),
)
}
case "JSON", "Nullable(JSON)":
case "JSON":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be combined into:

Suggested change
case "JSON":
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),
)
}

fmt.Fprintf(&projection,
"JSONExtractString(_peerdb_data, %s)::JSON AS %s,",
peerdb_clickhouse.QuoteLiteral(colName),
Expand All @@ -206,6 +206,19 @@ func (t *NormalizeQueryGenerator) BuildQuery(ctx context.Context) (string, error
peerdb_clickhouse.QuoteIdentifier(dstColName),
)
}
case "Nullable(JSON)":
fmt.Fprintf(&projection,
"JSONExtract(_peerdb_data, %s, 'Nullable(String)')::Nullable(JSON) AS %s,",
peerdb_clickhouse.QuoteLiteral(colName),
peerdb_clickhouse.QuoteIdentifier(dstColName),
)
if t.enablePrimaryUpdate {
fmt.Fprintf(&projectionUpdate,
"JSONExtract(_peerdb_match_data, %s, 'Nullable(String)')::Nullable(JSON) AS %s,",
peerdb_clickhouse.QuoteLiteral(colName),
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 @@ -49,6 +49,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