Skip to content

GH-55682: [C++][Parquet] Fix non-nullable list inside null ancestor - #55704

Open
1fanwang wants to merge 4 commits into
apache:mainfrom
1fanwang:1fanwang/parquet-non-nullable-fixed-size-list-null-ancestor
Open

1fanwang wants to merge 4 commits into
apache:mainfrom
1fanwang:1fanwang/parquet-non-nullable-fixed-size-list-null-ancestor

Conversation

@1fanwang

Copy link
Copy Markdown
Contributor

Rationale for this change

A struct can be null while a fixed-size list field underneath it is declared non-nullable in the schema. In that case the list keeps no validity information of its own, so nothing records that the struct's null row left no physical values behind for it. Reading such a column back raises "Expected all lists to be of size=N but index M had size=0" even though the file is well-formed. This follows on from GH-35692, which fixed the same symptom for the case where the list field itself carries the null.

What changes are included in this PR?

The reader decided whether to pad a missing fixed-size list slot based on whether the list had its own null count, which is always zero for a non-nullable field regardless of what its ancestor did. The fix instead looks at the decoded element offsets directly: a null ancestor still leaves a zero-length span where a full list was expected, and that gap is now detected and padded the same way as a list that is null in its own right.

Are these changes tested?

Yes, with a new regression test reproducing the reported schema (a nullable struct holding a non-nullable fixed-size list field):

ninja parquet-arrow-reader-writer-test
./debug/parquet-arrow-reader-writer-test --gtest_filter=ArrowReadWrite.NonNullableFixedSizeListInsideNullableStruct

Before the fix, this fails with the exact reported error:

'_error_or_value34.status()' failed with Invalid: Expected all lists to be of size=2 but index 2 had size=0

After the fix it passes, and the roundtripped table decodes the null struct row's fixed-size list as nulls instead of erroring:

x:
  [
    -- is_valid:
      [true, false, true]
    -- child 0 type: fixed_size_list<element: int32>[2]
      [[1, 2], [null, null], [3, 4]]
  ]

Are there any user-facing changes?

No API changes; this fixes a read failure on previously-unreadable but well-formed files.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The change silently converts present empty lists into null-filled fixed-size lists instead of rejecting size mismatches, while also adding unnecessary child-buffer allocations and copies to ordinary reads.

2 open issues
What changed in this PR

Addresses GH-55682 in the C++ Parquet reader by padding missing fixed-size-list child values beneath a null ancestor, without changing public APIs.

Changes:

  • Extends run-based child reconstruction to detect missing list slots from decoded offsets.
  • Adds a round-trip regression test for a non-nullable fixed-size list inside a nullable struct.
File Description
cpp/​src/​parquet/​arrow/​reader.cc Adds offset-based gap detection and reuses child-padding logic.
cpp/​src/​parquet/​arrow/​arrow_reader_writer_test.cc Adds coverage for fixed-size lists beneath null struct rows.

Review effort: Balanced

Comment thread cpp/src/parquet/arrow/reader.cc Resolved
Comment thread cpp/src/parquet/arrow/reader.cc Resolved
Copilot AI balanced review requested due to automatic review settings November 21, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The nullable-field guard silently pads present empty required lists with nulls instead of rejecting size mismatches, without distinguishing them from absent ancestors.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread cpp/src/parquet/arrow/reader.cc Resolved
Copilot AI balanced review requested due to automatic review settings November 21, 2026 11:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The definition-level guard can silently accept invalid nested fixed-size lists, converting a present empty size-2 list into [null, null] instead of rejecting the size mismatch.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Reject empty required lists beneath present optional structs

cpp/​src/​parquet/​arrow/​reader.cc:819

For a REQUIRED size-2 list beneath an OPTIONAL struct that is present, [1, 2], [], [3, 4] produces offsets [0, 2, 2, 4] and passes def_level > rep_level. This code silently turns the visible empty list into [null, null] instead of rejecting the size mismatch; an optional outer list can also satisfy the guard without supplying a missing inner slot. Use each slot's definition level, accounting for the closest repeated ancestor, to distinguish absent ancestors from present empty lists, and add rejection regressions for these nested schemas.

1 resolved since last review

Review effort: Balanced

…stor

The reader only padded a null fixed-size list slot when the list's own
null count was nonzero, but a non-nullable list never has a validity
bitmap. A null struct ancestor leaves no child values written for that
row, and nothing recorded the gap. Detect it from the offsets directly:
a zero-length span where list_size was expected is padded the same way
an own-null run already is.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
A batch paid for a rebuild even with no gaps. A nullable field with
zero nulls could pad a physically empty list instead of rejecting it,
since its validity buffer is discarded whenever null count is zero,
regardless of nullability.

Branch on field()->nullable() instead: scan offsets for gaps only
when non-nullable, since zero nulls on a nullable field already means
no gap exists.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
A non-nullable field has no validity buffer regardless of ancestor
nullability, so the gap scan could not tell a null struct ancestor
from a corrupt present-but-empty list under a bare REQUIRED list.

Every repeated step raises def_level and rep_level equally, so
def_level > rep_level means an ancestor is optional. Scan for gaps
only then; otherwise reject any gap as corrupt.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
An absent ancestor and a corruptly empty required list under a
present struct collapse to the same zero-length offset span, and a
non-nullable field has no validity buffer to tell them apart.

BuildArray always computes the per-slot bitmap from definition
levels, which does distinguish them, clearing it for a non-nullable
result. Added a required-list-under-present-struct regression.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang force-pushed the 1fanwang/parquet-non-nullable-fixed-size-list-null-ancestor branch from 19fe7cb to d8efe8b Compare November 21, 2026 16:31
Copilot AI balanced review requested due to automatic review settings November 21, 2026 16:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the fixed-size-list read fix.

No open issues 🎉

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants