Repository navigation
Read the Iceberg initial-default of fields absent from older data files - #130101
alexey-milovidov merged 40 commits into
Conversation
An Iceberg field added with an `initial-default` must read as that default in
every data file written before it was added (spec, "Column Projection"). The
key was never parsed, so such rows read as NULL, filters on the column missed
them, and a required field added with a default made the table unreadable.
A field absent from a data file is synthesized in two places, and both now use
the default:
- the schema evolution DAG, for a file read under its own older schema: the
constant of a new top-level field, and `AddingTransform` for a field added
inside a struct (also inside list elements and map values);
- the format reader, for a file read under the schema that has the field (its
manifest was rewritten under the newer schema and the old snapshot expired,
or a stale ClickHouse INSERT): Parquet (top level, struct elements at any
depth, requested subcolumns), ORC (top level and struct elements) and Avro
(top level), through a new `ColumnMapper` map of defaults.
The JSON single-value serialization (spec Appendix D) of every type is parsed
once in `IcebergSchemaProcessor`; a malformed default, or a non-null one for a
type that must default to null, fails with ICEBERG_SPECIFICATION_VIOLATION
instead of being ignored. A struct field's own default can only be `{}`, which
stands for the defaults of its fields.
A reader fills a field with its default only when the data file identifies
the fields at that level by field id and none of them has the field's id, the
rule ClickHouse#126879 introduced for Avro: a field missing only by name may be in the
file under another name. With that proof, ORC and Avro no longer read such a
column from a same-named field of the file (a dropped column re-added under
the same name), and ORC builds no search argument for that file, because it
resolves predicate columns by name.
The query condition cache key of UUID-less tables and the Parquet columns cache
identity now include the defaults, since the value read for an absent field
depends on them. A metadata.json schema replaces an identical copy registered
from a manifest header, which does not carry `initial-default`.
The new test reads the Apache Impala and DuckDB Iceberg tables of ClickHouse#130028 and
ClickHouse#130010 (identical files) as written and with their older data files bound to
the newer schema, and ClickHouse-written Parquet, ORC and Avro tables evolved
with nested, required, struct, list and malformed defaults.
Closes ClickHouse#129992
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tamp defaults A field whose value comes from an identity partition of the data file must read as that value, even when it is NULL, before its `initial-default` applies (spec, "Column Projection"). NULL identity values were skipped, so the reader filled the default instead; and a struct read as a whole got the defaults of its nested identity sources. NULL identity values are now applied, and the per-file column mapper drops the defaults of the file's identity partition columns (the shared mapper is replaced by the per-file one for such files). A `timestamp` / `timestamp_ns` default must be an ISO-8601 local date-time and a `timestamptz` / `timestamptz_ns` default the same with `+00:00`; the lenient parser accepted any offset (and shifted the value), a missing offset, a space separator. Other shapes now fail with ICEBERG_SPECIFICATION_VIOLATION. With `input_format_parquet_allow_missing_columns = 0`, a field proven absent by field id that has a default is not a missing column (ORC and Avro already exempt it). Adds the DuckDB `partition_values_missing_edge_cases/default/mixed` table of ClickHouse#130010 (identical files); it is not read by a test yet, since its `final.metadata.json` name is rejected (ClickHouse#129988). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ity precedence A data lake read hands tuple-element columns (`t.x`) to the ORC reader whenever the table's format supports PREWHERE, and an Iceberg table function defaults to Parquet. The absence check compared such a column's field id with the ids of the root struct only, so every nested id looked absent: `SELECT t.x` on an Iceberg ORC table read NULL, and a field of an absent struct without a struct default got its own default. The check now walks the structs on the column's path by field id and applies the default inside an absent struct only when every struct from the absent one down has a struct default, as the Parquet reader does. The identity partition precedence is tested on a copy of DuckDB's `mixed` table whose metadata file is renamed, because `final.metadata.json` is not read as a metadata version (ClickHouse#129988). The per-file column mapper replaces the shared one only when an identity partition column of the file has a default, the only case where the two differ. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fix struct The ORC absence check treated every prefix of a column name that names a field of the data lake schema as a struct on the column's path. A top-level field `a.b` next to a struct `a` was thus looked up inside `a`, not found, and read as absent, so `SELECT a.b` returned NULL instead of the file's value. Field ids are unique in an Iceberg schema, so a struct on the way that has the column's own id holds the column itself: the walk now stops there and reads the field. The parsed `iceberg.id` attributes of a struct are cached per file, since the check now looks each struct up twice per header column. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten two design comments (schema copy replacement, ORC same-named field) to one line each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (4 rounds)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261108-072400 |
|
cc @SmitaRKulkarni @al13n321, could you review this and add the |
|
Workflow [PR], commit [f3036d9] Summary: ✅
AI ReviewSummaryThis fixes Iceberg Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes24 object files changed (+516.20 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units161 translation units recompiled, 1917 s compile time in total, 161 of them have a recent master baseline. |
…ld with another id The ORC search argument resolves a predicate column by name. The guard that skipped it for an absent column with a same-named field of the file looked only at the header columns, so a predicate on a tuple element (`t.j`, where `t` is in the header and its field `j` was dropped and re-added) was still built against the dropped field's statistics, and the stripe holding a row whose `t.j` reads its `initial-default` was skipped: `SELECT t ... WHERE t.j = 9` returned nothing while `SELECT t` returned `(9)`. The guard now also checks every column the filter requires, resolved by field id through the current-schema mapper (the filter names columns of the current schema, also when the file is read under its own older schema). This also covers an added field without a default (`WHERE t.j IS NULL` lost the row the same way). Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is interesting - a default that has to be processed and filled within the format. Ok.
# Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/tests/gtest_iceberg_schema_processor.cpp
Resolve conflicts with the migration of `src/Processors/Formats` to `-WithMemoryTracking` containers, the Iceberg schema validation (`findSchemaViolation`) and the ORC map key type fix: keep both sides, and use `VectorWithMemoryTracking`, `UnorderedMapWithMemoryTracking` and `UnorderedSetWithMemoryTracking` in the code added by this PR under `src/Processors/Formats`, as the style check now requires.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged master to resolve the conflicts with the |
A requested element of a struct, such as `t.s` with `optimize_functions_to_subcolumns = 1`, is read through the `nested_tables` branch of `orcColumnsToCHChunk`, which passed neither the mapper path nor a type hint of the struct itself, so the field-id matching and the `initial-default` handling of `readColumnFromORCColumn` did not apply: a dropped field `t.s.j` was read instead of the default of the re-added one. Build the hint of the struct from the requested elements and pass the mapper path. Address review: ClickHouse#130101 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cestors A subcolumn path of a query never names the element of a list or the key or value of a map: `l.element` of `l Array(Tuple(element ...))` is the field `element` of the elements of `l` (Iceberg path `l.element.element`). `getIcebergFieldPath` took the longest prefix found in the storage encoding, here the list's element node `l.element`, which has no default, so an absent `l` read `l.element` as `[]` on Parquet, ORC and Avro while the whole `l` and `tupleElement(l, 'element')` read the default. It now takes only fields reached from the top level through structs. Parquet's missing tuple element path names its field by the Iceberg path (`l.element.y`), so it passes that field explicitly instead of resolving it. Avro filled the default of an absent `n.x` without looking at `n`: an absent `n` with no struct default is NULL, and so is `n.x`, as Parquet and ORC read it. An Avro data file is read through tuple subcolumns whenever the table's format is Parquet (the table function's default), so `SELECT n.x` returned the default of `x` where master returns NULL. `getColumnsAbsentFromIcebergFile` now also returns the absent columns inside an absent struct without a struct default, and these get no default. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`getColumnsAbsentFromIcebergFile` looked up the exact column name in the storage encoding. A subcolumn of a list member is not there: for `l.y` of `l Array(Tuple(y ...))` the encoding has `l` and `l.element.y`, so `l.y` of a list absent from an Avro file was never marked absent. With the table's format Parquet (the table function's default) the file is read through subcolumns, and `SELECT l.y` threw `THERE_IS_NO_COLUMN`, or read `[]` with `input_format_avro_allow_missing_fields = 1`, where Parquet and ORC read the member of the list's default. The absence is now tested on the field that has the column, `getIcebergFieldPath`, like the default lookup already does. A flattened nested read of an Avro array also skips those columns now: a list dropped and added again under a new id read `p.y` from the dropped list while `p` read the default. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ColumnMapper::getIcebergInitialDefault(path, type)` first looked `path` up as an exact storage path. A query subcolumn can spell another field's storage path: in `q Array(Tuple(element Tuple(y Nullable(Int32)), y Array(Nullable(Int32))))` the subcolumn `q.element.y` (member `y` of member `element`) is also the storage path of the sibling member `y` of the list elements. Reading `q.element.y` from a file without `q` returned that sibling's own default (`[9]`) instead of the subcolumn of `q`'s default (`[5,6]`), and `WHERE has(q.element.y, 5)` lost the row, on Parquet, ORC and Avro. The getter now takes the field explicitly (the readers already resolve it with `getIcebergFieldPath`) and extracts the subcolumn from that field's default; the ORC nested synthesis keeps passing the storage path as both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uld have it Address review: `getColumnsAbsentFromIcebergFile` required field ids only on the top-level fields and then looked the field id up in the ids of the whole file. A nested field stored without a `field-id` was therefore taken as absent, and its `initial-default` (or NULL) was read instead of its value: `SELECT n.x` and `WHERE n.x = 100` disagreed with `SELECT n`. The field is now absent only if the record that would have it (found by the id of the struct, list element or map value) identifies all its fields by id and none of them has the field's id, or if that container is absent itself, like in the ORC and Parquet readers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Poco::Dynamic::Var::extract` returns a const reference, so the copy of the `Poco::JSON::Object::Ptr` is unnecessary; `Build (arm_tidy)` rejects it with `performance-unnecessary-copy-initialization`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
…en they are pruned Whether the fields of an ORC struct are matched by Iceberg field id is decided on the struct of the file when the fields are selected, but the conversion decided it again on the selected struct, which has only the requested fields. If a field without a field id was not requested, the selected struct had field ids on all its fields, so the conversion matched by field id a field that was selected by name, did not find it, and filled in the `initial-default` of the field added again under that name: in an ORC file with `t.j` (field id 2) and `t.k` (no field id), read under a schema where `j` was dropped and added again with a default, `SELECT t` returned `(7,100)` but `SELECT t.j` returned the default `9`, and both `WHERE t.j = 100` and `WHERE t.j = 9` matched nothing with filter push-down. The reader now passes the structs of the file with a field without a field id to the conversion, which matches their fields by name, as the selection does, so `t.j` reads `100` as on master. Reported in ClickHouse#130101 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The ORC filter push-down guard resolved a filter column by Iceberg field id at every struct on its way and gave up at a struct with a field without a field id, so push-down stayed enabled. The reader matches such a struct by name and the structs below it by field id, so the two could disagree one struct deeper: in an ORC file with `t.s.j` (field id 4) and `t.k` (no field id), read under a schema where `t.s.j` was dropped and added again with `initial-default = 9`, `SELECT t` returned `((9),7)` but `WHERE t.s.j = 9` matched nothing with push-down, because the search argument was built on the old physical `j`. The guard now resolves a struct with a field without a field id by name, as the reader selects it, so it sees that `t.s.j` is absent from the file while a field of that name is in it, and disables push-down. Reported in ClickHouse#130101 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
396cfed
One conflict, in NativeORCBlockInputFormat.cpp: master (ClickHouse#130101) selects and reads the fields of a struct by Iceberg field id when all of them have one, and this branch pairs them by name with DataTypeTuple::matchElementsByName. Both are kept: the field id first, else the name pairing; findORCStructFieldByName, which the new master code still calls, is the one-name case of that pairing. The missing-column fill keeps master's absent-column default before createMissingColumn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the name mapping Since ClickHouse#130101 a field that a Parquet data file proves absent (every field of its level has a field id, none of them the field's) reads as its `initial-default`. A file without field ids never proved that, so a field added with an `initial-default` read as NULL from the files read through `schema.name-mapping.default`. Their ids come from the mapping, and an element the mapping does not name is not in the table, so the absence check now takes the ids from `getFieldId` and skips such elements, like Iceberg Java's readers after `ApplyNameMapping`. The test also covers the JOIN runtime filter file pruner of the merge: with the names of `id` and `b` swapped in the mapping, pruning by the manifest bounds of `id` lost the row of `id` 50. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…apper path The `initial-default` code of ClickHouse#130101 keyed the field ids of a struct, and looked up the default of a missing tuple element, by `TraversalNode::name`, which master sets to the ColumnMapper path (`l.element`) inside a list. This PR keeps `name` the ClickHouse name (`l`) and the mapper path in `column_mapper_path`, so after the merge a field added with an `initial-default` to the element struct of a list read as NULL, or threw THERE_IS_NO_COLUMN (05568_iceberg_initial_default). Both lookups now use `getColumnMapperPath()`, as does the map key/value check of ClickHouse#130102. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rquet-list-element-subcolumn The `initial-default` code of ClickHouse#130101 (merged 2026-11-18) relies on the list element node being named with the column mapper path, which this PR changes: 05568_iceberg_initial_default fails on the merge of this PR with master. The fix in the next commit uses that code, so it needs master.
…column mapper path ClickHouse#130101 keyed the field ids of a struct, and looked up the default of a missing tuple element, by `TraversalNode::name`, which master set to the column mapper path (`l.element`) inside a list. This PR keeps `name` the ClickHouse name (`l`), so on the merge with master a field added with an `initial-default` to the element struct of a list was read as NULL, or threw THERE_IS_NO_COLUMN with `input_format_parquet_allow_missing_columns = 0` (05568_iceberg_initial_default). Both lookups now use `getColumnMapperPath()`. The subcolumn `l.y` of such a field, read without the rest of `l` (addMissingElementOfTupleInArray), now takes the `initial-default` of `l.element.y` instead of NULL, keeping the sizes of `l`, also with `input_format_parquet_allow_missing_columns = 0`, which now only rejects it when there is no default. Requested on ClickHouse#130023 (issuecomment-6935263914). ORC already read these values. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #129992
Related: #130028
Related: #130010
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed reading Iceberg tables with columns added with an
initial-default: rows of data files written before such a column was added now return the default instead ofNULL, also in filters and for fields added inside a struct, and a required column added with a default no longer makes the table unreadable.Description
On 26.10.2.103,
SELECT * FROM icebergLocal('iceberg_v3/iceberg_v3_default_value')(Impala test table,jadded with"initial-default": -1) returns1 \Ninstead of1 -1, andWHERE j = -1returns nothing.ClickHouse never parsed
initial-default. A field absent from a data file is synthesized with the type default in two places: the schema evolution DAG, for a file read under its own older schema, and the format reader, for a file read under the schema that has the field.The default is now parsed once in
IcebergSchemaProcessor(the spec's JSON single-value serialization, all types), used by the DAG, and passed throughColumnMapperto the Parquet, ORC and Avro readers. A reader fills a field with its default only if the file has field ids at that level and none is the field's id (the rule of #126879); ORC and Avro no longer bind it to a same-named field of the file (a dropped and re-added column). An identity partition value of the file, even NULL, still comes before the default (NULL partition values are now applied). The query condition cache key of a table function and the Parquet columns cache key include the defaults. A metadata.json schema replaces an identical manifest-header copy, which lacks the defaults.Test: the Impala and DuckDB tables of #130028 and #130010, as written and under the newer schema, plus ClickHouse-written Parquet, ORC and Avro tables evolved with nested, required, struct, list and malformed defaults; fails on master, passes with the fix (50/50 randomized).
Unchanged:
write-defaultonINSERT, Vortex (no field ids), a field missing inside an Avro record on the newer schema (still an error), equality deletes on absent fields (#129997). A struct that is NULL in a row reads its added fields' defaults (an Iceberg struct is read as a non-NullableTuple).Workflow [PR]
Sync PR [sync-upstream/pr/130101]
Version info
26.11.1.2692-master(included in26.11and later)