Repository navigation
Fix Iceberg duplicate field ids after ADD COLUMN on nested-field table - #110884
PedroTadim merged 5 commits into
Conversation
createEmptyMetadataFile initialized last-column-id to the number of top-level columns, ignoring the nested field ids that tuple/array/map children consume. For (id Int64, t Tuple(a, b)) the field ids are id=1, t=2, t.a=3, t.b=4, but last-column-id was written as 2. A later ADD COLUMN then reused id 3 (already held by t.a), publishing metadata with a duplicate field id: the ALTER succeeded but the next SELECT failed with Code 743 Duplicate field id 3 (ICEBERG_SPECIFICATION_VIOLATION). Record the max assigned field id (counting nested children) as last-column-id, both on initial table creation and in generateAddColumnMetadata, so every newly added field id (including the children of a newly added complex column) is globally unique. Closes: ClickHouse#110877 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-5:20260717-150900 |
|
cc @PedroTadim — as offered on #110877. Fixes the duplicate-field-id-after-ADD-COLUMN bug by recording the max assigned field id (counting nested tuple/array/map children) as |
|
Workflow [PR], commit [5af3640] Summary: ❌
AI ReviewSummaryThis PR fixes Findings❌ Blockers
Final VerdictNot ready: the fresh-table regression is fixed, but the upgrade path for metadata already written by the buggy build still publishes duplicate field ids. |
generateAddColumnMetadata trusted the persisted last-column-id when allocating the next field id. A table written by an older buggy build recorded last-column-id too small (top-level column count, ignoring nested tuple/array/map children), so after upgrade ADD COLUMN still reused a nested child id and published metadata with a duplicate field id. Derive the starting id from max(persisted last-column-id, max field id assigned in the current schema) so upgraded tables also get unique ids. Extend the regression test: a second ADD COLUMN after a complex column exercises the nested half of the fix, an assertion on last-column-id guards the recorded value, and an upgrade-path scenario (metadata with a too-small last-column-id) reproduces the original duplicate-field-id failure. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Both addressed in 42800d7.
|
|
@groeneai fix the merge conflict |
Resolve conflict in MetadataGenerator.cpp by dropping the maxAssignedFieldId recompute (and its recursive collectMaxFieldId walker): per reviewer, do not handle tables written before this patch, so the recursion (and thus a stack-overflow guard for it) is no longer needed. Keep the new-table fix: createEmptyMetadataFile records the max assigned field id (counting nested children) as last-column-id, and generateAddColumnMetadata assigns nested children of a newly added complex column their own ids. Strengthen the regression test: SELECT after each ALTER (surfaces a duplicate id immediately) and a SELECT after two consecutive ALTERs (s then d) so the nested-child half of the fix is exercised. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pushed b7bc8b8.
|
The merge-conflict resolution in the previous commit dropped the Utils.cpp initializer fix, so last-column-id was written as the top-level column count again. For (id Int64, t Tuple(a, b)) that is 2, ignoring the nested ids t.a=3 t.b=4, so the first ADD COLUMN reused id 3 and ClickHouse#110877 still reproduced on newly created tables. Set last-column-id after the field loop to iter, which getIcebergType advances past every nested tuple/array/map child, so it records the real max assigned field id.
Head branch was pushed to by a user without write access
CI finish ledger — 2d76d8eCI finished on this head. Every failure below has an owner (a fixing PR); none are caused by this PR's diff (this is an Iceberg metadata change, unrelated to stress/hung-check).
Reports:
Session id: cron:our-pr-ci-monitor:20260718-020000 |
| # would reuse a child id of `s` and that SELECT would fail with a duplicate id. | ||
| TABLE_DIR="${WORK_DIR}/t0" | ||
| mkdir -p "${TABLE_DIR}" | ||
| ${CLICKHOUSE_LOCAL} \ |
There was a problem hiding this comment.
@groeneai, why are you testing with clickhouse local? You can also remove a column, then add another one to check that last_column_id is still right.
There was a problem hiding this comment.
Good point, switched to clickhouse-client in 5af3640. clickhouse-local was only for convenience here; the isolation reason other Iceberg tests use it (e.g. 04214, whose bug SIGABRTs and must be contained to a subprocess) does not apply, since this bug is a caught ICEBERG_SPECIFICATION_VIOLATION exception, not a crash. Kept it parallel-safe with a unique table name and ${USER_FILES_PATH} path.
Also added the drop-then-add check you suggested: after ADD c/s/d, DROP COLUMN d (id 9) then ADD COLUMN e, asserting last-column-id stays monotonic at 10 (e takes a fresh id, the dropped 9 is not reused). SELECT after each ALTER, plus a SELECT after the two consecutive ALTERs (s then d).
Verified both directions on a server: baseline fails at the first SELECT with Code: 743 Duplicate field id 3 (last-column-id=2); with the fix all SELECTs are clean (last-column-id=10). 50/50 runs pass.
Per review, run the regression via clickhouse-client instead of clickhouse-local (the bug is a caught exception, not a crash, so it does not need the subprocess isolation clickhouse-local gives). Add SELECTs between the ALTERs so a duplicate field id surfaces immediately, and a DROP COLUMN d then ADD COLUMN e step asserting last-column-id stays monotonic (dropped id 9 is not reused, e takes 10). Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 26/26 (100.00%) · Uncovered code |
CI finish ledger — 5af3640CI fully finished (Finish Workflow pass, 0 checks queued/in-progress, >20min buffer). This head is the test-only update addressing @PedroTadim's 2026-07-20 review (server-based test + drop-then-add-column last-column-id check). One failure, non-PR-caused (this PR only touches Iceberg
Session id: cron:our-pr-ci-monitor:20260720-210000 |
fa0b31f
…-field-id-reuse-110877 Fix Iceberg duplicate field ids after ADD COLUMN on nested-field table
…small ClickHouse 26.3 and 26.6 wrote `last-column-id` as the number of top-level columns, ignoring the ids of nested fields (list element, map key/value, struct children). `generateAddColumnMetadata` took the next id from that value, so the first `ALTER TABLE ... ADD COLUMN` on a newer version gave the new column an id that a nested field already had, and every later read failed with `Duplicate field id N (ICEBERG_SPECIFICATION_VIOLATION)`. Measured with official images: a table created by 26.6.8.7 or 26.3.42.3, then altered by 26.8.34.13. New ids now start after max(`last-column-id`, the largest field id of every schema in `schemas`, nested ids included). All schemas, not only the current one, because a dropped column keeps its ids in older schemas and in old data files. The walk reuses `IcebergSchemaProcessor::traverseSchema`, the same walk the reader uses to map field ids, and `traverseComplexType` gets a stack-size check because it now also runs over historical schemas that no read has parsed. ClickHouse#110884 fixed `last-column-id` for new tables; its first version also had this upgrade path for the current schema, which was dropped during review (ClickHouse#110884 (comment)). Issue ClickHouse#128455 is the measured upgrade case that needs it. Closes ClickHouse#128455. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #110877
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed Iceberg tables producing duplicate field IDs after
ALTER TABLE ... ADD COLUMNwhen the initial schema contains nested fields (Tuple/Array/Map).last-column-idnow records the maximum assigned field ID including nested children, so a subsequently added column no longer reuses a nested field ID and reads no longer fail withICEBERG_SPECIFICATION_VIOLATION(Duplicate field id).Description
createEmptyMetadataFileinitializedlast-column-idto the number of top-level columns, ignoring the nested field IDs that tuple/array/map children consume. For(id Int64, t Tuple(a Int64, b Int64))the assigned field IDs areid=1, t=2, t.a=3, t.b=4, butlast-column-idwas written as2. A subsequentADD COLUMN cthen reused id3(already held byt.a): theALTERsucceeded and published invalid metadata, and the nextSELECTfailed withCode: 743 ... Duplicate field id 3 (ICEBERG_SPECIFICATION_VIOLATION).The fix records the max assigned field ID (counting nested children) as
last-column-id, both on initial table creation (createEmptyMetadataFile) and ingenerateAddColumnMetadatawhen the added column is itself complex, so every newly added field ID is globally unique.Repro from the issue (https://fiddle.clickhouse.com/e0c313b0-fcad-41b4-a7a1-4c27e0e8bc90); regression test
04545_iceberg_add_column_nested_field_id_reuse_110877covers initial nested schema + scalar ADD COLUMN + complex ADD COLUMN + read-back.Version info
26.7.1.1264(included in26.7and later)