Skip to content

Do not read a Parquet map as an unrelated Tuple filled with default values - #130102

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/parquet-map-requested-as-tuple-type-mismatch
Nov 8, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/parquet-map-requested-as-tuple-type-mismatch

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130020
Related: #130010

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed reading a Parquet Map column as a Tuple that 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 the Tuple were silently returned as NULL or default values, now the query throws TYPE_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 column payload returns 2 (NULL) instead of a type mismatch error; the map_to_struct Iceberg table of #130020 returns (NULL) for the row whose data file stores a map.

SchemaConverter::processSubtreeMap dropped the MAP interpretation for any requested Tuple, to keep the literal reading Tuple(key_value Array(Tuple(key, value))) of the schema tree. processSubtreeTuple then matched the requested elements by name against the only child, the repeated key_value group: 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 Tuple that describes the map's tree: unnamed, or with an element named like the repeated group, matched as processSubtreeTuple matches it (incl. input_format_parquet_case_insensitive_column_matching). Any other Tuple gets the existing parquet 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.foo is matched by its flattened name, so it still reads defaults when the file stores payload as 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_failures loop of #130010's 05712 now 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

  • Merged into: 26.11.1.1687-master (included in 26.11 and later)

groeneai and others added 3 commits November 8, 2026 07:27
`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]>
@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review
Finding Verdict
❌ The copied DuckDB fixture had no MIT notice Agreed, fixed: data_iceberg/duckdb/README.md carries the provenance and the license
⚠️ A tuple-element subcolumn (payload.foo) still reads defaults Not changed here: it is matched by its flattened name and behaves the same for a map, a list or a primitive in the file, a separate path (disclosed in the description)
⚠️ A truncated MAP schema now gives std::out_of_range for a Tuple request Not changed: the same .at is already reached for every other request and for LIST groups; only the error class of a corrupt file differs
💡 A MAP used as a map key keeps the literal reading on this PR alone Composes with #130080, which adds the map-key context to the same check
💡 data_iceberg/duckdb/README.md is also added by #130010 with other content The fixture files are byte-identical; whichever PR merges second keeps #130010's README

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT * FROM file('m.parquet', Parquet, 'id Int64, payload Tuple(value Nullable(String))') over a Parquet map column returns 2 (NULL) on master every time; the issue's icebergLocal('.../map_to_struct') returns 1 ('profile'), 2 (NULL).
b Root cause explained? processSubtreeMap fell back to the literal schema-tree reading for any requested Tuple. processSubtreeTuple then matched the requested names against the map's only child, the repeated key_value group; nothing matched, so every element was filled as a missing column (input_format_parquet_allow_missing_columns, on by default).
c Fix matches root cause? Yes. The fallback is kept only for a Tuple that describes the map's tree (unnamed, or naming the repeated group, matched like processSubtreeTuple); any other Tuple reaches the existing TYPE_MISMATCH of the same function. No new error path or setting.
d Test intent preserved / new tests added? New 05572_parquet_map_requested_as_tuple: the map at the top level, in a list, as a map value and in a struct; the literal, positional and case-insensitive Tuple reads that must keep working; reading other columns; the Iceberg table from the issue (fixture copied from duckdb-iceberg, provenance and MIT notice in data_iceberg/duckdb/README.md).
e Both directions demonstrated? Yes. On the master binary the test differs on 8 of 16 reference lines; with the fix it passes (50/50 runs). Three mutations of the new predicate (always literal, never literal, case-sensitive) each fail the test.
f Fix is general across code paths? The one site that drops the MAP interpretation is fixed for all contexts it handles; LIST groups already reject a Tuple (REPEATED level needs an Array); struct groups keep name matching on purpose (schema evolution). All Parquet consumers (file, url, s3, Iceberg, Delta, Hudi) share this reader. Not changed here: ORC (a different reader) and a tuple-element subcolumn (payload.foo, matched by its flattened name, same result before and after).
g Fix generalizes across inputs (params/datatypes/wrappers)? Covered positions: top level, Array element, Map value, Tuple element, nullable (Iceberg file) and required groups. Nullable(Tuple), Tuple() and Tuple(String) hints were already rejected and are unchanged; Map, Array(Tuple) and JSON hints are unchanged; both values of allow_missing_columns and of case_insensitive_column_matching are tested.
h Backward compatible? (maintainer-approved exception only) A named Tuple request that describes nothing in the map used to return defaults and now throws; that result was not the data. The literal and positional Tuple reads, and every non-Tuple request, behave as before. No setting, no format change.
i Invariants and contracts preserved? The check runs after the MAP structure checks, so a malformed MAP keeps the literal fallback for any request. It calls the same useColumnMapperIfNeeded on the same child that processSubtreeTuple would call, so name and field-id resolution and their errors are the same as before.

Session id: cron:clickhouse-impl-slot-5:20261108-080000

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @al13n321 @grantholly-clickhouse, could you review this and add the can be tested label so CI runs? SchemaConverter::processSubtreeMap kept the literal schema-tree reading for any requested Tuple, so a Tuple that names nothing in a Parquet map (an Iceberg struct over a file that stores a map) was filled with defaults; now only a positional Tuple or one naming the repeated group falls back, and any other Tuple gets the existing parquet type is Map TYPE_MISMATCH.

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f0bcb50]

Summary: ✅


AI Review

Summary

The change rejects Parquet maps requested as unrelated named Tuple types instead of silently returning default values, while preserving positional and literal schema-tree reads. Reviewed PR head f0bcb50f38a1fce062130e26372a38a3e5a63dac, the full modified converter, its callers, regression coverage, and all prior discussion. No actionable findings.

Missing context / blind spots
  • ⚠️ Runtime validation was not independently repeated: this checkout has no ClickHouse binary or build directory. The author reports that the new test fails on master and passes with the fix, including mutation checks. CI bugfix-validation jobs were dropped, and Finish Workflow reports missing bugfix validation. A successful CI run of 05572_parquet_map_requested_as_tuple and its bugfix validation would close this independent-execution gap.
Final Verdict

✅ Approve — no code changes requested. CI validation remains outstanding.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). labels Nov 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f0bcb50f3 with master 7b5f2bf32 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Nov 8, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 8, 2026
Merged via the queue into ClickHouse:master with commit 5a203e1 Nov 8, 2026
373 of 375 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 8, 2026
@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

@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 l is a list, m a map, p a string and id an Int64:

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

m.foo and p.foo also return NULL, id.foo returns 0, and WHERE p.foo IS NULL matches the row. filterTupleColumnsToRead pushes l.foo down as a flat name, and SchemaConverter::prepareForReading fills an unmatched flat name as a missing column. The flat name can also match an unrelated column: in a file with l Array(UInt8) and a top-level column literally named l.foo, the element l.foo returns that column's value.

Options:

  • A. Carry the resolved path (element names and array steps) from filterTupleColumnsToRead to the reader through ReadFromFormatInfo and a new IInputFormat setter, and throw TYPE_MISMATCH when a file node on that path is a list, a map or a non-String primitive where the declared type needs a tuple (or a tuple where it needs an array). About 10 files. A String parent keeps today's default, since the whole-column read parses tuple text ('(''abc'')' reads as ('abc')).
  • B. When the exact path of a pushed-down element is not in the file, read the parent column with its declared type and extract the element, so the result matches the whole-column read (including the String parse and the flat-name collision). Needs the declared type in the reader and an extract step in Reader.
  • C. Leave it as is: the structure is mis-declared, and reading the whole column already fails.

Which do you prefer: A, B or C?

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 23, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg: a Parquet MAP column is silently read as the struct of the Iceberg schema instead of a type mismatch error

3 participants