Skip to content

Refuse to read Paimon data files written before a column rename or a re-add instead of returning wrong values - #127816

Merged
fm4v merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/paimon-refuse-renamed-or-reused-column-files
Nov 1, 2026
Merged

fm4v merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/paimon-refuse-renamed-or-reused-column-files

Conversation

@groeneai

@groeneai groeneai commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #127545
Related: #122506

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Reading an Apache Paimon table throws an exception instead of returning wrong results when a data file was written before a column was renamed, or before a column was dropped and another one with the same name was added. Before, the renamed column read as NULL and the re-added column returned the dropped column's values. Closes #127545.

Description

On 26.9 (26.9.19.9, also 26.8.28.14), after Spark runs RENAME COLUMN b TO b2 on a Paimon table, paimonLocal returns NULL for b2 in every row written before the rename. After DROP COLUMN email and ADD COLUMN email STRING, it returns the dropped [email protected] / [email protected] where Spark returns NULL. The paimon* table functions are not gated.

Root cause. Paimon identifies columns by field id: RENAME keeps the id, and ADD assigns a new one. The reader keeps only each manifest entry's path, drops its schema_id, and reads every Parquet/ORC file by column NAME with the pinned snapshot's schema.

The change. Following the design in #127545 (comment): for every data file a query reads, its schema_id is compared with the read schema. If a field id now has a different name, or a name (compared case-insensitively) now belongs to a different field id, the read throws NOT_IMPLEMENTED. ADD/DROP-only evolution reads as before. The error says how to recover: rewriting the table with the current schema (for example INSERT OVERWRITE) makes the snapshots created after it readable, and a lagging incremental read moves on once those snapshots expire or its cursor is moved past them. The limitation is added to the Paimon table function and engine docs.

Validation. test_schema_evolution.py: the RENAME step moves to its own test expecting the error, plus a drop-and-re-add test (also with the name re-added in another case) and an incremental read across a RENAME; all three fail on master. Both refusal tests read the right rows after an INSERT OVERWRITE. The Paimon integration suite and the Paimon stateless tests pass.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127816]

Version info

  • Merged into: 26.11.1.1006-master (included in 26.11 and later)

groeneai and others added 3 commits October 26, 2026 03:03
…re-add

Paimon identifies columns by field id: RENAME COLUMN keeps the id and changes
the name, ADD COLUMN assigns a new id. The reader kept only each manifest
entry's path, dropped its `schema_id`, and read every data file by column name
with the pinned snapshot's schema. So rows written before a rename read `NULL`
for the renamed column, and after DROP + ADD of the same name the dropped
column's values came back (also through filters).

As designed by the Paimon code owner in
ClickHouse#127545 (comment),
every data file a query actually reads (after DELETE entries, partition
pruning and deduplication) is now checked against the read schema: when a
field id has a different name, or a name belongs to a different field id, the
read throws `NOT_IMPLEMENTED`. `collectDataFilesFromManifests` is the single
listing path of full scans, `paimon_target_snapshot_id` reads and incremental
first/delta reads, so the throw happens before an incremental read commits its
watermark. The read schema is the pinned state's schema on every path,
including the targeted snapshot. Only ids and names of the old schema are
parsed: parsing its types would newly reject a file whose since-dropped column
had an unsupported type such as `ROW`. Compatible (file schema, read schema)
pairs are cached, since a schema never changes once written and `iterate`
validates the table identity before listing.

ADD/DROP-only evolution reads as before. The limitation is documented in the
Paimon table function and engine reference (source-level docs).

Tests: the RENAME step of `test_schema_evolution` moves to its own test that
expects the error, a DROP + re-ADD test is added, and a caught-up incremental
read across a RENAME guards against over-refusal. The README marks schema
changes as partially covered.

Closes: ClickHouse#127545

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The refusal now names its recovery: rewriting the table with the current
schema (for example INSERT OVERWRITE) for a plain read, and for an incremental
read the kept cursor plus snapshot expiry or a manual cursor move. The same is
documented. The tests pin the INSERT OVERWRITE recovery of both refusal cases
and the lagging incremental read (refused, cursor kept, resumes after the move).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed column

