Skip to content

fix(DBI-1096 - clickhouse destination connector): Honor nullability for destination_type overrides in normalize - #4783

Merged
pfcoperez merged 1 commit into
mainfrom
fix/clickhouse-nullable-destination-type-normalize
Sep 10, 2026
Merged

pfcoperez merged 1 commit into
mainfrom
fix/clickhouse-nullable-destination-type-normalize

Conversation

@pfcoperez

@pfcoperez pfcoperez commented Sep 10, 2026

Copy link
Copy Markdown
Member

With a table mapping column setting both a destination_type override and nullability (table- or column-level nullable_enabled), the DDL generator creates the destination column as Nullable(), but the normalize query still extracted it as plain . JSONExtract to a non-nullable type turns JSON nulls into the type's default, so NULL values silently landed as 0, " ", etc. instead of NULL.

This PR makes the normalize query generator mirror the DDL:

  • Wraps the override in Nullable(...) under the same conditions.
  • Guards both generators against double wrapping when the override is already spelled Nullable(...), which previously produced invalid Nullable(Nullable()) DDL.

Part of: https://linear.app/clickhouse/issue/DBI-1096
Related to:

@pfcoperez pfcoperez self-assigned this Sep 10, 2026
@pfcoperez
pfcoperez requested a review from a team as a code owner September 10, 2026 08:38
return nil, fmt.Errorf("error while converting column type to ClickHouse type: %w", err)
}
} else if (tableSchema.NullableEnabled || columnNullableEnabled) && column.Nullable && !colType.IsArray() {
} else if (tableSchema.NullableEnabled || columnNullableEnabled) && column.Nullable && !colType.IsArray() &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

afaiu tableSchema.NullableEnabled is kind of a global flag whether we want to have nullable fields at the destination at all (regardless of source column nullability)
so, I think it should be tableSchema.NullableEnabled && columnNullableEnabled, no?
if tableSchema.NullableEnabled is false, it means that none of the destination columns can be nullable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah
we have schema.NullableEnabled and column.NullableEnabled
seems like we can put false on the schema lvl and override on the column lvl..
so OR is correct here I guess

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

seems like we can put false on the schema lvl and override on the column lvl..

Exactly, at least this is how I interpret it.

}
} else if (schema.NullableEnabled || columnNullableEnabled) && column.Nullable && !colType.IsArray() &&
!strings.HasPrefix(clickHouseType, "Nullable(") {
// mirror the table DDL: a nullable-enabled column created as Nullable(...) must also be

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we move it to the helper then?
if it's exactly the same condition as in flow/connectors/clickhouse/normalize.go.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's the same condition today but JSON extraction function and DDL are different enough IMO as to maybe make us stumble upon different conditions in future changes.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Flaky Test Detected

Analysis: All 88 failures are timeout collateral from panic: test timed out after 20m0s in the ClickHouse-cluster-only e2e suites on a single matrix leg (ch-stable, 1207s vs 995s/1006s on the two passing legs), and the PR's own nullable normalize tests passed in their non-cluster form on the same commit — pointing to a stalled/overloaded 2-node ClickHouse cluster plus thin test-deadline headroom rather than a code bug.
Confidence: 0.87

✅ Automatically retrying the workflow

View workflow run

@pfcoperez
pfcoperez merged commit e7b033c into main Sep 10, 2026
51 of 52 checks passed
@pfcoperez
pfcoperez deleted the fix/clickhouse-nullable-destination-type-normalize branch September 10, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants