yraivo opened a new pull request, #55847: URL: https://github.com/apache/arrow/pull/55847
### Rationale for this change A positional filter on a Parquet Dataset is bound to the Dataset schema, but `ParquetFileFragment::TestRowGroups` resolves field references directly against `physical_schema_`. When the Dataset schema reorders columns relative to the Parquet file, row-group pruning can apply statistics from a different column and silently drop matching rows without error. ### What changes are included in this PR? * Pass `options->dataset_schema` from `ParquetFileFormat::ScanBatchesAsync` and `ParquetFileFormat::CountRows` into `ParquetFileFragment::FilterRowGroups` / `TestRowGroups` / `TryCountRows` (falling back to `physical_schema_` for fragment-only callers without a scan schema). * Canonicalize positional `FieldRef`s to name sequences against the scan schema before matching physical columns and caching statistics, preserving each parameter's bound logical type and indices. * Skip statistics for a field when its scan-schema name is ambiguous (duplicate names). ### Are these changes tested? Yes. Added three unit tests in `cpp/src/arrow/dataset/file_parquet_test.cc`: * `PredicatePushdownWithReorderedSchemaAndFieldIndex`: positional vs. named filters when a reordered column sits next to a different-type column. * `PredicatePushdownWithReorderedIntegerFields`: positional vs. named filters for same-type reordered columns in both cache warm-up orders, checking both `CountRows` and scanned table results. * `AmbiguousFieldReferenceDoesNotCacheStatistics`: skipping an ambiguous reference does not prevent a later named query from using statistics, in either cache order. Verified locally with `arrow-dataset-file-parquet-test`. ### Are there any user-facing changes? **This PR contains a "Critical Fix".** Parquet dataset scans with positional filters (such as `ds.field(0)` or Substrait `ReadRel` filters) could silently drop matching rows when the dataset schema reordered columns relative to the file schema. With this fix, positional filters resolve against the scan schema and return the expected rows. ### Was AI used for this PR? In accordance to the [AI generation guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code), please disclose below whether and how AI was used in this PR. Used AI coding tools to help draft the implementation and unit tests. I reviewed the diff and verified the tests locally. **PR code and description written by:** - [x] Human - [x] AI **Reviewed before submission by:** - [x] Human - [x] AI - [ ] Not reviewed * GitHub Issue: Closes #55846 -- 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]
