[Python] Results of running a substrait plan against a tpch data table written into parquet are all null
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
SQL
```java
SELECT l_returnflag, l_linestatus FROM lineitem
```
Substrait Plan:
```java
"""
{
"extensionUris": [],
"extensions": [],
"relations": [{
"root": {
"input": {
"project": {
"common": {
},
"input": {
"read": {
"common": {
"direct": {
}
},
"baseSchema": {
"names": ["L_ORDERKEY", "L_PARTKEY", "L_SUPPKEY", "L_LINENUMBER", "L_QUANTITY", "L_EXTENDEDPRICE", "L_DISCOUNT", "L_TAX", "L_RETURNFLAG", "L_LINESTATUS", "L_SHIPDATE", "L_COMMITDATE", "L_RECEIPTDATE", "L_SHIPINSTRUCT", "L_SHIPMODE", "L_COMMENT"],
"struct": {
"types": [{
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"i32": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"decimal": {
"scale": 0,
"precision": 19,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"decimal": {
"scale": 0,
"precision": 19,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"decimal": {
"scale": 0,
"precision": 19,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"decimal": {
"scale": 0,
"precision": 19,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"fixedChar": {
"length": 1,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"fixedChar": {
"length": 1,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"date": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"date": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"date": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"fixedChar": {
"length": 25,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"fixedChar": {
"length": 10,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"varchar": {
"length": 44,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}],
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
},
"local_files": {
"items": [
{
"uri_file": "file://FILENAME_PLACEHOLDER",
"format": "FILE_FORMAT_PARQUET"
}
]
}
}
},
"expressions": [{
"selection": {
"directReference": {
"structField": {
"field": 7
}
},
"rootReference": {
}
}
}, {
"selection": {
"directReference": {
"structField": {
"field": 6
}
},
"rootReference": {
}
}
}]
}
},
"names": ["L_TAX", "L_DISCOUNT"]
}
}],
"expectedTypeUrls": []
}
"""
```
Result:
```java
pyarrow.Table
L_TAX: decimal128(19, 0)
L_DISCOUNT: decimal128(19, 0)
----
L_TAX: [[null,null,null,null,null,null,null,null,null,null]]
L_DISCOUNT: [[null,null,null,null,null,null,null,null,null,null]]
```
Reproduction Steps:
```java
import pyarrow as pa
import pyarrow.parquet as pq
import pyarrow.substrait as substrait
from pyarrow import json as pyarrow_json
from pyarrow.lib import tobytes
substrait_query =
json_file_path = os.path.join(, 'lineitem.json')
arrow_data_path_parquet = os.path.join(str(tmpdir), 'substrait_data.parquet') substrait_query = tobytes(substrait_query.replace("FILENAME_PLACEHOLDER", arrow_data_path_parquet))
# Save lineitem.json into parquet file
table = pyarrow_json.read_json(json_file_path)
pq.write_table(pa_table, arrow_data_path_parquet)
# Run the substrait query plan
buf = pa._substrait._parse_json_plan(substrait_query)
reader = substrait.run_query(buf)
result = reader.read_all()
print(result)
```
lineitem.json is attached
**Reporter**: [Richard Tia](https://issues.apache.org/jira/browse/ARROW-16980) / @richtia
#### Original Issue Attachments:
- [lineitem.json](https://issues.apache.org/jira/secure/attachment/13046319/lineitem.json)
**Note**: *This issue was originally created as [ARROW-16980](https://issues.apache.org/jira/browse/ARROW-16980). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Research direction
Reproduce the issue using lineitem.json, the Parquet file, and the shown pyarrow.substrait entry points, especially _parse_json_plan and run_query. Compare the Substrait plan's selected fields with the returned table and trace why the selected values are null. Done means the query returns the expected non-null values for the selected lineitem columns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-engineering, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100