yraivo opened a new issue, #55846:
URL: https://github.com/apache/arrow/issues/55846
## Describe the bug
A Parquet Dataset scan can silently drop matching rows when the Dataset
schema reorders the file's columns and the filter references a field by
position.
In the example below, the physical column order is `(other, x)` and the
Dataset schema order is `(x, other)`. Both `ds.field("x")` and `ds.field(0)`
refer to logical column `x`, but the positional filter returns 0 rows instead
of 2 (without raising an error):
```python
import pyarrow as pa
import pyarrow.dataset as ds
import pyarrow.parquet as pq
physical = pa.table({
"other": pa.array([100, 100, 0, 0], type=pa.int32()),
"x": pa.array([1, 2, 20, 21], type=pa.int32()),
})
sink = pa.BufferOutputStream()
pq.write_table(physical, sink, row_group_size=2)
data = sink.getvalue()
logical = pa.schema([("x", pa.int32()), ("other", pa.int32())])
print("PyArrow", pa.__version__)
for ref in ["x", 0]:
fragment = ds.ParquetFileFormat().make_fragment(pa.BufferReader(data))
result = fragment.to_table(schema=logical, filter=ds.field(ref) < 10)
print(repr(ref), result.to_pydict())
```
Actual output (PyArrow 26.0.1):
```text
PyArrow 26.0.1
'x' {'x': [1, 2], 'other': [100, 100]}
0 {'x': [], 'other': []}
```
Expected: both filters return `{'x': [1, 2], 'other': [100, 100]}`.
### Root cause
The filter predicate is bound against the Dataset schema, so `FieldRef(0)`
refers to `x`. However, `ParquetFileFragment::TestRowGroups` resolves
`FieldRef` directly against `physical_schema_`, matching physical column `0`
(`other`) instead and applying `other`'s row-group statistics (`[100, 100]`) to
prune row group 0.
Besides direct `ds.field(index)` calls, Arrow's Substrait consumer also
produces positional `FieldRef(index)` filters
(`cpp/src/arrow/engine/substrait/expression_internal.cc`) and passes `ReadRel`
filters directly into `ScanOptions::filter` (`relation_internal.cc`).
Related: found while working on #36302. #20114 is an earlier report about
numeric field-reference support. This reproducer accepts the positional
reference but returns incorrect rows after schema reordering.
Used AI tools to help trace the root cause and draft this report (repro
verified locally).
## Component(s)
C++, Python, Parquet
--
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]