Repository navigation
Conversation
…absent Iceberg writers older than 0.12 (e.g. Spark 2.4, the Apache Impala test tables) write format version 1 metadata with only the legacy `schema`, which has no `schema-id`, manifest headers whose `schema` has no `schema-id`, snapshots without `schema-id`, and no `sort-orders`. Snapshots without `schema-id` are also legal in format version 2. All of these are optional in the spec, but `parseTableSchemaV1Method`, `traverseMetadataAndFindNecessarySnapshotObject`, `createIcebergDataSnapshotFromSnapshotJSON`, `ManifestFileIterator::create` and `IcebergMetadata::getSortingKey` required them, so such tables failed with BAD_ARGUMENTS or POCO_EXCEPTION. Use the defaults of the Java reader: - `parseCurrentTableSchema` returns `schemas` + `current-schema-id` when `schemas` exists (or format version >= 2), else the legacy `schema`; a missing id means schema 0 (`SchemaParser`). The id is set on a copy because the parsed metadata object is shared through the metadata files cache. The helper also serves the sort key and `GlueCatalog`'s timestamp lookup. - A snapshot without `schema-id` (absent or null) is not registered in the schema processor: a fabricated binding would be persistent and would throw on re-binding after a schema evolution, while unregistered snapshots already read their data files with the schema of their manifest. The snapshot's own table schema (time travel, manifest list pruning) is the current schema, as `SnapshotUtil.schemaFor`. - A format version 1 manifest header schema without `schema-id` takes the header `schema-id` key, else 0. Format version 2/3 still require it. - Format version 1 metadata without `sort-orders` is unsorted (`SortOrder.unsorted()`). - `system.iceberg_metadata_log_entries` treats a null snapshot `schema-id` as absent. Writes and maintenance commands are unchanged: they support only v2-shaped metadata and keep failing closed on legacy metadata. The test vendors Impala's `iceberg_partitioned` table unmodified (the same 25 files as ClickHouse#130028) and modifies copies of the PyIceberg corpus table. Closes ClickHouse#129991 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test now checks three things that it did not observe before: - for snapshots whose `schema-id` is absent or null, the per-file `schema_id` of `system.iceberg_files` (the data files keep the schema of their manifest, ids 0, 1 and 2, the same as for the unmodified table); - for the legacy `schema` with a sort order, `system.tables.sorting_key` (`id`; the table without `sort-orders` has none). One read of each table is needed first, because the Iceberg sort order reaches the table metadata on a read; - in the Glue gtest, that the legacy `schema` of the input metadata is not given a `schema-id` (the id is set on a copy). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove two comments that restate the code below them, shorten the manifest schema-id comment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds, head d9b5f40)
Round 2 re-review of the fix: no findings. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261108-024800 |
|
cc @SmitaRKulkarni @arsenmuk, could you review this and add the |
|
Workflow [PR], commit [0abfd7c] Summary: ✅
AI ReviewSummaryReviewed #130071 at Findings❌ Blockers
Tests
Performance & SafetyThe negative schema-ID representation was traced through these consumers:
Final VerdictStatus: ❌ Block Preserve per-file schema semantics during data compaction, support synthesized schemas during manifest consolidation, and add the two focused regressions above. |
…wn id A format version 1 manifest written before Iceberg 0.12 has no `schema-id` in its header schema, and that schema is the one its data files were written with. Defaulting it to 0 made a manifest written before a rename (or before a drop and re-add of a column with the same name) share the id 0 of the current legacy `schema`; the conflict tolerance then kept the metadata.json schema, so no schema transformation was applied. Parquet still read correctly through the field ids, but ORC is read by name: a renamed column came back empty and a re-added column showed the values of the dropped one. Such a schema now keeps 0 only if metadata.json binds 0 to the same fields, and otherwise gets a negative internal id, one per distinct schema, so the files are read with their own schema and transformed to the table schema. The choice and the registration happen under one mutex, so concurrent reads of the same table agree on the ids. The ids stay internal to the reader: `system.iceberg_files.schema_id` shows 0 for them, the default of a schema without an id, and cluster reads are unaffected because the initiator ships the schema transformation to the workers. The ORC fixture is three data files of the vendored Impala table rewritten as ORC with the same manifest layout (pyarrow + avro); the test renames `user` and drops and re-adds it in a copy of both tables. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| if (header_schema_id.has_value()) | ||
| schema_object->set(f_schema_id, *header_schema_id); | ||
| else if (manifest_format_version == 1) | ||
| schema_processor.addIcebergTableSchemaWithoutId(schema_object); |
There was a problem hiding this comment.
[Major] Handle synthesized schema IDs in manifest compaction as well.
A table upgraded from an old writer to format version 2 can retain v1 manifests without schema-id, while its metadata has valid schemas, current-schema-id, partition specs, and sort orders. If a retained manifest schema differs from metadata schema 0, this call now assigns it a negative ID. writeConsolidatedManifestFile groups data files by that resolved_schema_id, but its get_schema_object_by_id searches only the metadata's schemas array. When compaction actually consolidates such a group, it therefore throws Iceberg metadata does not contain a schema entry matching schema-id -1 at Compaction.cpp:949.
This also affects v2-shaped metadata, so the stated restriction on writing legacy metadata does not exclude it. Please preserve the manifest schema through the rewrite and serialize it with a valid external schema identity; substituting the current schema would reintroduce the rename/drop-and-readd problem. A focused test can upgrade an evolved legacy fixture to v2 metadata, retain two manifests with the same old schema, and run OPTIMIZE TABLE ... MANIFEST with iceberg_insert_single_manifest_for_all_partitions = 1 before checking the rows again.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes9 object files changed (+69.90 KiB total), 0 added.
716 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 units53 translation units recompiled, 422 s compile time in total, 53 of them have a recent master baseline. |
… `schema-id` The internal negative id of an id-less format version 1 manifest schema was a counter, known only to the server that read the manifest. A cluster function worker does not read the manifests, so a column read of such a file failed there with `Schema with id -1 is unknown` (or, on a worker that had walked the manifests for lazy materialization in another order, could bind the id to another schema). The id is now derived from the fields of the schema, so every server gives a schema the same id, and a server that meets an unknown negative id walks the manifests of the snapshot it reads to register it, as lazy materialization does. Reading with the table schema 0 instead is not enough: ORC and Avro files, and Parquet files without field ids, are read by column name. 05569 reads the evolved Parquet and ORC copies through `icebergLocalCluster` with lazy materialization disabled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - bbca130Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261108-123006 |
…hema-id-129991 Conflicts resolved: - `GlueCatalog.cpp`: master removed the timestamp type lookup through metadata.json (`getCurrentSchemaFieldTypes`) and now reads the current schema with `getCurrentSchema` + `loadCurrentSchema`. The legacy v1 `schema` without `schema-id` now goes through `parseTableSchemaV1Method` there, so `loadCurrentSchema` gets schema 0 instead of a POCO exception. - `gtest_glue_timestamp_type.cpp` was deleted on master; its legacy v1 case moved to `gtest_glue_schema_columns.cpp`. - `IcebergMetadata.cpp`: master dropped `updateLastColumnId`; kept the optional `schemas` handling. - `gtest_iceberg_schema_processor.cpp`: kept the tests of both sides. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #129991
Related: #100304
Related: #130028
Related: #117112
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed reading Iceberg tables written by Iceberg older than 0.12 (for example by Spark 2.4) and tables whose snapshots have no
schema-id: a format version 1schemaor manifest header schema withoutschema-id, a snapshot without (or with a null)schema-id, and format version 1 metadata withoutsort-orderswere rejected withBAD_ARGUMENTSorPOCO_EXCEPTION.Description
On 26.10.2.103 (also 26.3 LTS),
SELECT count() FROM icebergLocal('iceberg_partitioned')on Apache Impala's Spark 2.4 test table fails withCannot parse Iceberg table schema: 'schema-id' field is missing in schema. (BAD_ARGUMENTS); Impala returns 20. A snapshot withoutschema-idgivesPOCO_EXCEPTION(#100304).Root cause: these fields are optional for old writers, but the readers require them.
Change, with the defaults of the Java reader:
parseCurrentTableSchemapicksschemas+current-schema-id, else the legacyschema, whose missing id is 0 (on a copy). Also used for the sort key; the Glue catalog reads the legacyschemathe same way.schema-idis not bound to a schema: its data files keep the schema of their manifest, and its table schema (time travel) is the current one, asSnapshotUtil.schemaFor.schema-idtakes the headerschema-idkey, else 0 if it matches the metadata.json schema 0, else an internal id derived from its fields: files written before a rename or a drop and re-add of a column are read with their own schema (ORC reads by name). Cluster function workers register it from the manifests.sort-ordersis unsorted.The open #117112 overlaps this, but sets
schema-idon the cached metadata object and still requiressort-orders.Writes and maintenance commands still require v2-shaped metadata.
Validation:
05569_iceberg_optional_schema_id(Impala'siceberg_partitioned, the same files as in #130028, an ORC copy of three of them, and modified copies of the PyIceberg corpus table, also throughicebergLocalCluster) fails on master and passes with the fix. In #130028's05700, 5 of 15 tables now pass; the other 10 stop at #129989.Workflow [PR]
Sync PR [sync-upstream/pr/130071]