Skip to content

Fix reading a subcolumn of a struct inside an array from Iceberg tables with Parquet data files - #132229

Open
groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-parquet-list-element-subcolumn
Open

groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-parquet-list-element-subcolumn

Conversation

@groeneai

@groeneai groeneai commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130023
Related: #128775
Related: #130173
Related: #130101

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 subcolumn of a struct inside an array (for example profile.hobbies.name or friends.nickname) from Iceberg tables with Parquet data files, which returned empty arrays. Closes #130023.

Description

On 26.10.4.207, SELECT profile.hobbies.name FROM icebergLocal(...) over the Parquet copy of the issue's Doris table returns [] instead of ['Reading','Swimming','Cooking']; the ORC copy and arrayMap(x -> x.name, profile.hobbies) are correct.

Since #102362, SchemaConverter::processSubtreeArrayInner replaced the name of a list element with its column mapper name (l.element). That name is also the one looked up among the requested columns, where array levels are transparent (l.x), so a requested subcolumn under a list was never found and was filled as a missing column. The element now keeps its name, and the mapper path is carried separately in TraversalNode::column_mapper_path (and in TupleInArray), which is what the useColumnMapperIfNeeded call sites use. A member added to a list after the file was written, read alone, now also keeps the list sizes.

Same approach as #128775 by @ josephperez3. My #130173 has the same split as part of the name mapping work; whichever of the two merges second drops it. The initial-default lookups of #130101 under a list now use the mapper path too, and a member added with one, read alone as l.y (or a subcolumn of it), resolves to the field l.element.y to take it instead of NULL.

Validation: the new test 05814 (list in a struct, nested lists, struct in a struct in a list, a member in WHERE and one read after a PREWHERE), two queries added to 03548 and six to 05568 fail on master and pass with the fix; ORC and Parquet copies of the Doris tables from #130016 return the same rows; 538 of the 616 Iceberg and Parquet stateless tests pass with the fix, the others need S3 or fail on master too.

🤖 Generated with Claude Code


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

…uet files

Since ClickHouse#102362 `processSubtreeArrayInner` replaced the name of a list element
with its ColumnMapper name (`l.element`). `TraversalNode::name` has two roles:
the parent path that `useColumnMapperIfNeeded` strips from the mapped names of
the children (needs `l.element`), and the name looked up among the requested
columns, where array levels are transparent (`l.x`). The override fixed the
first role and broke the second, so `l.x` or `profile.hobbies.name` was never
matched and was filled as a missing column: empty arrays for every row of an
Iceberg table with Parquet data files carrying field ids.

Keep `name` reader-side and carry the mapper path in a separate
`column_mapper_path` (unset means equal to `name`), extended by
`appendNameComponent` together with `name`. All `useColumnMapperIfNeeded` call
sites use it, and `TupleInArray` records it, so `addMissingElementOfTupleInArray`
resolves the children of the tuple by mapper path while it matches the
requested name by reader name: a member added to a list after the file was
written, read alone, gets the list sizes. At every node the mapper path equals
the old `name`, so every mapper-derived result is unchanged.

Same approach as ClickHouse#128775. The `initial-default` lookup of such a member from
ClickHouse#130101 is not here: it needs code that exists only in ClickHouse#130101.

Closes ClickHouse#130023

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds; final round: 0 findings)
Finding Verdict
⚠️ 05814: the optimize_move_to_prewhere variants never used PREWHERE (an IcebergLocal table does not support subcolumns in PREWHERE), so the PREWHERE claim was unproven AGREE, fixed: an explicit PREWHERE id = 1 query now reads the list members after the filter
💡 The mapper path of TupleInArray is not reached by a test DISAGREE: it only matters for a requested path through an existing primitive member (x.old.foo); a request that names an existing member is matched before that code runs
💡 Textually independent of #130101, but its initial-default lookup for list members keys on the old name noted: whichever of the two merges second adapts it; #130101's test catches it

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @grantholly-clickhouse, could you review this? The Parquet SchemaConverter used the Iceberg column mapper name of a list element (l.element) as the requested-column name, so a subcolumn under a list such as profile.hobbies.name was never matched and read as empty arrays; the element now keeps its reader name and the mapper path is carried separately.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: SELECT profile.hobbies.name FROM icebergLocal('be/complex_user_profiles_iceberg_parquet') WHERE id = 1 on the Doris fixture prints [] on master and on 26.10.4.207, every run; the ORC copy prints ['Reading','Swimming','Cooking'].
b Root cause explained? processSubtreeArrayInner overwrote the list element's name with its column mapper name (l.element), so the requested l.x was never matched in the header and was filled as a missing column.
c Fix matches root cause? Yes: name stays the reader name, the mapper path is kept in column_mapper_path and used by every useColumnMapperIfNeeded call; no guard, no setting.
d Test intent preserved / new tests added? New 05814 (list in a struct, nested lists, struct in a struct in a list, a member in WHERE and one read after a PREWHERE, member together with the whole list); 03548 gains two queries (renamed and added list member read alone). Existing lines unchanged.
e Both directions demonstrated? Both tests fail on the master snapshot and with only the processSubtreeArrayInner hunk reverted, and pass with the fix; 50 randomized runs each: 100/100 OK.
f Fix is general across code paths? All four useColumnMapperIfNeeded call sites (tuple children, map key/value probe, path component, missing member of a tuple in a list) use the mapper path. ORC and Avro readers were already correct.
g Fix generalizes across inputs (params/datatypes/wrappers)? Nullable and required members, nested lists, maps holding lists and lists holding maps (equal to file() on the same data file), a member added after the file was written (list sizes kept).
h Backward compatible? (maintainer-approved exception only) Yes: no setting or format change; output changes only from [] to the stored values.
i Invariants and contracts preserved? At every node getColumnMapperPath() equals the old name, so every mapper-derived name is unchanged; name is now only the requested-column name. 488 Iceberg and Parquet stateless tests: no failure that master does not have.

