Skip to content

GH-47417: [C++] Fix JSON parser losing nulls in a null-typed list - #51108

Open
advitrocks9 wants to merge 5 commits into
apache:mainfrom
advitrocks9:fix-gh-47417
Open

advitrocks9 wants to merge 5 commits into
apache:mainfrom
advitrocks9:fix-gh-47417

Conversation

@advitrocks9

@advitrocks9 advitrocks9 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

{"a": [null, 1]} silently parses to [[1]] in release builds, and aborts in debug.

This was introduced in b7054c21aab (0.14.0).

What changes are included in this PR?

AppendNull looks up its child from the parent and returns the updated BuilderPtr, instead of taking a copy from the caller. Null() writes it back to builder_, so builder_ no longer drifts from the parent's copy.

Are these changes tested?

Two new tests, BlockParser.NullsInList (inferred schema) and BlockParserWithSchema.NullsInList (explicit schema), parse lists of nulls, including {"a": [{"b": null}, null]}. Both fail in debug without the fix.

Are there any user-facing changes?

{"a": [null, 1]} now parses to [[null, 1]].

This PR contains a "Critical Fix". Well-formed JSON silently loses list elements.

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

@advitrocks9
advitrocks9 requested a review from pitrou as a code owner August 31, 2026 18:32
Copilot AI lite review requested due to automatic review settings August 31, 2026 18:32
@github-actions

Copy link
Copy Markdown

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

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.

Pull request overview

Fixes a long-standing JSON parsing bug in the C++ BlockParser where null elements could be silently dropped (or trigger DCHECKs in debug) when appending nulls to a null-typed list, by ensuring the inline null-count state in BuilderPtr is updated in-place.

Changes:

  • Change RawBuilderSet::AppendNull to take a BuilderPtr* so increments to the inline null-count for Kind::kNull persist to the caller.
  • Update all AppendNull call sites to pass builder pointers accordingly (including nested object-field null propagation).
  • Add a regression test covering nulls inside lists (null-only and promoted-from-null cases).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cpp/src/arrow/json/parser.cc Fixes null appends by mutating the BuilderPtr in-place, preventing lost null counts in null-typed list builders.
cpp/src/arrow/json/parser_test.cc Adds a regression test to ensure nulls inside lists are preserved and don’t break list offsets.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cpp/src/arrow/json/parser_test.cc
Copilot AI review requested due to automatic review settings September 3, 2026 05:50
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

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

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

The fix is narrowly scoped, updates all relevant call sites, and adds targeted regression tests exercising both the all-null and promotion scenarios described.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Sep 3, 2026
@advitrocks9

Copy link
Copy Markdown
Contributor Author

@pitrou mind taking a look? the current red CI is from an existing known repowide issue

# Conflicts:
#	cpp/src/arrow/json/parser.cc
#	cpp/src/arrow/json/parser_test.cc
Copilot AI lite review requested due to automatic review settings October 8, 2026 19:32

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

The focused fix addresses the reported state-loss bug and has regression coverage for both parsing paths.

1 open finding

🧠 Review effort: Lite

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

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

@advitrocks9

Copy link
Copy Markdown
Contributor Author

Merged main to fix the conflict with the simdjson rewrite. The fix itself is unchanged.

@pitrou

pitrou commented Oct 21, 2026

Copy link
Copy Markdown
Member

@Reranko05 @taepper Since you both recently worked on the JSON reader, would you like to review this?

@taepper

taepper commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@advitrocks9 Thank you for the contribution! Would you mind filling out the AI disclosure section of the PR template?

### Was AI used for this PR?

In accordance to the [AI generation guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code), 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

@Reranko05 Reranko05 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to also test a null struct with a null-typed child, like {"a": [{"b": null}, null]}? Existing tests don't cover the kNull case inside the recursive kObject branch of AppendNull.

Comment thread cpp/src/arrow/json/parser.cc Outdated
Copilot AI lite review requested due to automatic review settings October 22, 2026 01:33

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 unresolved blocking issues were identified, and all supplied assessments indicate approval readiness.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@github-actions

Copy link
Copy Markdown

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

@advitrocks9

Copy link
Copy Markdown
Contributor Author

@taepper @Reranko05 thanks for the review! I've gone ahead and addressed your concerns, and updated the PR body (:

Comment thread cpp/src/arrow/json/parser.cc Outdated
Comment on lines 971 to 974
@@ -966,7 +972,7 @@ class ParseImpl : public BlockParser {
if (ARROW_PREDICT_FALSE(!field_builder.nullable)) {
return ParseError("a required field was absent");
}

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.

We could use

if (ARROW_PREDICT_FALSE(!Cast<Kind::kObject>(parent)->field_builder(i).nullable)) {
  return ParseError("a required field was absent");
}

to avoid the variable field_builder

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!

Comment on lines +676 to +678
ARROW_ASSIGN_OR_RAISE(builder_,
builder_set_.AppendNull(builder_stack_.back(), field_index_));
return Status::OK();

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.

I like this a lot! :)

Copilot AI lite review requested due to automatic review settings October 24, 2026 13:58

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

The reviewed changes address the null-list parsing defect and include comprehensive regression coverage with no unresolved review issues.

No open issues 🎉

Review effort: Lite

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants