Repository navigation
Do not read a Parquet map as an unrelated Tuple filled with default values - #130102
Conversation
`SchemaConverter::processSubtreeMap` dropped the MAP interpretation of a Parquet group for any requested `Tuple`, so that the literal shape of the schema tree, `Tuple(key_value Array(Tuple(key, value)))`, stays readable. `processSubtreeTuple` then matched the requested elements to the group's children by name. The only child is the repeated `key_value` group, so a Tuple such as `Tuple(value String)` matched nothing, every element became a missing column, and the read returned defaults (`NULL` for the Iceberg case) instead of the data or an error. With `input_format_parquet_allow_missing_columns = 0` it failed with `THERE_IS_NO_COLUMN`, which is not a type error either. This is how an Iceberg table whose schema has `payload struct<value: string>` read a data file that stores `payload` as a map (ClickHouse#130020): the requested type comes from the table schema, the file has no field ids, and the column is matched by name. Plain `file()` with an explicit structure shows the same in every nesting position (top level, list element, map value, struct field). Keep the literal fallback only for a Tuple that describes the map's tree: an unnamed Tuple (matched by position), or a named Tuple that has an element named like the repeated group, matched as `processSubtreeTuple` matches it (column mapper + `case_insensitive_column_matching`). Any other Tuple now reaches the existing `parquet type is Map, requested type is ...` `TYPE_MISMATCH`, the same error every other kind mismatch in this reader raises. A query that does not read the column is unaffected. The check runs after the structure checks, so a MAP-annotated group without the MAP structure keeps the literal fallback for any request. A generic "a named Tuple that matches no child is an error" rule in `processSubtreeTuple` would be wrong for structs: Iceberg schema evolution (drop one field, add another) legitimately produces it and NULL is the right answer there. Only the map case is a kind mismatch. The test adds the `map_to_struct` table of the DuckDB Iceberg extension tests (duckdb/duckdb-iceberg b57f45c2c78965c71f699aa23ae73c292923668e), at the same path and with the same content as ClickHouse#130010. Closes ClickHouse#130020 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The README carries the provenance and the MIT notice of the copied fixture; ClickHouse#130010 adds a README at the same path with a superset of this content (whichever lands second keeps ClickHouse#130010's). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the Tuple fallback comment in processSubtreeMap to one line and state that a positional Tuple also falls back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261108-080000 |
|
cc @al13n321 @grantholly-clickhouse, could you review this and add the |
|
Workflow [PR], commit [f0bcb50] Summary: ✅
AI ReviewSummaryThe change rejects Parquet maps requested as unrelated named Missing context / blind spots
Final Verdict✅ Approve — no code changes requested. CI validation remains outstanding. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
5a203e1
|
@al13n321, a design question on the tuple-element pushdown into the Parquet reader, before I send a fix for the subcolumn path that the description above leaves unchanged. On master, with a Parquet file where SELECT l.foo FROM file('f.parquet', Parquet, 'l Tuple(foo Nullable(String))'); -- NULL
SELECT l FROM file('f.parquet', Parquet, 'l Tuple(foo Nullable(String))'); -- TYPE_MISMATCH: parquet type is Array
Options:
Which do you prefer: A, B or C? |
…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]>
Closes: #130020
Related: #130010
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed reading a Parquet
Mapcolumn as aTuplethat does not describe the map, for example an Iceberg table whose schema has a struct where a data file stores a map: the elements of theTuplewere silently returned asNULLor default values, now the query throwsTYPE_MISMATCH. Closes #130020.Description
On 26.10.2.103 (and 26.3.60.2),
SELECT * FROM file('m.parquet', Parquet, 'id Int64, payload Tuple(value Nullable(String))')over a Parquet map columnpayloadreturns2 (NULL)instead of a type mismatch error; themap_to_structIceberg table of #130020 returns(NULL)for the row whose data file stores a map.SchemaConverter::processSubtreeMapdropped the MAP interpretation for any requestedTuple, to keep the literal readingTuple(key_value Array(Tuple(key, value)))of the schema tree.processSubtreeTuplethen matched the requested elements by name against the only child, the repeatedkey_valuegroup: nothing matched, and every element was filled as a missing column. This happens in every position (top level, list element, map value, struct field).The literal fallback is now kept only for a
Tuplethat describes the map's tree: unnamed, or with an element named like the repeated group, matched asprocessSubtreeTuplematches it (incl.input_format_parquet_case_insensitive_column_matching). Any otherTuplegets the existingparquet type is Map, requested type is ...error; queries that do not read the column are unaffected.Siblings: the other eight cases of the DuckDB test are already rejected, and so is this case in Avro and Arrow files. ORC returns defaults for any kind-mismatched column (a different reader). A tuple-element subcolumn such as
payload.foois matched by its flattened name, so it still reads defaults when the file storespayloadas a map, a list or a primitive (a separate path). Neither is changed here.Validation: the new test fails on master on 8 of its 16 lines and passes with the fix; the
mapping_failuresloop of #130010's05712now matches its reference; the Parquet, Iceberg, Delta and Hudi stateless tests show no new failures.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130102]
Version info
26.11.1.1687-master(included in26.11and later)