Session id: cron:clickhouse-impl-slot-7:20261117-030500

@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ab46c11]

Summary: ✅


AI Review

Summary

PR #132229 separates requested subcolumn names from Iceberg field paths when reading Parquet arrays. It preserves array offsets and applies initial-default values to absent list members and their subcolumns. No actionable findings in head ab46c11c56609b17bf94b5098552dc653fe1a9dd.

Missing context / blind spots
  • ⚠️ Current-head stateless tests and functional bugfix validation are still pending in the CI report. Regression coverage is present in 03548, 05568, and 05814; execution results for this head remain to be confirmed. No local tests were run because this review job has no ClickHouse binary.
Final Verdict

Status: ✅ Approve

@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 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6ae1369

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) / 05629_explain_analyze_join_side_q_error flaky, not from this PR (the diff touches only the Parquet SchemaConverter and two Iceberg tests): the second line of the result reads 1 0 instead of 1 1 under the randomized MergeTree settings index_granularity 983, min_bytes_for_wide_part 0 (the runner's diagnosis: 184 of 184 re-runs fail with the same settings, 206 of 206 pass without them). It failed the same way on 2 other PRs in the last 30 days #132149 (mine, open)
Build profile diff infra, not from this PR (no ci/ file in the diff): all 8 readiness probes to the CI logs cluster hit Read timed out. (read timeout=3), so has_pr_data raised LogClusterNotReady: the endpoint never became ready. The same job errored on 49 PRs in the last 24 hours #129675 (mine, open)
Mergeable Check praktika rollup of the 05629 row #132149 (mine, open)
PR praktika rollup of the rows above #132149 (mine, open), #129675 (mine, open)

The other CIDB FAIL rows on this head are Config Workflow / Pre Hooks and Finish Workflow / Post Hooks of the run before the can be tested label. All five Stateless tests (*, flaky check) jobs and the functional Bugfix validation jobs passed. CH Inc sync is green.

Session id: cron:our-pr-ci-monitor:20261117-080018

groeneai and others added 3 commits November 23, 2026 23:00
…rquet-list-element-subcolumn

The `initial-default` code of ClickHouse#130101 (merged 2026-11-18) relies on the list element node being named
with the column mapper path, which this PR changes: 05568_iceberg_initial_default fails on the merge
of this PR with master. The fix in the next commit uses that code, so it needs master.
…column mapper path

ClickHouse#130101 keyed the field ids of a struct, and looked up the default of a missing tuple element, by
`TraversalNode::name`, which master set to the column mapper path (`l.element`) inside a list. This
PR keeps `name` the ClickHouse name (`l`), so on the merge with master a field added with an
`initial-default` to the element struct of a list was read as NULL, or threw THERE_IS_NO_COLUMN
with `input_format_parquet_allow_missing_columns = 0` (05568_iceberg_initial_default). Both lookups
now use `getColumnMapperPath()`.

The subcolumn `l.y` of such a field, read without the rest of `l` (addMissingElementOfTupleInArray),
now takes the `initial-default` of `l.element.y` instead of NULL, keeping the sizes of `l`, also with
`input_format_parquet_allow_missing_columns = 0`, which now only rejects it when there is no default.
Requested on ClickHouse#130023 (issuecomment-6935263914). ORC already read these values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…om the field that has it

The subcolumn `l.a.v` of a list of structs `a` added to the elements of `l` was looked up as the
field `l.element.a.v`, which has no default (the default belongs to `l.element.a`), so it read as
empty arrays. `ColumnMapper::getIcebergFieldPath` now takes the struct its walk ends at, and the
Parquet reader resolves the field under the element struct of the list with it, the same way as
for a top-level column.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ab46c11c5 with master a7735deb4 (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

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

Job report

This branch has not been deployed

No deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg Parquet: subcolumn of an array of structs (profile.hobbies.name) reads as empty arrays

1 participant