Repository navigation
Refuse to read Paimon data files written before a column rename or a re-add instead of returning wrong values - #127816
Conversation
…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]>
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).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261026-063700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261026-051400 |
|
Workflow [PR], commit [69b3464] Summary: ✅
AI ReviewSummaryThe 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
Final Verdict✅ Approve based on code review and the recorded regression evidence. No new inline findings to post. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+34.55 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 units22 translation units recompiled, 226 s compile time in total, 22 of them have a recent master baseline. |
43e5185
…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]>
…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]>
…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]>
Closes: #127545
Related: #122506
Changelog category (leave one):
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
NULLand 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 b2on a Paimon table,paimonLocalreturnsNULLforb2in every row written before the rename. AfterDROP COLUMN emailandADD COLUMN email STRING, it returns the dropped[email protected]/[email protected]where Spark returnsNULL. Thepaimon*table functions are not gated.Root cause. Paimon identifies columns by field id:
RENAMEkeeps the id, andADDassigns a new one. The reader keeps only each manifest entry's path, drops itsschema_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_idis 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 throwsNOT_IMPLEMENTED. ADD/DROP-only evolution reads as before. The error says how to recover: rewriting the table with the current schema (for exampleINSERT 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 anINSERT 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
26.11.1.1006-master(included in26.11and later)