Skip to content

Read a Parquet LIST or MAP used as a MAP key as Array or Map - #130080

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/parquet-list-map-as-map-key
Nov 8, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/parquet-list-map-as-map-key

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130000
Related: #130016

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 Parquet files in which the key of a MAP is a LIST or a MAP, for example a Spark-written Iceberg table with a map<array<float>, string> column. Such a key was read as a Tuple of its Parquet children, so schema inference returned Map(Tuple(list Array(Tuple(element Nullable(Float32)))), ...) and an explicit Map(Array(Float32), String) type, or any Iceberg table with such a column, failed with TYPE_MISMATCH. The key is now read as Array or Map. Closes #130000.

Description

On 26.10 (26.10.2.103) and 26.3 LTS, reading a Parquet MAP whose key is a LIST as Map(Array(Float32), String), or through an Iceberg table with a map<array<float>, ...> column, fails with Requested type of column m.key doesn't match parquet schema: parquet type is Tuple ... (TYPE_MISMATCH).

SchemaConverter gives the key of a map the context MapKey, but processSubtreeMap and processSubtreeArrayOuter accepted only None and ListElement, so a LIST or MAP group in the key position fell through to processSubtreeTuple and was read literally. Both now accept MapKey too. A LIST key requested as Tuple or JSON is still read as the tuple of its children, so the type that schema inference returned until now keeps working (a MAP key requested as Tuple already did). A MAP key requested as JSON now gives the map's JSON, as a MAP column does.

The new test covers seven map columns with a LIST or MAP key (LIST keys of two element types, a MAP, a list of lists, a list of maps, and a LIST key inside a map value and inside an array) through file(), plus an IcebergLocal table. All of them fail on master and pass with the fix, 50/50 with randomized settings. With the fix, the four Doris tables from #130016 give exactly the output in its 05720 reference.


Workflow [PR]
Sync PR [sync-upstream/pr/130080]

Version info

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

processSubtreeTuple gives the key of a map the context MapKey, but
processSubtreeMap and processSubtreeArrayOuter accepted only None and
ListElement. A LIST- or MAP-annotated key group therefore fell through to
processSubtreeTuple and was read literally (Tuple(list Array(Tuple(element
...)))), and an explicit Array/Map type, e.g. the one an Iceberg schema
supplies for map<array<float>, ...>, failed with TYPE_MISMATCH.

Both handlers now accept MapKey. A LIST key requested as Tuple or JSON is
still read as the tuple of its children, so the type schema inference
returned until now (possibly stored in table metadata) keeps reading; a MAP
key requested as Tuple already fell back the same way. A MAP key requested
as JSON now gets the map's JSON, like a MAP column in any other position.

Closes ClickHouse#130000

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: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings), plus my own cold review (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 The MapKey fallback in processSubtreeArrayOuter accepts any Tuple, so a Tuple whose names match nothing still reads defaults for a LIST key AGREE, noted, not changed Same output as master for that input (Map(Tuple(value String), String) gives {(''):'a'} on both) and the same shape as the existing processSubtreeMap fallback; a mismatched Tuple request is the class of #130020
2 💡 PR description miscounted the test's key shapes AGREE, fixed description edited

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-49:20261108-051600

@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. The issue's pyarrow file read with 'm Map(Array(Float32), String)' fails with Code: 53 TYPE_MISMATCH on every run (master, 26.10.2.103, 26.3.42.3); the new test fails on master every run.
b Root cause explained? The map key gets the context MapKey, but processSubtreeMap and processSubtreeArrayOuter accepted only None / ListElement, so a LIST / MAP key group fell through to processSubtreeTuple, was read literally, and an Array / Map type hint hit its TYPE_MISMATCH check.
c Fix matches root cause? Yes. Both handlers accept MapKey; no guard, no setting. A LIST key requested as Tuple / JSON keeps the literal reading so existing inferred types still read.
d Test intent preserved / new tests added? New SQL test: 7 key shapes + a control through file() (inferred and explicit types, subcolumns, Tuple and JSON requests) and an IcebergLocal table (array key, map key, struct under a list key).
e Both directions demonstrated? Fails on the master binary (Code: 53, 38 differing reference lines), passes with the fix, 50/50 randomized. Each half of the change has its own reddening lines (mutation arms: LIST check, MAP check, fallback, JSON part of the fallback).
f Fix is general across code paths? Both annotation handlers that rejected the key context are fixed. Deeper positions already got None / ListElement, processSubtreeArrayInner runs only below the outer handler, and the Array(Tuple) request of a map already gave the key None. ORC copies of the same tables already read correctly.
g Fix generalizes across inputs (params/datatypes/wrappers)? LIST of Nullable floats and ints (empty list, NULL element), MAP, list of lists, list of maps, a LIST key inside a map value and an array, struct elements under a LIST key; non-Nullable and Nullable element hints; Tuple and JSON hints.
h Backward compatible? (maintainer-approved exception only) Schema inference changes to the issue's expected type. The previously inferred literal types still read. The only changed explicit-type output is a MAP key requested as JSON, which now gives the map's JSON like a MAP column. No setting.
i Invariants and contracts preserved? A Map key is never top-level Nullable (elements inside the Array may be, which DataTypeMap accepts); column assembly and field-id name mapping are unchanged (Array(Tuple(...)) control and the Iceberg arm).

Session id: cron:clickhouse-impl-slot-6:20261108-041600

@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? processSubtreeMap and processSubtreeArrayOuter rejected the MapKey schema context, so a Parquet LIST or MAP group used as a map key fell through to the literal Tuple reading; both now accept it, and a LIST key requested as Tuple or JSON keeps the old literal reading.

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ba18d66]

Summary: ✅


AI Review

Summary

Reviewed #130080 at ba18d669caba2ecdfc8e1c4d1165033ef1bf74c4, including all prior discussion. The change makes Parquet LIST and MAP groups used as map keys produce Array and Map, fixing schema inference and explicit-type reads described in #130000. No actionable blockers or majors found. The focused stateless test covers nested and empty keys, nullable elements, explicit types, subcolumns, legacy tuple requests, JSON, and IcebergLocal reads.

Consumers traced for the changed key representation: NativeParquetSchemaReader::readSchema propagates inferred types; Reader::formOutputColumn recursively assembles arrays and maps with their existing repetition levels; DataTypeMap accepts non-nullable composite keys; and IcebergSchemaProcessor::getComplexTypeFromObject supplies matching composite type hints. Legacy tuple hints retain the literal-schema path.

Missing context / blind spots
Final Verdict

Status: ✅ 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-parquet-reader-v3 Issues related to the native Parquet reader. labels Nov 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ba18d669c 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, 17 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.

Very good.

@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 af71c9e Nov 8, 2026
373 of 375 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 8, 2026
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-parquet-reader-v3 Issues related to the native Parquet reader. 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.

Parquet: a LIST used as a MAP key is read as Tuple(list Array(Tuple(element ...))) instead of Array

3 participants