Repository navigation
Fix Iceberg ADD COLUMN reusing a nested field id when last-column-id is too small - #128525
Conversation
…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]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261101-213800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261101-210900 |
|
cc @PedroTadim @SmitaRKulkarni, could you review this and add the |
|
Workflow [PR], commit [e5f9b02] Summary: ✅
AI ReviewSummaryReviewed PR #128525 at Final VerdictStatus: ✅ Approve. No new inline findings. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+23.20 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units52 translation units recompiled, 591 s compile time in total, 52 of them have a recent master baseline. |
|
🕵️ @groeneai two things on the new 1. Ids can still be lost when a column name contains a dot. The helper takes the max over
2. The test doesn't reproduce an upgraded table. It lowers A related question: the read path still passes the stored |
`getLastAssignedFieldId` took the max over `traverseSchema`, which keys ids by dotted path, so a top-level column named `a.b` overwrote the id of field `b` of a tuple `a` and that id could be assigned again. A small recursive walk now collects only the ids, without building a path for every field of every schema. The stack-size check moves to it from `traverseComplexType`. The test now reads the lowered `last-column-id` through a second table over the same path, as a newer server opening an old table does, and covers a `Map` column and the dotted-name case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, both changed in df5838b.
On the read path: no. I measured it with this PR's release build, a fresh |
| } | ||
| } | ||
|
|
||
| Int64 getMaxFieldIdOfType(Poco::JSON::Object::Ptr type) |
There was a problem hiding this comment.
@groeneai are you sure you can't reuse a function from somewhere to do this?
There was a problem hiding this comment.
Yes, there was one: collectTimeFieldIds already walked every field, list element and map key/value id. In e5f9b02 I turned it into a forEachFieldId visitor (with checkStackSize) used by both collectIcebergTimeFieldIds and getMaxFieldId, and removed getMaxFieldIdOfType.
The other walkers don't fit: traverseSchema is keyed by path (the a.b collision), and the REST catalog's collectAndValidateNestedFields throws on duplicate ids and on types getSimpleType rejects, which an old schema may still contain.
Checked: the test passes 50/50 with random settings, and a table with time at the top level, in a tuple, as a list element and as a map key reads the same values as before the change.
`collectTimeFieldIds` already walked every field, list element and map key/value id of a schema. Turn it into a `forEachFieldId` visitor (with `checkStackSize`) and use it both for the `time` field ids and for `getMaxFieldId`, instead of a second recursive walker. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ield id when `last-column-id` is too small
…ield id when `last-column-id` is too small
…field id when `last-column-id` is too small
Backport #128525 to 26.10: Fix Iceberg `ADD COLUMN` reusing a nested field id when `last-column-id` is too small
Backport #128525 to 26.9: Fix Iceberg `ADD COLUMN` reusing a nested field id when `last-column-id` is too small
Backport #128525 to 26.8: Fix Iceberg `ADD COLUMN` reusing a nested field id when `last-column-id` is too small
…ield id when `last-column-id` is too small
…ield id when `last-column-id` is too small
…field id when `last-column-id` is too small
Closes: #128455
Related: #110884
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
ALTER TABLE ... ADD COLUMNon Iceberg tables created by ClickHouse 26.6 or older: the new column could get the field id of an existing nested field (anArrayelement, aMapkey or value, aTupleelement), and the table could no longer be read (Duplicate field id). New field ids now start after the largest id used by any schema of the table. Closes #128455.Description
On 26.8.34.13 (also 26.7.22.4, 26.9.25.15, 26.10.2.103),
ALTER TABLE ... ADD COLUMNon an Iceberg table created by 26.3 or 26.6 gives the new column an id that a nested field already has, and every later read fails withDuplicate field id 3. (ICEBERG_SPECIFICATION_VIOLATION). Measured with the official images:(id Int64, arr Array(Int64))created on 26.6.8.7 or 26.3.42.3, thenADD COLUMNon each newer version.26.3 and 26.6 wrote
last-column-idas the number of top-level columns (2 here, whilearr.elementhas id 3). #110884 fixed that for new tables, butgenerateAddColumnMetadatastill allocates from the stored value.New ids now start after
max(last-column-id, largest field id of every schema in schemas, nested ids included), andlast-column-idis updated to the new largest id. All schemas, not only the current one, because a dropped column keeps its ids in older schemas and in old data files.IcebergSchemaProcessor::getMaxFieldIdcollects only the ids, reusing thetimefield id walk (now a shared visitor withcheckStackSize), so a top-level column nameda.bcannot hide the id of fieldbof a tuplea.The first version of #110884 had this upgrade path for the current schema; it was dropped in review (#110884 (comment)). This issue is the upgrade case that needs it.
Validation:
last-column-id, as the issue asks (same technique as04337_iceberg_schema_id_reuse_across_versions), and reads it through a second table. ItsArray,Map, dropped-Tupleanda.bcases all reuse an id on master (Duplicate field id 3) and pass with the fix, 50/50 with random settings. A walk over the current schema only fails the dropped case; a path-keyed one failsa.b.ADD COLUMNon the fixed build.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128525]
Version info
26.11.1.1203-master(included in26.11and later)