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

   ### What changes were proposed in this pull request?
   
   `WindowSpec::partition_by` and `WindowSpec::order_by` of the Rust API 
appended their columns to those of the spec. The drop-in's 
`WindowSpec.partitionBy` and `orderBy` call them.
   
   PySpark's (connect/window.py:85-96), as Spark's `WindowSpec`, return a new 
spec whose partitioning or ordering is the new columns only, and keep the other 
parts:
   
   ```python
   def partitionBy(self, *cols):
       return WindowSpec(
           partitionSpec=[c._expr for c in _to_cols(cols)],
           orderSpec=self._orderSpec,
           frame=self._frame,
       )
   ```
   
   So a chained call gave other results, silently. For rows `(1, 10), (2, 10), 
(3, 20)` of columns `a` and `b`:
   
   | | PySpark 4.3.0 (now here too) | before |
   |---|---|---|
   | `count("*").over(Window.partitionBy("a").partitionBy("b"))` | `2, 2, 1` | 
`1, 1, 1` |
   | `row_number().over(Window.orderBy("a").orderBy(col("b").desc(), "a"))` | 
`2, 3, 1` | `1, 2, 3` |
   | `repr(Window.partitionBy("a").partitionBy("b"))` | 
`WindowSpec(PartitionBy(b))` | `WindowSpec(PartitionBy(a, b))` |
   | `repr(Window.partitionBy("a").partitionBy())` | `WindowSpec()` | 
`WindowSpec(PartitionBy(a))` |
   
   With this PR, the two methods replace the partitioning or the ordering, in 
the core, so the Rust API and the drop-in both do as PySpark does. A round-2 
review of master against PySpark 4.3.0 found this. It has been in the core 
since its first version.
   
   ### Why are the changes needed?
   
   A window over a chained `partitionBy` or `orderBy` returned wrong results, 
with no error.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes: a chained `partitionBy` or `orderBy` partitions or orders by the 
columns of the last call only, in the drop-in and in the Rust API, as PySpark 
and Spark do.
   
   ### How was this patch tested?
   
   - **New tests**, which fail on master:
     - `window.rs`: 
`chained_partition_by_and_order_by_replace_the_specs_as_pyspark`;
     - `test_dropin_offline.py`: 
`test_chained_partition_by_and_order_by_replace_the_spec_as_pyspark`, the reprs 
of the official client;
     - `test_dropin_e2e.py`: 
`test_chained_window_specs_partition_and_order_by_their_last_columns_as_pyspark`,
 the results above against a Spark 4.3.0 server.
   - **Existing tests.** The window tests of `test_dropin_offline.py` and 
`test_dropin_window_tablearg_offline.py` on pandas 2 and 3, and the live window 
tests of `test_dropin_e2e.py`. On the Rust side, `cargo test -p 
apache-spark-connect --release --lib window` and `--test window_golden`.
   - **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -p 
apache-spark-connect --all-targets -- -D warnings` and ruff 0.14.0.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: 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]

Reply via email to