The Parquet and ORC readers can match column names case-insensitively, so a
column dropped and re-added under another case (email, then EMAIL) still
returned the dropped values. The test covers the default and the
case-insensitive Parquet matching.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 5 findings over 3 rounds) plus my own review (5 findings).

# Sev Finding Verdict Evidence / action
1 ⚠️ The refusal says why but not how to recover; a lagging incremental read stays stuck, undocumented (PaimonMetadata.cpp) AGREE, fixed recovery text in the error and docs: INSERT OVERWRITE with the current schema, or the cursor move for a lagging incremental read; tests for both
2 ⚠️ The incremental test never reaches the check, so the kept cursor is untested (test_schema_evolution.py) AGREE, fixed lagging read refused with the Keeper cursor kept, also for a targeted old snapshot; resumes after the cursor is moved
3 ⚠️ The compatible-pair cache grows with schema generations (PaimonMetadata.h) DISAGREE at most N^2/2 pairs of ~64 B over N schema generations (0.3 MB at 100); the schema processor already keeps every parsed schema for the table's lifetime
4 💡 Test comment attributes the delay to the background refresh; metadata refreshes per query AGREE, fixed comment removed (measured: the renamed column is visible right after the insert)
5 ⚠️ With input_format_parquet_case_insensitive_column_matching, a column re-added under another case reads the dropped values (PaimonMetadata.cpp) AGREE, fixed reproduced first (3 [email protected]); the re-add check compares names case-insensitively, independent of settings; the test covers both settings
6 💡 The support matrix still lists Paimon schema evolution as not supported DISAGREE the reference pages now say what is read; the matrix row (with its Cloud column) is the owner's status call
7 💡 A paimon* table function query reads one extra schema file per older schema id with live files noted inherent to comparing a file's schema; normally a handful
8 ⚠️ A query filtered by _file/_path to a current-schema file still throws for an old file it would skip DISAGREE same listing-level refusal as the deletion-vector check from #122506, which also ignores _path/_file; checking after that filter would run after the incremental cursor is committed in iterate()
9 💡 Two current columns differing only in case make older files refused after any schema change noted cost of the settings-independent comparison, documented as "compared case-insensitively"; INSERT OVERWRITE recovers

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-8:20261026-063700

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The rename and drop-and-re-add tests (s3, azure) fail on every master run: the SELECT returns NULL for b2 and the dropped [email protected] / [email protected]; released 26.9.19.9 and 26.8.28.14 return the same rows.
b Root cause explained? Paimon identifies columns by field id; collectDataFilesFromManifests dropped each entry's schema_id, so files were read by name with the pinned schema: a renamed id reads NULL, a re-bound name reads the dropped field.
c Fix matches root cause? Yes, the owner's design: each data file that is read is checked against the read schema by field id and name, and a conflict throws NOT_IMPLEMENTED.
d Test intent preserved / new tests added? Yes. ADD/DROP keeps its row assertions; RENAME and drop-and-re-add (also in another case, both name-matching settings) assert the error; an incremental read across a RENAME continues when caught up and, lagging, is refused with the Keeper cursor kept; both refusals read the right rows after INSERT OVERWRITE.
e Both directions demonstrated? Yes. Master: the 6 new cases fail with wrong rows, ADD/DROP passes; fix: 8/8, 40/40 over 5 runs; disabling either branch, the cursor argument, the delta-path schema or the case-insensitive comparison fails its test.
f Fix is general across code paths? Yes. collectDataFilesFromManifests is the only listing path (full scans, target snapshot, incremental first and delta reads); Paimon integration suite 91 passed / 4 xfailed (test_hdfs.py on a re-run after an HDFS sidecar timeout), deletion vectors 5/5, incremental read 15/15, 15 Paimon stateless tests (only the local zoneinfo/UTC draw fails).
g Fix generalizes across inputs (params/datatypes/wrappers)? Only top-level ids and names are compared, case-insensitively, so the verdict is independent of type, storage, format and input_format_{parquet,orc}_case_insensitive_column_matching; ADD-only fixtures (test_reader_compat.py) still read.
h Backward compatible? (maintainer-approved exception only) No setting or format change; the only change is the owner-requested refusal of files currently read with wrong values.
i Invariants and contracts preserved? DELETE, pruning and deduplication are unchanged and run first; the throw precedes setCommittedSnapshot (Keeper cursor asserted unchanged); the verdict cache has its own mutex and is keyed by immutable schema ids.

