You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GH-51037: [C++] Replace RapidJSON with simdjson in JSON parser - #51038
This PR continues the simdjson migration by replacing the RapidJSON-based parsing implementation used by the JSON parser.
The existing parser uses RapidJSON's SAX/handler interface to parse JSON values and populate Arrow builders. This change replaces that implementation with simdjson's ondemand API while retaining the existing builder and type-inference logic.
Changes
Replace the RapidJSON parser and handler interface with simdjson's ondemand API.
Parse JSON documents using simdjson::ondemand::parser::iterate_many.
Use ResolveSimdjsonResult() consistently when handling simdjson results.
Preserve support for nested objects and arrays.
Preserve explicit-schema and inferred-field behavior.
Preserve unexpected-field handling for Error, Ignore, and InferType.
Continue storing numeric values as raw JSON tokens.
Trim trailing whitespace from numeric raw tokens to preserve existing behavior.
Preserve JSON parse error propagation through Status::Invalid.
Remove the parser's RapidJSON-specific dependencies.
Are there any user-facing changes?
No
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.
@pitrou@rok I’ve rebased the parser PR and incorporated the latest feedback, including reusing the simdjson::ondemand::parser and using padded_string_view when the Arrow Buffer has sufficient capacity.
The native C++ build and tests pass, but Crossbow’s ubuntu-cpp-emscripten job now fails in arrow-dataset-file-json-test:
RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
at abort (/build/cpp/debug/arrow-dataset-file-json-test.js:491:11)
at _abort (/build/cpp/debug/arrow-dataset-file-json-test.js:4483:7)
at invoke_v (/build/cpp/debug/arrow-dataset-file-json-test.js:5907:29)
at arrow-dataset-file-json-test.wasm.std::__terminate(void (*)()) (wasm://wasm/arrow-dataset-file-json-test.wasm-0f1ca1f2:wasm-function[41574]:0x277e6cb)
at arrow-dataset-file-json-test.wasm.std::terminate() (wasm://wasm/arrow-dataset-file-json-test.wasm-0f1ca1f2:wasm-function[41572]:0x277e6a4)
at arrow-dataset-file-json-test.wasm.simdjson::fallback::ondemand::document_stream::start() (wasm://wasm/arrow-dataset-file-json-test.wasm-0f1ca1f2:wasm-function[20092]:0x10168d0)
at arrow-dataset-file-json-test.wasm.arrow::Status arrow::Status arrow::json::HandlerBase::DoParse<arrow::json::Handler<(arrow::json::UnexpectedFieldBehavior)2>>(arrow::json::Handler<(arrow::json::UnexpectedFieldBehavior)2>&, std::__2::shared_ptr<arrow::Buffer> const&)::'lambda'(arrow::json::Handler<(arrow::json::UnexpectedFieldBehavior)2> const&)::operator()<simdjson::padded_string>(arrow::json::Handler<(arrow::json::UnexpectedFieldBehavior)2> const&) const (wasm://wasm/arrow-dataset-file-json-test.wasm-0f1ca1f2:wasm-function[20180]:0x1030c99)
at invoke_viii (/build/cpp/debug/arrow-dataset-file-json-test.js:5885:29)
at arrow-dataset-file-json-test.wasm.arrow::Status arrow::json::HandlerBase::DoParse<arrow::json::Handler<(arrow::json::UnexpectedFieldBehavior)2>>(arrow::json::Handler<(arrow::json::UnexpectedFieldBehavior)2>&, std::__2::shared_ptr<arrow::Buffer> const&) (wasm://wasm/arrow-dataset-file-json-test.wasm-0f1ca1f2:wasm-function[20178]:0x102f33c)
at arrow-dataset-file-json-test.wasm.arrow::json::Handler<(arrow::json::UnexpectedFieldBehavior)2>::Parse(std::__2::shared_ptr<arrow::Buffer> const&) (wasm://wasm/arrow-dataset-file-json-test.wasm-0f1ca1f2:wasm-function[20177]:0x102ef89)
Do you have any idea what I need to do to fix this?
get_number rejects raw numeric tokens previously preserved
cpp/src/arrow/json/parser.cc:870
Calling get_number() here is not compatible with the parser's raw-token contract. The old RapidJSON path used kParseNumbersAsStringsFlag (and kParseNanAndInfFlag), so it retained arbitrary integer text—including values outside 64-bit ranges—and non-finite tokens for later string/decimal/float conversion; simdjson reports BIGINT_ERROR for out-of-range integers and its typed numeric accessors reject some non-finite tokens. As a result, valid inputs that previously worked for string or decimal columns now fail before RawNumber can store them. Validate the token without narrowing it, or explicitly special-case these token classes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
This PR continues the simdjson migration by replacing the RapidJSON-based parsing implementation used by the JSON parser.
The existing parser uses RapidJSON's SAX/handler interface to parse JSON values and populate Arrow builders. This change replaces that implementation with simdjson's ondemand API while retaining the existing builder and type-inference logic.
Changes
simdjson::ondemand::parser::iterate_many.ResolveSimdjsonResult()consistently when handling simdjson results.Error,Ignore, andInferType.Status::Invalid.Are there any user-facing changes?
No
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:
Reviewed before submission by:
Fixes: #51037