GH-50944: [C++] Replace RapidJSON with simdjson in JSON chunker - #50945
GH-50944: [C++] Replace RapidJSON with simdjson in JSON chunker#50945Reranko05 wants to merge 23 commits into
Conversation
e9fc9fe to
be4c2a1
Compare
pitrou
left a comment
There was a problem hiding this comment.
I don't understand why this is parsing JSON by hand?
It seems that we might be able to use simdjson::ondemand::parser::iterate_many.
I initially tried using That said, I agree that parsing JSON manually here is not ideal. I'll revisit this using |
|
@pitrou I tried using Manual structural parsing approach preserved the existing test behavior. @rok, since your earlier implementation was helpful here, do you have any suggestions on how to preserve the current error behavior with |
As long as an error is reported while reading the JSON stream, I don't think we care if it's reported by the chunker or the parser. |
|
@pitrou I gave |
Hmm, I see. Thanks for trying anyway :-)
Well, as a last resort, yes. The problem:
|
|
Try to understand the issue. Is it that json strings legal for rapidjson may fail on simdjson, makes future Arrow release potentially incompatible to old version? Writing our own optimized version looks not ideal. Can we just use simdjson? It's state-of-the-art, and even with self written object delimiter, there's still incompatibility risk I'm afraid. |
|
@cyb70289 I don't think the issue is JSON compatibility between RapidJSON and simdjson. The main issue I ran into is the boundary/streaming semantics. The previous RapidJSON implementation uses With I agree that writing our own optimized JSON parser would not be ideal. The manual approach I used, and which @rok also implemented in rok#47, only scans for the boundary of the first complete object or array while respecting strings and escapes, and then lets simdjson perform the actual JSON validation. But I agree this still introduces complexity and needs careful testing. If there is a way to use simdjson directly while preserving the old stop-after-one-value semantics, that would definitely be preferable. |
Is that a problem? We want to keep compatibility when parsing valid JSON streams. The failure mode for an invalid JSON stream can change. |
|
A discussion about ignoring trailing garbage in simdjson. Looks there're real use cases lenient parsing can be useful. |
|
Trailing garbage is not the problem here. We are parsing a stream of valid JSON documents. We are happy to error out on trailing garbage. |
6923f56 to
008f53c
Compare
008f53c to
1f75592
Compare
1f75592 to
8b364d1
Compare
|
I've made enough changes that it may benefit from another person's review. @HuaHuaY Do you want to take a look? |
|
@github-actions crossbow submit -g cpp |
|
Revision: 386900c Submitted crossbow builds: ursacomputing/crossbow @ actions-810cb09b40 |
|
(CI failures are unrelated) |
|
Thanks, @pitrou. Appreciate the additional changes and review. |
Rationale for this change
This PR continues the simdjson migration by replacing the RapidJSON-based JSON boundary detection used by the JSON chunker.
The existing implementation uses RapidJSON's streaming parser to identify complete JSON values. This change replaces that logic with the simdjson streaming parser.
Are these changes tested?
Yes, by existing tests.
Are there any user-facing changes?
No, except perhaps slight differences in error message and timing of error reporting when reading from an invalid JSON stream (i.e. there may be cases where a JSON parse error is reported earlier or later while iterating over RecordBatches).