Skip to content

Fix empty arrays for missing elements of a Parquet list of structs - #131125

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:parquet-levels-only-array-sizes
Nov 13, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:parquet-levels-only-array-sizes

Conversation

@groeneai

@groeneai groeneai commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #130259
Related: #130279

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 list of structs with an explicit structure or a data lake schema that requests only elements the file does not have: l.d and l Array(Tuple(d ...)) returned empty arrays, so ARRAY JOIN and length saw no elements, instead of arrays of default values with the sizes of the list in the file.

Description

On 26.10.2.103 (also 26.8.21.12 and 26.3.33.24), SELECT l.d FROM file('f.parquet', Parquet, 'l Array(Tuple(a Nullable(Int32), d Nullable(Int32)))') over a file whose l has no d returns [] instead of [NULL], and ARRAY JOIN l.d returns no rows. l Array(Tuple(d Nullable(Int32))) returns [] for every row. The same happens to an Iceberg list read under a schema in which none of its element's fields are in the file.

Parquet stores the array sizes only in the leaf column chunks, and the reader reads a leaf only if a requested element maps to it. When no requested element is in the file, no leaf under the list is read, so the arrays come out empty.

Now one leaf under such a list is read only for its levels: the cheapest one (preferring fixed width, then no arrays of its own, then not already read for another column), decoded by its physical type and then dropped, so no value can be rejected. The requested elements are filled with defaults inside the arrays, and a DEFAULT expression of a missing l.d still applies. The candidate leaves are recorded during the existing schema traversal.

This changes what 03548_parquet_missing_tuple_elements pinned ([]): the new results are what the whole-column read, the Arrow reader and the ORC reader (#130279) return. The test is extended with nested lists, tuples in elements, dotted subcolumns with ARRAY JOIN, WHERE and PREWHERE, and NULL leaf values. Out-of-range leaf values, Iceberg and the columns cache are in the new 03548_parquet_missing_tuple_elements_pyarrow_iceberg, which needs pyarrow and so skips the fast test. Both fail on master in the changed lines and pass with the change.

This part is split out of #130259, so that that PR only unifies the readers.


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

Version info

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

groeneai and others added 2 commits November 11, 2026 17:02
… field in the file

The Parquet v3 reader returned empty arrays for a list of structs when none
of the requested elements under the list are in the file, e.g. the structure
`l Array(Tuple(a Nullable(Int32), d Nullable(Int32)))` over a file without
`d` gave `l.d` = [] instead of [NULL], and `ARRAY JOIN l.d` gave no rows.
Repetition and definition levels are stored only in the leaf column chunks,
and no leaf under such an array was read.

Read one leaf under such an array only for its levels: its values are decoded
as stored, without the logical type, and then dropped, and the existing
per-element missing fill runs inside the array. This covers both a whole
tuple whose requested elements are all missing, and a requested `arr.missing`
subcolumn that matches no schema element.

This is the carrier reviewed on ClickHouse#130259, split out of it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lready computed

processSubtreePrimitive records every leaf under an array with its levels,
so the leaves of a subtree are a contiguous range, and addLevelsOnlyPrimitive
picks from that range instead of walking the subtree again. It keeps the
cheapest leaf whose physical type it can decode in a single pass, with the
same cost order and the same leaf as before, without throwing and catching
per leaf. A requested `arr.missing` column is handled inside the existing
loop over the missing columns of prepareForReading, so the found columns
are not computed twice.

The test reads a NULL in a Nullable leaf of a file written by ClickHouse
instead of a GEOMETRY leaf written by pyarrow: the leaf is decoded by its
physical type, so both are the same case.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding).