Session id: cron:clickhouse-impl-slot-4:20261026-051400

@clickhouse-gh

clickhouse-gh Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [69b3464]

Summary: ✅


AI Review

Summary

The PR refuses Apache Paimon data files whose field ids and column names conflict with the query's pinned schema, preventing incorrect results after column renames or drop-and-re-add operations. It documents recovery and adds regression coverage for both conflicts, rewrite recovery, and incremental cursor preservation. No actionable findings remain after reviewing the current diff, callers, tests, and prior discussion.

Missing context / blind spots
  • ⚠️ Runtime validation was not independently repeated in this checkout, which has no ClickHouse build. The author reports passing regression and Paimon-suite runs, but the current Praktika report contains no integration or bugfix-validation test results; the workflow completion check reports dropped bugfix-validation jobs. Completed integration and bugfix-validation jobs would close this verification gap.
Final Verdict

✅ Approve based on code review and the recorded regression evidence. No new inline findings to post.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Oct 26, 2026
@JiaQiTang98 JiaQiTang98 self-assigned this Oct 26, 2026
@JiaQiTang98 JiaQiTang98 added the can be tested Allows running workflows for external contributors label Oct 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 69b346452 with master c7b68329f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

4 object files changed (+34.55 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Paimon/PaimonMetadata.cpp.o 804.26 KiB 836.58 KiB +32.32 KiB (+4.02%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

22 translation units recompiled, 226 s compile time in total, 22 of them have a recent master baseline.

Job report

@fm4v
fm4v added this pull request to the merge queue Nov 1, 2026
Merged via the queue into ClickHouse:master with commit 43e5185 Nov 1, 2026
351 of 353 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 1, 2026
w62 pushed a commit to w62/ClickHouse that referenced this pull request Nov 1, 2026
…snapshot's schema

A Paimon schema change (`ALTER TABLE ... ADD COLUMNS`, `RENAME COLUMN`,
`DROP COLUMN`) writes a new `schema/schema-N` file but no snapshot.
`PaimonMetadata::loadLatestState` built the latest table state with
`snapshot.schema_id`, i.e. the schema the last commit was written with, so
until the next commit `DESCRIBE` showed the old columns, `SELECT` of an added
column failed with `UNKNOWN_IDENTIFIER`, and a renamed or dropped column kept
its old name. `PaimonTableState::operator==` compares `schema_id`, but the id
never changed, so `update()` did not republish the state either.

In Paimon a read of the latest state uses the latest schema file:
`FileStoreTableFactory.create` takes `SchemaManager.latest()`, which lists
`schema/` and picks the highest `schema-N`; a snapshot's `schemaId` is only
the schema its files were written with. Spark, Flink and pypaimon return the
added column as NULL for existing rows.

`loadLatestState` now lists the schema directory after reading the snapshot
(`PaimonTableClient::getLatestTableSchemaInfo`, already used by `create`) and
builds the state with that id. Every consumer of the latest state keys off
`state->schema_id` (table structure, per-query columns, cluster workers,
partition pruner, options, manifest parsing), so they all follow. Manifest
parsing uses the schema only for partition types, and Paimon refuses to
rename, retype or drop partition keys, so parsing with the latest schema is
safe; the manifest cache key includes the schema id. States loaded for a
specific snapshot id (incremental read, `paimon_target_snapshot_id`) keep the
snapshot's own schema.

This is a regression: v26.3 re-read the latest schema file on every update;
ClickHouse#102343 ("Re-add paimon storage engine") switched to the snapshot's schema id
(first stable release v26.5).

Mapping data files written before a RENAME/DROP by field id is out of scope
(ClickHouse#127816).

Closes ClickHouse#128308

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fm4v fm4v self-assigned this Nov 2, 2026
qoega pushed a commit to qoega/ClickHouse that referenced this pull request Nov 7, 2026
…a column rename or re-add are readable

Paimon identifies columns by field id: RENAME COLUMN keeps the id and changes
the name, ADD COLUMN assigns a new id, and every data file stores its columns
under the names of the schema it was written with (DataFileMeta.schemaId).
The reader read every file by the current names, so ClickHouse#127816 refused, with
NOT_IMPLEMENTED, every file whose write schema gives a field id another name
or a name (case-insensitively) another field id (ClickHouse#128541).

Such a file is now read under its own schema and mapped by field id, as
Paimon's SchemaEvolutionUtil does:

- PaimonMetadata::getDataFileSchemaTransform (replaces checkDataFileSchema,
  same detection, cached per file schema and read schema) builds a DAG whose
  inputs are the columns of the file under the file's names, typed with the
  read schema's types (so type promotion works as before), and whose outputs
  are the read schema's fields in order: the input, an alias for a rename, or
  a materialized default for a field id the file does not have. A file with
  no field of the read schema gets one unused input, because the cluster
  protocol drops a transform without inputs and the replica would then read
  the file by name.
- The transform is carried in ObjectInfo::data_lake_metadata->schema_transform,
  which the cluster protocol already sends to paimon*Cluster and parallel
  replica workers, and PaimonMetadata::getInitialSchemaByPath returns its
  inputs, so the reader reads the file's own names.
- Files that read the same by name and by id (no rename, no reused name) keep
  the current path with row-group pruning and the query condition cache.

For an object with both an initial schema and a per-object transform (only
Paimon: Iceberg never sets data_lake_metadata, Delta never returns an initial
schema), StorageObjectStorageSource now:

- does not consult the plain query condition cache: its key is not scoped by
  schema, so an entry written while the file's name meant another field id
  (kept for a table with a UUID) would skip row groups;
- gives the reader no filter: the reader sees the file's names, so statistics
  pruning would compare a current column with the file's same-named column;
  a row-level filter or PREWHERE, if any, runs after the transform;
- does not prune the transform: unused inputs would otherwise stay in the
  block next to an output with the same name and another type.

Tests in test_storage_paimon_with_spark: renames in Parquet, ORC and Avro,
through paimonS3Cluster on a node2-only cluster, and before a copy-on-write
UPDATE; DROP + ADD under the same name, also in another case with case-
insensitive Parquet matching; rotated names on a table engine with the query
condition cache, the reader filter and a single-column read (each guard has
its own failing assertion when removed); a file with no current field, local
and through the cluster function; incremental and paimon_target_snapshot_id
reads across a rename; the rename-without-commit test now checks the values.
The documentation drops the limitation.

Closes ClickHouse#128541

Co-Authored-By: Claude Opus 5.5 <[email protected]>
qoega pushed a commit to qoega/ClickHouse that referenced this pull request Nov 7, 2026
…eld-id reads

A file read under its own names yields whole columns, while `filterTupleColumnsToRead` asks
for a tuple element (`s.y`) as a flat column, so `SELECT s.y` on a file written before a
top-level rename threw NOT_FOUND_COLUMN_IN_BLOCK. Extract the requested elements after the
schema transform, as ClickHouse#125439 does for Iceberg (gated to Paimon objects here).

Fields inside a ROW are still matched by name: after a nested rename, or a nested drop and
re-add under the same name, an older file returned NULL for the renamed field or the dropped
field's values. The schema mapping now compares nested field ids and names (through ARRAY,
MULTISET and MAP) and refuses such a file with NOT_IMPLEMENTED and the recovery text of
ClickHouse#127816. The docs say that only top-level columns are matched by field id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paimon reads columns by name, not field id: dropped values reappear after re-add

4 participants