Repository navigation
Read a column missing from an Iceberg Avro data file as NULL - #126879
alexey-milovidov merged 12 commits into
Conversation
An INSERT planned before `ALTER TABLE ... ADD COLUMN` commits its data file under the widened schema (accepted since ClickHouse#121821), so the file lacks an optional field of the schema its manifest names. The Iceberg spec reads such a field as null, but whether the format reader tolerated it was left to the generic `input_format_avro_allow_missing_fields` (default 0) and `input_format_{parquet,orc}_allow_missing_columns` settings: every Avro query reading the column failed with `Field d not found in Avro schema`, and Parquet/ORC failed the same way when a user set those settings to 0. Pin the three settings in `IcebergMetadata::modifyFormatSettings`, as `DeltaLakeMetadataDeltaKernel::modifyFormatSettings` already does for Parquet, and for the compaction reader in `IcebergMetadata::optimize`, which reads data files with the storage's own format settings. Compaction rewrites data files only when position deletes exist, and only Parquet tables accept DELETE, so the test covers it with a Parquet DELETE before OPTIMIZE. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Iceberg (apache/iceberg TypeToSchema) writes a column whose name is not a
valid Avro name under an escaped name (`name.column` as `name_x2Ecolumn`) and
keeps the original in the field property `iceberg-field-name`. The Avro reader
matches fields by name only, so with missing fields tolerated (now always the
case for Iceberg reads) such a present column would be read as NULL instead of
failing. `AvroRowInputFormat` now reads `iceberg-field-name` of the top-level
fields from the file's writer schema and resolves a header column that no
field matches directly by that name. A column that another field already
resolves to, directly or by alias, is not aliased again, so a crafted file
cannot write two fields into one column.
Compaction reads every data file under the current schema's names without a
per-file schema transform, and only Parquet resolves them by field id, so it
now tolerates missing columns for Parquet only: an Avro or ORC file written
before a RENAME COLUMN must not be rewritten with defaults.
The test fixture `data_avro/iceberg_escaped_field_name.avro` was generated
with Python `avro` 1.12.1:
schema = avro.schema.parse('{"type": "record", "name": "r1", "fields": [{"name": "id", "type": "int", "field-id": 1}, {"name": "name_x2Ecolumn", "type": "string", "field-id": 2, "iceberg-field-name": "name.column"}]}')
DataFileWriter(out, DatumWriter(), schema, codec="null") with rows (1, 'a'), (2, 'b'), (3, 'c')
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The alias for a top-level field stored under an escaped name was taken
while walking the record, so it was refused only for a field directly named
the original or a column an EARLIER field had bound. A LATER field whose
descendant path equals the alias (a nested record `n` with `c` for `n.c`,
a union branch, a flattened `Nested` array) still bound the same column,
and two actions wrote into one column: three values per row, or a
LOGICAL_ERROR in `Chunk::checkNumRowsIsConsistent`.
`createAction` now binds a record in two passes. The first is the loop as
it was before aliases existed, so every direct binding wins regardless of
field order. The second binds an alias only into a column that is still
unbound, and only from a top-level field that bound nothing in the first
pass, whose action just reads and discards the value; each such binding
marks the column, so of two aliases of one name the first in field order
wins.
The test fixture `data_avro/iceberg_field_name_collision.avro` was
generated with Python `avro` 1.12.1:
schema = avro.schema.parse(json.dumps({"type": "record", "name": "r", "fields": [
{"name": "x", "type": "string", "iceberg-field-name": "y"},
{"name": "y", "type": "string"},
{"name": "p", "type": "string", "iceberg-field-name": "n.c"},
{"name": "n", "type": {"type": "record", "name": "R", "fields": [{"name": "c", "type": "string"}]}},
{"name": "q1", "type": "string", "iceberg-field-name": "z"},
{"name": "q2", "type": "string", "iceberg-field-name": "z"}]}))
DataFileWriter(out, DatumWriter(), schema, codec="null") with rows i = 1..3:
x = 'x<i>', y = 'y<i>', p = 'p<i>', n = {c: 'n<i>'}, q1 = 'q1_<i>', q2 = 'q2_<i>'
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove a comment that restates the second binding pass in AvroDeserializer::createAction. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (rounds 0-2): 3 findings fixed before publish, 1 narrowed, 1 disagreed with evidence
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261020-024100 |
|
cc @scanhex12 @Avogar, could you review this and add the |
|
Workflow [PR], commit [a7ed5ae] Summary: ✅
AI ReviewSummaryThis PR passes the Iceberg Final VerdictStatus: ✅ Approve |
…the file Enabling `input_format_avro_allow_missing_fields` for every Iceberg read also defaulted a column the data file holds under another name: a column renamed after the file was written read as NULL wherever the reader resolved the file under the renamed schema (a stale INSERT across RENAME COLUMN, or a manifest rewrite followed by snapshot expiry), where master raised `Field b not found in Avro schema`. The Avro reader now gets the Iceberg `ColumnMapper` (through a new `IInputFormat::setColumnMapper`, which `FormatFactory` calls for the formats whose creator does not receive the `FormatFilterInfo`), and defaults a column only when the file identifies every top-level field by `field-id` and the column's field id is not among the file's ids, as the Iceberg column projection rules require. Any other column it does not find still fails. The `iceberg-field-name` alias is removed: it existed only so that the blanket setting could not blank an escaped column, and which field it bound depended on the projection. The ORC and Parquet settings are no longer pinned either, neither for reads nor for compaction: both already default to tolerating a missing column, ORC resolves columns by name like Avro, and the pins only overrode a user who disabled the setting. Co-Authored-By: Claude Opus 5.5 <[email protected]>
NULL in every formatAvro data file as NULL
The RENAME COLUMN block relied on a stale INSERT that writes the renamed column without a field id. ClickHouse#126768 refuses that INSERT for every format, so the block would start failing as soon as it is merged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes55 object files changed (+271.87 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 units160 translation units recompiled, 1294 s compile time in total, 160 of them have a recent master baseline. |
…missing-from-data-file Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126879&sha=d673fb05c34f9b6d234acc7064729ae5eb8bc094&name_0=PR&name_1=Stress%20test%20%28amd_msan%29 (Segmentation fault, STID 2661-3aba, in |
|
The fix is #127912 (open). If a web terminal session closes while the embedded client asks whether to print a binary format (RowBinary, BSONEachRow, ODBCDriver2), the #126142 is a different defect on the same |
|
🕵 @groeneai, investigate the failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126879&sha=47777f57851260101b05c052ced7c16bc3b53cc3&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29 ( |
|
|
🕵 @groeneai, investigate the failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126879&sha=5ff546ad542f6a2a235a59695e8085f26999074b&name_0=PR ( |
|
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126879&sha=3b4a14473b80b91f0e41e098e6309b7e14c29893&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 ( The other failure, |
|
This is the race #125026 fixes, and #125026 is still the in-progress fix, so no separate PR is needed. The run had |
On 2026-10-30 the performance dashboard backend was switched to a new CIDB (explained by egor-click on ClickHouse#128236). For about 3 minutes (14:09:54Z to 14:13:05Z, measured from the polls of 6 shards) it answered HTTP 500 with ClickHouse code 60 for the tables it reads: failed to resolve performance comparison run: code: 60, message: Unknown table expression identifier 'perf_test_times_v1' failed to load performance comparison rows: code: 60, message: Unknown table expression identifier 'query_metrics_v2' `dashboard_did_not_answer` knew no signature for this message, so the 500 was a `PerfDashboardError`; the poll loop keeps the first hard error, and `main` failed the shard instead of judging it by its own report. Four `Performance Comparison (arm_release, master_head, N/6)` jobs whose 600 s wait ended inside the window failed this way (ClickHouse#126879 6/6, ClickHouse#128209 1/6 and 3/6, ClickHouse#128097 2/6), all with 0 slower queries. Shards whose wait outlived the window got the same requests answered with 200 and passed. The request cannot cause this answer: the table names are the backend's own storage, and identical requests (same run id and test) were served after the window. It is the case the class documents, "the dashboard, or the CIDB tables it reads, did not answer", so add the measured signature next to the two existing ones. Only a 5xx with an application envelope is affected; a 4xx with this text, a non-JSON body, and every other 5xx keep their classification, and a real hard error seen before or after it still wins. Validated locally against a fake dashboard serving the logged bodies: the incident replay fails on master and reaches the own-report fallback with the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The sink guard refused an INSERT whose block omits fields added since it was planned when the table is written as Avro, because the Avro reader used to reject a data file lacking a field of its schema. Master now reads such a field as NULL (ClickHouse#126879), and its test 05411_iceberg_read_field_missing_from_data_file writes exactly that file, so the carve-out failed it deterministically. Avro now follows Parquet and ORC: the input may omit fields and its columns are matched by name. The Avro case of 04365 asserted the old refusal; 05411 covers the now accepted shape. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
Related: #121821
Related: #109838
Related: #126768 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Field ... not found in Avro schemaon every query reading a column of anAvroIceberg table after anINSERTwas committed whileALTER TABLE ... ADD COLUMNadded that column. A column whose Iceberg field id is not in anAvrodata file is now read asNULL, as the Iceberg spec requires.Description
On 26.9.19.9, after an
INSERTinto anAvroIceberg table commits whileALTER TABLE t ADD COLUMN d Nullable(Int64)runs, every query that readsdfails withField d not found in Avro schema.Since #121821 such an
INSERTcommits its data file, which lacksd, under the widened schema. That is valid Iceberg: a field whose id is not in a data file reads as null. But the Avro reader matches fields by name and fails on any column it does not find, and enablinginput_format_avro_allow_missing_fieldswould also blank a column the file holds under another name (a renamed column read under the renamed schema).The Avro reader now receives the Iceberg
ColumnMapper, as the Parquet reader already does:IInputFormat::setColumnMapper, called byFormatFactoryfor formats whose creator does not take theFormatFilterInfo. A column the reader does not find is read asNULLonly if the file identifies every top-level field byfield-idand the column's field id is not among them. Any other missing column still fails as before. Parquet resolves columns by field id already, and the Parquet and ORC missing-column settings default to tolerant, so they are unchanged.The test builds the stale commit with
iceberg_metadata_file_pathand readsdasNULLwithinput_format_avro_allow_missing_fields = 0. It fails on master and passes with the fix (50/50 runs). After a staleINSERTacrossRENAME COLUMN, whose file has no field id for the renamed column, reading that column still fails instead of returningNULL(checked locally: #126768 refuses thatINSERT).Workflow [PR]
Sync PR [sync-upstream/pr/126879]
Version info
26.11.1.959-master(included in26.11and later)