tdcmeehan opened a new pull request, #432:
URL: https://github.com/apache/spark-connect-rust/pull/432

   ### What changes were proposed in this pull request?
   
   [SPARK-61285](https://issues.apache.org/jira/browse/SPARK-61285): 
`DataFrame::repartition_by_range` and `repartition_by_range_opt` sort each 
column that is not already a sort order ascending, nulls first, as PySpark's 
`repartitionByRange` does.
   
   - `crates/spark-connect/src/dataframe.rs`: `repartition_by_range_opt` wraps 
each plain column in `SortOrder::asc_nulls_first` and keeps sort orders as they 
are. The server range-partitions only on sort orders, so before this change a 
plain column was hash-partitioned.
   - `crates/pyspark-rs/src/dataframe.rs`: `repartitionByRange` had the same 
wrapping in the Python client. It now relies on the core method, so both 
clients share one code path. Its behavior is unchanged.
   - Tests: an offline unit test in `plan_construction_tests` checks the 
`partition_exprs` of both methods (plain column becomes ascending, nulls first; 
descending and ascending-nulls-last sort orders are unchanged). An e2e test in 
`tests/e2e_dataframe.rs` checks that `range(100).repartition_by_range(4, id)` 
puts 0-24, 25-49, 50-74 and 75-99 in the four partitions.
   
   ### Why are the changes needed?
   
   Repro against an OSS Spark 4.3.0 Connect server, the min, max and count of 
`id` per `spark_partition_id()`:
   
   | Call | Result before | Result after |
   |---|---|---|
   | Rust `repartition_by_range(4, id)` | (2, 93, 28), (0, 99, 24), (14, 94, 
24), (3, 98, 24) | (0, 24, 25), (25, 49, 25), (50, 74, 25), (75, 99, 25) |
   | Python `repartitionByRange(4, "id")` | (0, 24, 25), (25, 49, 25), (50, 74, 
25), (75, 99, 25) | unchanged |
   | PySpark 4.3.0 `repartitionByRange(4, "id")` | (0, 24, 25), (25, 49, 25), 
(50, 74, 25), (75, 99, 25) | same |
   
   The Rust result equals `repartition(4, id)`, so the rows of a partition were 
not contiguous. Files written per partition therefore differed, and 
`sortWithinPartitions` after the call did not sort globally.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `DataFrame::repartition_by_range` and `repartition_by_range_opt` now 
range-partition on plain columns instead of hash-partitioning them. Calls that 
pass sort orders (`asc`, `desc`, with nulls first or last) are unchanged.
   
   ### How was this patch tested?
   
   - New offline unit test `repartition_by_range_sorts_plain_columns_only` 
(both methods). It fails without this change.
   - New e2e test `repartition_by_range_splits_into_contiguous_ranges` in 
`tests/e2e_dataframe.rs`, run against the local Spark 4.3.0 Connect server. It 
fails without this change (it returned the hash split above) and passes with it.
   - `cargo test -p apache-spark-connect --release --lib`: 529 passed.
   - `cargo test -p apache-spark-connect --release --no-run`, and with 
`--features wasm-udf`: build.
   - `cargo fmt --all --check`: clean. Clippy reports no diagnostics on the 
changed lines.
   - Live `e2e_dataframe`, `e2e_ops_breadth`, `coverage_plan_extra`: 8, 5 and 7 
passed.
   - Python offline suites (`test_dropin_offline.py`, `test_ml_offline.py`, 
`test_arrow_handoff.py`): 2927 passed, 8 skipped. Live (`test_arrow_e2e.py`, 
`test_dropin_e2e.py`, `test_ml_e2e.py`): 236 passed, 1 skipped.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5 and Claude Haiku 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]

Reply via email to