fix(clickhouse): preserve legacy soft-delete column casing - #4597
fix(clickhouse): preserve legacy soft-delete column casing#4597floze-the-genius wants to merge 1 commit into
Conversation
pfcoperez
left a comment
There was a problem hiding this comment.
Thanks for your contribution! I've dropped a comment about the implementation detail.
1bacbfc to
ac5fe77
Compare
|
Narrowed the compatibility behavior in
Added positive tests for both legacy directions and negative tests for mixed/default and custom-case variants. Targeted ClickHouse tests and |
|
@fable review this PR |
|
Claude finished @pfcoperez's task in 3m 56s —— View job Code Review
VerdictThe fix is correct and well-scoped. The narrowed behavior requested in the earlier review round is implemented as described: an exact destination-column match always wins, the fallback is strictly limited to the What I verified
Minor suggestions (non-blocking)
Tests / CIThe new tests cover both legacy directions, the both-columns-present case, and the negative mixed-case/custom-name cases; |
| require.Equal(t, "_peerdb_is_deleted", resolveSoftDeleteColumnName("_PEERDB_IS_DELETED", columns[:1])) | ||
| require.Equal(t, "_PEERDB_IS_DELETED", resolveSoftDeleteColumnName("_peerdb_is_deleted", columns[1:])) | ||
| require.Equal(t, "_peerdb_is_deleted", resolveSoftDeleteColumnName("", columns[:1])) | ||
| require.Equal(t, "_PeErDb_Is_DeLeTeD", resolveSoftDeleteColumnName("_PeErDb_Is_DeLeTeD", columns)) |
pfcoperez
left a comment
There was a problem hiding this comment.
- For a custom soft-delete column name (anything other than
""/_peerdb_is_deleted/_PEERDB_IS_DELETED),resolveSoftDeleteColumnNameis always the identity, yet everyNormalizeRecordscycle now pays an extrasystem.columnsround-trip and gains a new hard-failure point. Gating the fetch on the configured name being one of the two defaults (or empty) would keep the fix free for custom-named mirrors.
This is a good point @floze-the-genius and it seems a simple enough change.
Besides that, the PR looks good to me, maybe @ilidemi or @jgao54 want to take a look too.
| return model.NormalizeResponse{}, err | ||
| } | ||
|
|
||
| destinationColumns, err := peerdb_clickhouse.GetTableColumnsMapping( |
There was a problem hiding this comment.
this introduces a clickhouse query per table table on every normalize iteration, and the destination column name does not change from iteration to iteration. so this would add latency to all pipes.
the history around upper case _peerdb_is_deleted is a bit unfortunate. initially, the SoftDeleteColName field was originally never used by clickhouse, it was only for snowflake/bigquery/postgres destinations. then #2008 started to use SoftDeleteColName for ClickHouse to support the delete-on-merge feature, which accidentally made it possible for CH to also have upper case _peerdb_is_deleted. while this bug was fixed immediately in #3574, it was only fixed in the UI path so it's still technically possible in the API path (and still possible for legacy existing pipes that have the config set to upper case)
my preference is actually to revert change introduced in #4365 and also tighten the validation on the server-side to prevent upper case from being introduced.
@ilidemi wdyt?
There was a problem hiding this comment.
Agreed. I don't have as much context about this feature, so if you think tightening validation is going to remove degrees of freedom in a good way, that sounds easier.
Does this mean that the existing setups would be recommended to rename the CH column, or would we keep some kind of handling to accommodate for both?
Summary
Root cause
Older PeerDB releases stored the UI default
_PEERDB_IS_DELETEDin mirror config, but ClickHouse table creation and normalization hardcoded the physical column as_peerdb_is_deleted. After #4365 began honoring the stored config, upgraded legacy mirrors generated inserts for the uppercase identifier even though their existing tables only had the lowercase column.Tests
go test ./connectors/clickhouse -skip '^TestCreateRawTableHasTTL$' -count=1go vet ./connectors/clickhousego test -race ./connectors/clickhouse -run 'Test(ResolveSoftDeleteColumnName|BuildQuery_UsesDestinationSoftDeleteColumnCase|ProcessTableComparison_WithResolvedSoftDeleteColumnCase)$' -count=1Fixes #4596