Skip to content

GH-33055: [C++] Allow null JSON structs with non-nullable children - #55805

Open
aikhanjum wants to merge 1 commit into
apache:mainfrom
aikhanjum:fix-json-null-struct-children-on-main
Open

aikhanjum wants to merge 1 commit into
apache:mainfrom
aikhanjum:fix-json-null-struct-children-on-main

Conversation

@aikhanjum

@aikhanjum aikhanjum commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

The JSON reader rejects a missing or null nullable struct when that struct has non-nullable children. With an explicit schema where my_struct is nullable and its child some_information is a non-nullable int64, reading {} or {"my_struct": null} fails with "JSON parse error: a required field was null". Each of those rows should produce one null struct.

What changes are included in this PR?

A null struct still needs placeholder slots in its child arrays so later rows stay aligned. RawBuilderSet::AppendNull appends those slots recursively, but it also checked each hidden child slot against the child's nullability, as if it were a real JSON null.

This passes parent_is_null through that recursion so slots masked by a null parent can be appended. Calls for actual JSON values keep the required-field check, so {"my_struct": {}} and {"my_struct": {"some_information": null}} are still rejected. No public API changes.

Are these changes tested?

Yes. Two parser tests were added.

  • BlockParserWithSchema.NullableStructWithRequiredChildren reads null and missing nullable structs with required children, including a required nested struct with a required boolean child, then a populated row. It checks parent validity, the populated row's child values and full array validation.
  • BlockParserWithSchema.RequiredChildrenOfValidStruct checks that absent or null required children are still rejected after a null parent row, and that absent or null non-nullable parents are rejected.

On upstream main dd456e0, macOS arm64, Apple Clang 21, Debug minimal preset with tests, compute, JSON and CSV enabled.

  • Without the parser change, both new tests fail with the reported "a required field was null" error.
  • With the change, both pass, and the full arrow-json-test binary passes 248 tests from 60 test suites.
  • clang-format 18.1.8 on the changed lines, cpplint 1.6.1 on both files and git diff --check pass.

Not run here. Python bindings, Linux, Windows, sanitizers, the full Arrow suite and upstream CI. This is independent of the output-schema nullability work in GH-31957 and the open PR for GH-43115.

Are there any user-facing changes?

Yes. Valid JSON that was rejected now reads as null structs.

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

OpenAI Codex searched for overlapping work, investigated the parser, wrote the fix and regression tests and ran the first validation. Claude Code re-ran the validation on current main and updated this description.

🤖 Generated with Claude Code

A null or missing nullable struct still appends placeholder slots to its
child builders so later rows stay aligned. RawBuilderSet::AppendNull
checked those hidden slots against each child's nullability, so reading
{} or {"my_struct": null} failed with "a required field was null".

Pass parent_is_null through the recursion so slots masked by a null
parent skip that check. Real JSON nulls and absent values for required
fields are still rejected.

Generated-by: OpenAI Codex, Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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