Repository navigation
Conversation
Iceberg v3 stores a `variant` in ORC as a struct of two binary fields,
`metadata` and `value`, in the variant binary encoding, and Iceberg asks
the ORC reader for the column as `Dynamic`. `updateIncludeTypeIds`
selected the fields of a struct only for a `Tuple` request, so for
`Dynamic` nothing was read, the column was treated as missing and filled
with defaults: every value of such a column was NULL, with no error.
A struct requested as `Dynamic`, `JSON` or `Nullable(JSON)` is now
selected in full and decoded with `Parquet::decodeVariantColumn`, before
the `Nullable` wrapping (a `Dynamic` cannot be inside `Nullable`, and the
decoder produces the NULLs). Only a struct of exactly two binary fields
named `metadata` and `value` is accepted, in either order: Iceberg writes
binary, and Parquet likewise only reads binary leaves as a variant. Any
other struct requested as `Dynamic` or `JSON` raises TYPE_MISMATCH instead
of returning NULL or `{}`. The struct's nulls reach both fields through
`StructColumnReader`, so a non-null empty blob is a malformed file, not a
null, and raises INCORRECT_DATA; without that check the decoder would
read it as NULL.
`ORCColumnToCHColumn` takes the `FormatSettings`, which the decoder needs
(`max_parser_depth`, the JSON skip-path option), instead of five values
copied out of them. `VariantEncoding.cpp` is also compiled into `dbms`
when ORC is enabled without Parquet (the FreeBSD build).
Closes ClickHouse#130031.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the comment narrating isORCVariantTargetType, shorten the struct-selection comment, fold the readVariantFromORCStruct doc into one line. 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; 0 findings) plus my own review (4 nits, none blocking).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261108-091100 |
|
Workflow [PR], commit [77b7f37] Summary: ❌
AI ReviewSummaryThe PR decodes Iceberg v3 variant blobs in ORC structs requested as Consumer tracing covered direct chunk output, Findings❌ Blockers
Tests
Missing context / blind spots
Final VerdictStatus: ❌ Block Preserve ordinary binary-struct conversion and decode explicitly requested dotted variant fields consistently, with the focused regressions above. Both remaining findings already have inline threads; no duplicate comments were posted. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261108-080700 |
|
cc @scanhex12 @Avogar, could you review this and add the |
CI finish ledger - b9a4b73Every 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-143005 |
…ceberg-variant
Conflicts in `src/CMakeLists.txt` and `NativeORCBlockInputFormat.{cpp,h}`:
- Master builds `VariantEncoding.cpp` without Parquet for Avro too, so the
condition is now `elseif (USE_AVRO OR USE_ORC)`.
- `ORCColumnToCHColumn` gained the data lake arguments on master; it now
takes `FormatSettings` in place of the five settings it took from it,
keeping the new arguments.
- `decodeVariantColumn` takes `Parquet::VariantSettings` on master.
- The `updateIncludeTypeIds` hunk that selected a struct whole for a
`Dynamic` or `JSON` request is dropped: since ClickHouse#130171 every list, map or
struct requested as another kind is selected whole.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… throwing Since ClickHouse#130171 an ORC struct requested as another kind is read whole and cast to the requested type, so `file('t.orc', ORC, 'v JSON')` over `struct<a:int,b:string>` returns `{"a":1,"b":"x"}` on master, as Parquet does. The variant reader threw `TYPE_MISMATCH` for every struct that is not exactly two binary fields `metadata` and `value`, which after the master merge would reject such input. Only a variant-shaped struct is decoded now; any other struct takes the cast path. The test checks the cast for a plain struct, a struct with other field names and a struct of `string` fields. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| checkStackSize(); | ||
|
|
||
| /// Before the Nullable wrapping below: `Dynamic` cannot be inside `Nullable`, and the decoder makes NULLs itself. | ||
| if (isORCVariantRead(*orc_type, type_hint)) |
There was a problem hiding this comment.
[Blocker] Preserve the variant type hint when reading a dotted column
The new decoder is skipped for a variant requested through a dotted schema. For example, using this test's nested.orc, compare:
SELECT t.v FROM file('nested.orc', ORC, 't Tuple(v Dynamic)');
SELECT * FROM file('nested.orc', ORC, '`t.v` Dynamic');The second request reaches orcColumnsToCHChunk's nested-column path. Nested::collect(nested_columns).front().type is just Dynamic here, since it only collects arrays into Nested. Consequently, readColumnFromORCColumn receives that hint for t, and its child v receives no hint. This condition then rejects v, and the final cast wraps the raw metadata/value tuple in Dynamic instead of decoding the object. Requesting the same value as a whole tuple or as a dotted field therefore returns different data; the analogous JSON request also exposes the blobs.
Reconstruct the parent type hint from the requested dotted fields for ordinary ORC reads too (the column_mapper path already does this), and add a stateless assertion comparing these two projections.
There was a problem hiding this comment.
Fixed in f53e790: a struct read for its dotted subcolumns now gets its type hint from them in ordinary ORC reads too, and 05569 compares the two projections.
There was a problem hiding this comment.
[Blocker] The simple struct projection is fixed, but the same hint loss remains for a list containing nested structs.
At src/Processors/Formats/Impl/NativeORCBlockInputFormat.cpp:3709, an ordinary ORC::LIST still needs column_mapper to enter recursive hint reconstruction. For a file with a Array(Tuple(s Tuple(v Tuple(metadata String, value String)))), containing an encoded object, compare:
SELECT a.s.v
FROM file('deep_array.orc', ORC, 'a Array(Tuple(s Tuple(v Dynamic)))');
SELECT *
FROM file('deep_array.orc', ORC, '`a.s.v` Array(Dynamic)');The first returns the decoded object array; the second returns an array of raw (metadata, value) tuples. Nested::collect gives the list element a flat s.v field hint, so its actual field s and the variant below it receive no hint. A shallow a.v projection works, which hides the deeper case.
This was reproduced with the 48997f039 PR binary; the final commit leaves this list path unchanged. Extend the recursive hint construction to list roots and compare these projections in the regression test.
There was a problem hiding this comment.
Reverted in 77b7f37: ORC reads a query's subcolumn such as t.v through the whole column t, which decodes the variant, so only an explicit flat schema like `t.v` Dynamic reaches this path. Rebuilding the hint there broke the existing t.null projection, so that schema keeps master's behaviour for every type.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 22 s compile time in total, 9 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: No query shows a performance change caused by this PR. The tested code adds Iceberg variant decoding to the native ORC reader and touches nothing else on the query path. The only flagged query, clickbench Q28 (+7.1%, 1002 ms to 1073 ms), is already inconclusive: the two tests disagree and the measurements on both sides were noisy. Q28 is a MergeTree scan with regex and GROUP BY that never runs the ORC reader, so the delta is not from this PR, and its cause was not checked. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Outside the data lake schema, a dotted request such as `t.v Dynamic` read the struct `t` with the type of its first requested subcolumn as the hint (`Nested::collect` only builds `Nested` from arrays), so its field `v` got no hint, the variant decoder was skipped, and the raw `metadata`/`value` tuple was cast to `Dynamic`. `t Tuple(v Dynamic)` and Parquet both decode it. A struct read for its dotted subcolumns now gets the hint from them in ordinary reads too: `makeTypeHintFromSubcolumns`, which the data lake path already uses, takes an optional `ColumnMapper`; without one, an element is the longest prefix of the subcolumn path that the file's struct has as a field, so a field named `v.w` is found as well. Lists keep the `Nested::collect` hint. Non-variant dotted reads of structs give the same results as before (30 shapes: casts, Nullable, LowCardinality, nested tuples, arrays and maps inside the struct, missing and case-insensitive fields, fields with dots in their names). Co-Authored-By: Claude Opus 5.5 <[email protected]>
| /// `Dynamic` or `JSON`. | ||
| static bool isORCVariantRead(const ORC::Type & orc_type, const DataTypePtr & type_hint) | ||
| { | ||
| if (orc_type.getKind() != ORC::STRUCT || orc_type.getSubtypeCount() != 2 || !type_hint) |
There was a problem hiding this comment.
[Blocker] Distinguish an Iceberg variant from an ordinary binary struct
This treats every two-binary-field struct named metadata and value as a variant, even when it has no variant annotation. The Iceberg ORC mapping identifies variants with iceberg.struct-type=VARIANT; ORC::Type::buildSelectedType preserves that attribute.
For example, write an ordinary ('meta', 'payload')::Tuple(metadata String, value String) with output_format_orc_string_as_string=0. Reading it as v JSON or v Dynamic now throws Unsupported Parquet variant metadata version 13. Reading it as a Tuple and then casting still returns the original fields, which is the existing generic struct conversion. Ordinary data can also accidentally contain valid encoding bytes and silently become a different value.
Require the variant annotation or an explicit variant schema/opt-in before decoding, preserve the cast for ordinary structs with these names, and add a regression covering this collision.
There was a problem hiding this comment.
Not changing this: it is Parquet's rule for an explicit Dynamic/JSON request, and the same ('meta', 'payload') written to Parquet with output_format_parquet_string_as_string = 0 and read as v JSON fails on master with the same Unsupported Parquet variant metadata version 13. With the default output_format_orc_string_as_string = 1 the fields are ORC string, and the struct is cast as before.
…ke schema This reverts f53e790. Rebuilding the type hint of a struct from its dotted subcolumns in ordinary reads turned virtual subcolumns into tuple elements, so the existing projection `t.a Nullable(Int32), t.null UInt8` over a nullable struct failed with BAD_ARGUMENTS (`null` is a reserved tuple element name) where master reads it, and it still missed lists. ORC does not read tuple elements on its own: a query's subcolumn `t.v` is read through the whole column `t` and decoded as the variant, so a dotted name reaches this path only from an explicit flat schema such as `t.v Dynamic`. That request keeps master's behaviour for every type. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #130031
Related: #130028
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed reading Iceberg v3
variantcolumns from ORC data files, which returnedNULLfor every row: an ORC struct of twobinaryfieldsmetadataandvalueread asDynamicorJSONis now decoded with the variant binary encoding, as for Parquet. Closes #130031.Description
On 26.10, reading an Iceberg v3 table whose data files are ORC returns
NULLfor everyvariantvalue (measured on26.10.2.103; the Parquet copy of the table is read correctly). Iceberg is not needed:file('t.orc', ORC, 'v Dynamic')over thestruct<metadata: binary, value: binary>that Iceberg writes gives the same NULLs. On master the same queries return the rawmetadata/valueblobs instead, since #130171 casts such a struct.Iceberg maps
varianttoDynamic, and the ORC reader had no variant decoding.Now a struct of exactly two
binaryfields namedmetadataandvalue(either order) requested asDynamic,JSONorNullable(JSON)is decoded with Parquet'sdecodeVariantColumn; an empty non-null blob raisesINCORRECT_DATA. Any other struct is still cast to the requested type.ORCColumnToCHColumntakes theFormatSettings, andVariantEncoding.cppis also built with ORC but without Parquet (FreeBSD). Schema inference andTuplereads of the struct are unchanged.Validation:
05569_orc_read_variantcovers optional and required structs, swapped fields,JSON/Nullable(JSON), nesting inArray/Map/Tupleand in a nullable struct, malformed variants, and the cast of non-variant structs. It fails on master and passes 10/10, and a mutation of thebinarycheck reddens it. The issue's table gives the values #130028's05707_iceberg_impala_v3_variantexpects. All other ORC, Iceberg ORC and variant stateless tests pass.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130116]