Skip to content

GH-51639: [C++][Python] Fix invalid result when casting struct with null-typed child to its own type - #51646

Open
kartik00052 wants to merge 1 commit into
apache:mainfrom
kartik00052:GH-51639-fix-struct-null-child-cast
Open

kartik00052 wants to merge 1 commit into
apache:mainfrom
kartik00052:GH-51639-fix-struct-null-child-cast

Conversation

@kartik00052

@kartik00052 kartik00052 commented Sep 29, 2026 •

Copy link
Copy Markdown

Rationale for this change

Casting a struct containing a null-typed field to its own type could produce an invalid array when the struct child length differed from the enclosing execution batch length, such as a list containing multiple structs in one row or a sliced struct array. The null child was created using the parent execution length instead of the input child span length.

What changes are included in this PR?

  • Use the input ArraySpan length when creating null-filled cast results.
  • Add C++ regression coverage for sliced structs and nested list/struct cases.
  • Add PyArrow coverage for array, chunked array, compute, record batch, and Parquet casts.

Are these changes tested?

  • C++ scalar cast regression tests added.
  • PyArrow compute and Parquet regression tests added.
  • Python syntax, C++ diagnostics, and git diff whitespace checks pass.
  • Native C++ and PyArrow test execution is pending a compiler-enabled build environment; the current environment has no C/C++ compiler and no built local pyarrow extension.

Are there any user-facing changes?

Yes. Struct casts involving null-typed children now produce valid arrays instead of silently returning invalid arrays or raising during validation.

Critical Fix

This fixes incorrect or invalid data structures produced by a cast operation.

Was AI used for this PR?

  • Human
  • AI

The implementation and test changes were reviewed against the existing Arrow cast kernels, nested-array length handling, and repository conventions.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #51639 has been automatically assigned in GitHub to PR creator.

@kartik00052 kartik00052 changed the title GH-51639: [C++] Fix invalid result when casting struct with null-typed child to its own type GH-51639: [C++][Python] Fix invalid result when casting struct with null-typed child to its own type Sep 29, 2026
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.

1 participant