HyukjinKwon opened a new pull request, #526:
URL: https://github.com/apache/spark-connect-rust/pull/526
### What changes were proposed in this pull request?
The seeds of `randomSplit`, `sample`, `sampleBy` and `stat.sampleBy` that
PySpark cannot send now raise PySpark's errors in the Python client:
- `randomSplit` and `sample`: a seed whose `int()` is outside a long raises
`ValueError: Value out of range: <int>`, as protobuf does, instead of
`OverflowError`.
- `sampleBy` and `stat.sampleBy`: a seed that is not an int raises a bare
`AssertionError`, as PySpark's `StatSampleBy` asserts. A bool raises the
`TypeError` with which the proto refuses it, and an int out of the range of a
long raises `ValueError`. The checks of `col` and `fractions` come first, as in
PySpark.
### Why are the changes needed?
The drop-in did not match PySpark 4.3.0 for these seeds:
```python
df.randomSplit([1.0, 1.0], 2**63) # before: OverflowError: Python int too
large to convert to C long
# PySpark: ValueError: Value out of
range: 9223372036854775808
df.sampleBy("id", {0: 0.5}, 3.7) # before: TypeError: argument 'seed':
'float' object cannot be interpreted as an integer
# PySpark: AssertionError
df.sampleBy("id", {0: 0.5}, np.int64(3)) # before: accepted; PySpark:
AssertionError
df.sampleBy("id", {0: 0.5}, True) # before: accepted
# PySpark: TypeError: Cannot set
spark.connect.StatSampleBy.seed to True: True has type <class 'bool'>, but
expected one of: (int).
```
PySpark raises the `TypeError` of a bool seed and the `ValueError` of a seed
beyond a long when the plan is serialized; the drop-in raises them at the call,
as its other checks of proto fields do. This is a follow-up of SPARK-61396
(#486).
### Does this PR introduce _any_ user-facing change?
Yes. The errors for the seeds above now match PySpark's class and message.
Valid seeds, including the bounds of a long, are unchanged.
### How was this patch tested?
A new offline test,
`test_seeds_that_pyspark_cannot_send_are_refused_as_pyspark`, which fails
without the fix and passes with it. A probe against a Spark 4.3.0 server
matched the reference client's class and message for every seed above. Also ran
the offline suite (1836 passed), the e2e sample, randomSplit, sampleBy and
dropna tests against Spark 4.3.0, the Rust library tests, the `--no-run` builds
(with and without `wasm-udf`), `cargo fmt --check`, `scripts/audit_no_stubs.sh`
and the ruff gates.
### 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]