Skip to content

Cherry pick #128525 to 26.9: Fix Iceberg ADD COLUMN reusing a nested field id when last-column-id is too small - #128980

Merged
PedroTadim merged 4 commits into
backport/26.9/128525from
cherrypick/26.9/128525
Nov 3, 2026
Merged

PedroTadim merged 4 commits into
backport/26.9/128525from
cherrypick/26.9/128525

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #128525

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits November 1, 2026 21:33
…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.

#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
(#110884 (comment)).
Issue #128455 is the measured upgrade case that needs it.

Closes #128455.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`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]>
`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]>
…mall-last-column-id

Fix Iceberg `ADD COLUMN` reusing a nested field id when `last-column-id` is too small
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 3, 2026
@PedroTadim
PedroTadim merged commit a8c9f3d into backport/26.9/128525 Nov 3, 2026
144 of 145 checks passed
@PedroTadim
PedroTadim deleted the cherrypick/26.9/128525 branch November 3, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants