gengliangwang opened a new pull request, #60743: URL: https://github.com/apache/spark/pull/60743
### What changes were proposed in this pull request? Backport of https://github.com/apache/spark/pull/60314 (3ce2d25234a) to branch-4.4. The cherry-pick applies cleanly. All ten touched files (the Rust SDK under `sql/native/rust` and the Range example README) are the same on branch-4.4 and on master before #60314, so the change is the same as on master. The C ABI's `push_domains` (SPARK-61200) and the Rust SDK (SPARK-61282) are both in branch-4.4. Expose the C ABI's `push_domains` callback in the Rust native data source SDK. Spark derives conservative column domains from query filters, and a Rust connector can use them to skip files, row groups, pages, or rows that cannot match. Spark still evaluates all filters after reading. The SDK installs the callback for every source with batch reads and adds this default method to `ScanBuilder`: ```rust fn push_domains(&mut self, domains: &[Domain]) -> Result<Vec<bool>> { Ok(vec![false; domains.len()]) } ``` Spark calls it before `push_limit` and `prune_columns`, each at most once. The SDK: - Exposes `Domain { path, null_allowed, nan_allowed, ranges }`, `ValueRange { low, high }`, and typed `Value` bounds. Paths contain column and nested struct-field names resolved against the original scan schema, so later column pruning does not change their meaning. `ranges: None` admits every value other than null and NaN; `Some([])` admits none of those values. Null and NaN membership are controlled separately by their flags. - Supports boolean, integer, floating-point, decimal, string, binary, date, timestamp, and timestamp-without-time-zone bounds. Domains for unsupported column types are reported as unused. `Domain` and `Value` are non-exhaustive. - Takes ownership of the Arrow range arrays, aligns and validates their data before accessing it, and checks that bounds have their column's type. The same Arrow validation helper is shared with the write path. - Converts paired typed low/high iterators directly into the final range vector, avoiding complete temporary endpoint vectors. Type dispatch and downcasts occur outside the row loop, and support detection uses the same dispatch without constructing dummy Arrow arrays. - Makes domains serializable for transport in reader factories. Decimal bounds retain `i128` values in the Rust API but encode their unscaled values as strings, supporting Serde flattened fields and untagged or internally tagged enums. - Validates the number of returned usage flags. Spark reports a filter as pushed in `EXPLAIN FORMATTED` and the SQL UI when the connector uses the domains of all columns that the filter constrains. The trait documentation, SDK README, and Range example document call ordering, domain membership, Spark SQL comparison semantics, and the default behavior. Connectors may skip rows outside a domain but must preserve every row whose values are all within their domains. ### Why are the changes needed? SPARK-61200 (#59929) added domain pushdown to version 1 of the C ABI, but the Rust SDK introduced by SPARK-61282 (#59520) leaves the callback unset. Rust connectors therefore cannot use query-derived domains through the SDK to skip data. This provides the typed, serializable interface needed by sources such as the Parquet connector in #59692, without requiring each connector to import Arrow C range arrays or resolve column ordinals after projection. Both SPARK-61200 and SPARK-61282 ship in 4.4.0. Without this backport, the Rust SDK of 4.4.0 cannot use the domains that its C ABI already passes. ### Does this PR introduce _any_ user-facing change? Yes, in the unreleased experimental Rust SDK: `ScanBuilder::push_domains` and the public `Domain`, `ValueRange`, and `Value` types. Existing connectors continue to compile, and the default implementation reports every domain unused. For a batch query whose filters produce a domain, Spark now creates the source and scan builder (`DataSource::new` and `new_scan`) during query optimization, including for connectors that keep the default method. A pushed limit already causes the same earlier creation. Spark continues to evaluate all filters after reading. ### How was this patch tested? On this branch, from `sql/native/rust`, with Rust 1.85 (the toolchain of the `rust-sdk` CI job): ```sh cargo build --workspace --locked cargo test --workspace --locked cargo clippy --workspace --all-targets --locked -- -D warnings cargo fmt --all -- --check RUSTDOCFLAGS='-D warnings' cargo doc --workspace --no-deps --locked ``` 113 tests passed, with two pre-existing documentation examples ignored, as on master. Clippy, formatting, and documentation passed. The local Cargo runs used cached dependencies with `--offline` and a command-local registry mirror configuration. See #60314 for the tests that it adds. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5) This pull request and its description were written by Isaac. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
