Repository navigation
GH-55833: [C++] Return an error when a JSON field changes kind across blocks - #55840
RajaBabu15 wants to merge 3 commits into
Conversation
|
Notes from reading the code and related work, as context for this PR. The tests hold one rule: a read split into blocks gives the same result as the same rows in one block. For type inference that means merging types must not depend on block order or grouping, Inside one block One case goes further than the issue title. Numbers and strings reach the converters as the same array type, so on main ( How other readers merge two different types:
The same builders had earlier crash fixes around null and missing lists (ARROW-12065, ARROW-13871). A list or object after only nulls still fails, which is GH-20253. Update: the builders now check the JSON kind between blocks. The PR description lists what is and is not covered. |
4c723d5 to
5e6f122
Compare
Rationale for this change
The JSON reader parses each block separately, and the parser checks that a field keeps one JSON kind only within a block. When a field changes kind in a later block,
read_jsoncan crash, or return wrong values with no error. With default options this can happen on any file just over 1 MiB. A single-block read of the same data reportschanged from X to Y.What changes are included in this PR?
The parser already tags each field with the JSON kind it saw. The chunked builders now compare that tag between blocks and return
JSON parse error: Column mixes <kind> and <kind> values across blocks. With two kinds the message is the same whichever block is processed first. Promotion within one kind still works: int64 to double, timestamp to string. The list and struct builders and the number and string converters check the array type before casting it.Not changed here:
NotImplemented. That is [C++] An unstable crash may appears when reading table from a json file. #20253.Are these changes tested?
New tests in
reader_test.cccompare a read split into one row per block with a single-block read, with and without threads, at the top level and inside lists and objects, and check that valid input still reads.Are there any user-facing changes?
Input that used to crash now raises an error. A field that mixes numbers and strings across blocks used to read as string, int64 or double; it now raises an error, as a single-block read already did. Other valid files read as before.
This PR contains a "Critical Fix". It fixes a crash and incorrect data produced from JSON input.
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: