pyarrow.json.read_json ignores nullable=True on fields with non-nullable subfields in explicit_schema parse_options
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
**Summary:**
The parser seems to be ignoring the "nullable" flag on the parent field.
This behavior may be related to ARROW-16603, but that issue covers the opposite case - failing to include the "not null" constraints in the schema of the output table.
**Reproducible example:**
```java
import pyarrow as pa
interior_struct = pa.struct([
pa.field(name='some_information', type=pa.int64(), nullable=False)
])
sample_schema = pa.schema([
pa.field(name='my_struct', type=interior_struct, nullable=True)
])
# The issue persists regardless of the input JSON,
# so long as there is no field named "my_struct" in the input.
# Using an empty JSON object for example
sample_json_bytes = io.BytesIO('{}'.encode())
table = pa.json.read_json(
input_file=sample_json_bytes,
parse_options=pa.json.ParseOptions(explicit_schema=sample_schema)
)
print(table)
```
**Expected output:**
Table containing one column:
- Name is "my_struct"
- Type is "interior_struct"
- Contains a single value, which is null
**Actual output:**
```java
ArrowInvalid: JSON parse error: a required field was null
```
**Reporter**: [Ryan Weisman](https://issues.apache.org/jira/browse/ARROW-17835)
**Note**: *This issue was originally created as [ARROW-17835](https://issues.apache.org/jira/browse/ARROW-17835). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Research direction
Start by reproducing the issue through pyarrow.json.read_json with ParseOptions(explicit_schema=sample_schema) and an empty JSON object. Trace how the explicit schema is handled when the parent field is nullable but its nested field is non-nullable, then verify that the result contains a null my_struct value without a required-field error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100