# Sev Finding Verdict Evidence / action
1 ❌ Array(Nullable(Tuple(z String))) over a list of nullable structs without z still raises TYPE_MISMATCH DISAGREE Master raises the same error, from the physically nullable Tuple guard in processSubtreeTuple, which has no array condition: t Nullable(Tuple(z String)) outside a list fails the same way. Reading a leaf for its null map in that path is a separate change; this PR fixes the empty arrays only.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261112-200800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local over a file written by INSERT INTO FUNCTION file(...) SELECT [(toInt32(number), 'c')]::Array(Tuple(a Int32, c String)) AS l, read with l Array(Tuple(a Nullable(Int32), c Nullable(String), d Nullable(Int32))): l.d is [] and ARRAY JOIN l.d gives 0 rows on every run of master.
b Root cause explained? Parquet keeps array sizes only in leaf column chunks, and the reader reads a leaf only when a requested element maps to it. With no requested element in the file, nothing under the list is read and its arrays come out empty.
c Fix matches root cause? Yes. One leaf under such a list is read for its levels only (decoded by its physical type, values dropped), and the missing elements are filled inside the arrays. No guard, no setting.
d Test intent preserved / new tests added? 03548_parquet_missing_tuple_elements is extended; the only removed expectation is the [] the bug produced. Dropping the record of leaves, the REPEATED hook, the arr.missing handling, the cost order or the Nullable leaf output each makes it fail.
e Both directions demonstrated? Yes. Master fails 03548 in the changed lines and the repro gives [] / 0 rows; with the change 03548 passes (also 50/50 runs) and the repro gives [NULL] / 3 rows.
f Fix is general across code paths? Every repeated node (3-level and 2-level lists, plain repeated groups, map key_value) goes through the same hook, as do dotted requests inside arrays and nested lists; a requested arr.missing is handled in the missing-column loop. ORC got the same rule in #130279; Arrow already keeps the sizes.
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked over every physical type and encoding (38 files, incl. INT96 and DATE values out of the ClickHouse range), Nullable, LowCardinality, String and array leaves, Map inside the element, nested lists, empty and NULL lists, case-insensitive matching and DEFAULT expressions.
h Backward compatible? (maintainer-approved exception only) No setting or format change. The sizes now come from the file instead of [], matching the whole-column read and the Arrow and ORC readers; input_format_parquet_allow_missing_columns = 0 still throws THERE_IS_NO_COLUMN.
i Invariants and contracts preserved? An array output gets a leaf in its primitive range; that leaf's values are dropped after decoding, every primitive gets its output position, the columns cache hashes the new field and never caches a column reported as missing, and filters and page indexes still use only real primitive outputs. Schema inference is unchanged.

Session id: cron:clickhouse-impl-slot-40:20261111-165500

@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4ae85f6]

Summary: ✅


AI Review

Summary

Preserves Parquet list sizes when all requested struct fields are missing by reading a physical leaf for its repetition and definition levels, then filling the requested fields with defaults. Reviewed head 4ae85f6f6b9eb318c02322feafa10bc16fb66b9a and all prior discussion. No actionable findings. The fast test passes; 24 additional local checks across 12 physical encodings passed, including null lists, empty lists, and null elements. Additional nested-array and map projections behaved correctly on supported paths.

Missing context / blind spots
  • ⚠️ The Iceberg schema-evolution and columns-cache regression cases were inspected but not independently executed: the available fast-test binary omits IcebergLocal. The author reports successful full-build runs; running 03548_parquet_missing_tuple_elements_pyarrow_iceberg in the full stateless suite would independently confirm those paths.
Final Verdict

✅ Approve. No new inline findings.

@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 12, 2026
…e fast test

ClickHouse#126477 builds Parquet in the fast test and removed `no-fasttest` from 03548, so the cases this PR
added to it ran there and failed: the fast test has neither pyarrow nor the IcebergLocal engine.
They now live in 03548_parquet_missing_tuple_elements_pyarrow_iceberg, tagged `no-fasttest`; the
cases that only use files written by ClickHouse stay in 03548 and keep running in the fast test.
The moved cases and their expected output are unchanged.

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

clickhouse-gh Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4ae85f6f6 with master e4c0f8c75 (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.

Object file sizes

8 object files changed (+36.90 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Parquet/SchemaConverter.cpp.o 590.56 KiB 624.09 KiB +33.53 KiB (+5.68%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.64, programs/clickhouse-keeper ×0.73 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 6.4 s 14.0 s +9.9 s (+243%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.6 s 7.5 s +5.2 s (+226%)
Compile time of recompiled translation units

16 translation units recompiled, 157 s compile time in total, 16 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.

Looks good.

@alexey-milovidov alexey-milovidov self-assigned this Nov 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit d120e7c Nov 13, 2026
204 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 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.

3 participants