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

   ### What changes were proposed in this pull request?
   
   A follow-up of #571 (SPARK-61542), for the counts and values that it left: 
`bucketBy`, the bounds of `Window.rowsBetween`/`rangeBetween`, and 
`StorageLevel`. PySpark 4.3.0 stores these as given, and protobuf's default upb 
backend converts them when the plan is built. On protobuf 7.34+, which a fresh 
install of `pyspark-client` 4.3.0 gets, a bool in an int field raises 
`TypeError: Field spark.connect.<Msg>.<field>: Expected an int, got a 
boolean.`, and an int out of the field's range raises `ValueError: Value out of 
range: N`. The Python client took these values through PyO3 instead.
   
   **`DataFrameWriter.bucketBy`.** PySpark checks only that `numBuckets` is an 
int (a bool included) at the call. Its `WriteOperation` sends the bucketing at 
the write only for a count above 0. Now:
   - `bucketBy(True, ...)` raises the `TypeError` of `BucketBy.num_buckets` at 
the write, before any request. It used to send 1 bucket.
   - `2**40` raises `Value out of range: 1099511627776` at the write. It used 
to raise PyO3's `OverflowError` at `bucketBy`.
   - A count of 0 or less (`False` included) sends no bucketing, and the last 
`bucketBy` wins. It used to send `BucketBy{0}`.
   - Every write raises these errors: `save`, `saveAsTable`, `insertInto`, 
`jdbc` and the format writers, each time.
   - The core gets `DataFrameWriter::clear_bucket_by`.
   
   **Window frame bounds.** These follow PySpark's order. The comparisons with 
`Window._PRECEDING_THRESHOLD` and `_FOLLOWING_THRESHOLD` come first, so an 
incomparable type raises Python's `TypeError`, such as `'<=' not supported 
between instances of 'str' and 'int'`. Then come the `isinstance(int)` 
assertions of `WindowFrame`, a bare `AssertionError` for `np.int64`, a float or 
a `Decimal`. Then the proto conversion:
   - A row frame's `True` raises the `TypeError` of `Literal.integer`, and a 
range frame's that of `Literal.long`. Both used to be taken as 1.
   - `False` is the current row.
   - A range bound beyond a long raises `Value out of range`.
   - These used to raise "frame bound must be an int or FrameBound", or 
`OverflowError`.
   - `rangeBetween(..., Window.unboundedPreceding)` sends the long -2**63 as 
PySpark does. It used to send -2**63+1.
   
   As before, these errors are raised at the call, where PySpark raises the 
conversion's errors when it builds the plan.
   
   **`StorageLevel`.** As PySpark's, it stores its five values as given, with 
no checks (`StorageLevel(1.5, 'x', None, 0, 2**40)`). They are plain 
attributes, its `repr`, `str` and `==` are PySpark's, and it pickles as 
PySpark's does. `persist`, `localCheckpoint` and `cacheTable` convert it as 
PySpark's `storage_level_to_proto`:
   - a non-`StorageLevel` raises `AssertionError`;
   - a flag goes through upb's bool conversion, and a `None` flag or 
replication is left unset;
   - a bool replication raises `Field spark.connect.StorageLevel.replication: 
Expected an int, got a boolean.`
   - `cacheTable` sends no level for a false one, as PySpark's `if 
self._storage_level:`.
   It used to raise PyO3's errors at construction.
   
   **`sampleBy`'s seed** now uses the shared `proto_int`, with no change in 
behavior except one corner: an out-of-range seed of an int subclass with its 
own `__str__` shows its value, as PySpark's does.
   
   ### Why are the changes needed?
   
   To match PySpark 4.3.0 with protobuf 7. Probes of these cases against 
official `pyspark-client` 4.3.0 on protobuf 7.36.2 (upb) now match line for 
line: about 230 lines for the window bounds and about 165 for `StorageLevel`. 
The remaining differences come from PyO3, such as type names in messages and 
pickle protocols 0 and 1.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in the Python client. `bucketBy`, the window frame bounds and 
`StorageLevel` take and refuse the values that PySpark takes and refuses, with 
PySpark's errors at the same points. In the Rust API, 
`DataFrameWriter::clear_bucket_by` is added.
   
   ### How was this patch tested?
   
   - New tests, which fail without the change:
     - `test_writer_bucket_counts_are_set_at_the_write_as_pyspark`
     - `test_window_frame_bounds_are_compared_asserted_and_converted_as_pyspark`
     - `test_storage_levels_keep_their_values_as_pyspark`
     - `test_storage_levels_are_converted_as_pyspark`
     - 
`test_sample_by_seeds_of_int_subclasses_are_set_as_protobuf_does_as_pyspark`
     - `v1_write_clear_bucket_by_sends_no_bucketing` (Rust)
   - The lib tests of both crates (857 passed), the Rust integration tests 
against a local Spark 4.3.0 server (998 passed, 26 ignored), the build of all 
tests with `wasm-udf`, the offline Python suites (3269 passed, 8 skipped), and 
the live drop-in, Arrow and ML suites (310 and 51 passed), on master with 
SPARK-61590 and SPARK-61591 applied. `cargo fmt --all --check` and the no-stub 
audit pass.
   
   ### 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