SohamDutta02 opened a new issue, #55833:
URL: https://github.com/apache/arrow/issues/55833
### Describe the bug, including details regarding any error messages,
version, and platform.
`pyarrow.json.read_json` crashes the process, or silently returns wrong
values, when a field is an array or object in one block and a scalar in a later
block. With default options this happens on any file just over 1 MiB. If the
conflicting rows are in the same block, it correctly raises `ArrowInvalid: JSON
parse error: Column(/c) changed from object to number`.
```python
import io
import pyarrow.json as pj
data = b'{"c": {"x": 1}}\n' * (2**20 // 16) + b'{"c": 7}\n' * 1000
pj.read_json(io.BytesIO(data))
pj.read_json(io.BytesIO(b'{"c": [1]}\n{"c": 1}\n'),
read_options=pj.ReadOptions(block_size=11))
pj.read_json(io.BytesIO(b'{"c": {"x": 1}}\n{"c": 1}\n'),
read_options=pj.ReadOptions(block_size=16)).column("c").to_pylist()
```
Reproduced on pyarrow 12.0.1 through 26.0.1 (Linux x86-64) and with
`arrow::json::TableReader` built from `main` @ 5ef973d.
**Cause:** blocks are parsed independently, and
`ChunkedStructArrayBuilder::InsertChildren` passes a field's column to the
child builder created for that field's first block without checking its kind
([chunked_builder.cc#L419](https://github.com/apache/arrow/blob/5ef973da06974e42e0f6f07d35254f4b99ffe6b0/cpp/src/arrow/json/chunked_builder.cc#L419)).
The list and struct builders then `checked_cast` it to `ListArray` /
`StructArray`, guarded only by a `DCHECK`
([#L224-L225](https://github.com/apache/arrow/blob/5ef973da06974e42e0f6f07d35254f4b99ffe6b0/cpp/src/arrow/json/chunked_builder.cc#L224-L225),
[#L318](https://github.com/apache/arrow/blob/5ef973da06974e42e0f6f07d35254f4b99ffe6b0/cpp/src/arrow/json/chunked_builder.cc#L318)).
They should instead return the same `changed from X to Y` error.
### Component(s)
C++, Python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]