Skip to content

GH-43115: [C++][Python] Preserve JSON explicit schema nullability - #55718

Open
lll-hhh wants to merge 1 commit into
apache:mainfrom
lll-hhh:fix/json-schema-nullability-43115
Open

lll-hhh wants to merge 1 commit into
apache:mainfrom
lll-hhh:fix/json-schema-nullability-43115

Conversation

@lll-hhh

@lll-hhh lll-hhh commented Nov 22, 2026

Copy link
Copy Markdown

Rationale for this change

Fixes #43115.

ChunkedStructArrayBuilder reconstructed output fields from only their names and converted child types. That reset every explicit field's nullability to the default (nullable=true), including fields nested inside structs. The resulting Arrow table no longer matched the schema supplied through ParseOptions::explicit_schema, which can fail downstream validation when the table is written.

What changes are included in this PR?

  • Carry each declared child field's nullability into ChunkedStructArrayBuilder instead of discarding it.
  • Apply the retained nullability when constructing the output struct type.
  • Use the inferred field's nullability when an unexpected field is promoted, preserving the existing inference path.
  • Add a regression covering both required and optional top-level fields and required and optional fields in a nested struct.

Are these changes tested?

Yes, against an editable Arrow C++ 27.0.0/SNAPSHOT and PyArrow build in WSL.

  • The new regression fails on the unmodified base and passes with the change in both serial and parallel readers: 2 passed.
  • python -m pytest pyarrow/tests/test_json.py -q: 84 passed, 2 skipped.
  • Arrow C++ shared build and install completed successfully.
  • clang-format==18.1.8 --dry-run --Werror, flake8 with python/setup.cfg, and autopep8 --diff passed on the modified files.

Are there any user-facing changes?

Yes. JSON tables created with an explicit schema now retain the declared nullability of top-level and nested struct fields instead of silently replacing it with nullable=true. Data and types are otherwise unchanged.

Was AI used for this PR?

In accordance to the AI generation guidelines, AI was used for implementation, tests, and description. The behavior was reproduced against the unmodified base, reviewed, and validated against a local Arrow build before submission.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI balanced review requested due to automatic review settings November 22, 2026 09:56

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

[c++] arrow::json::TableReader::Make ignores nullable=False in explicit_schema parse_options

2 participants