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

   ### What changes were proposed in this pull request?
   
   A follow-up of #543 (SPARK-61496), from a review of it. The Python client's 
`_joinAsOf` (`crates/pyspark-rs/src/dataframe.rs`), which #543 changed to parse 
`how` and `direction` into `AsOfJoinType` and `AsOfJoinDirection`, now raises 
PySpark's errors for the values that are not names. #543 says the client raises 
no error that PySpark does not.
   
   PySpark's `_joinAsOf` only asserts `isinstance(how, str)`, and does not 
check `direction`. It puts both in protobuf string fields when it sends the 
plan, so their errors are protobuf's (pyspark/sql/connect/dataframe.py and 
plan.py `AsOfJoin`). This client builds the plan at once, so it raises those 
errors at the call:
   
   - A `how` that is a str but that UTF-8 cannot encode (a lone surrogate) 
passes PySpark's assert, and is protobuf's `ValueError`. It was the 
`AssertionError` "how should be a string", which says the wrong thing of a str.
   - `direction` is now taken as any value (`DefaultedOption`, with the same 
signature):
     - a str (protobuf's `ValueError` for a lone surrogate, where it was PyO3's 
`UnicodeEncodeError`);
     - bytes of UTF-8, read as their text, as protobuf does (they were a 
`TypeError`);
     - anything else, protobuf's `TypeError` "Cannot set 
spark.connect.AsOfJoin.direction to ...".
   
     Its errors come after those of PySpark's own checks, as the plan is sent 
after them.
   - The doc of `PlanIds::node_of` names `root_id_of` too, among the ways a 
node gets a plan ID.
   
   ### Why are the changes needed?
   
   To match PySpark 4.3.0. Probes with its Connect client against a local Spark 
4.3.0 server, with `left = spark.range(3)` and `left._joinAsOf(spark.range(3), 
"id", "id", ...)`:
   
   | argument | PySpark 4.3.0, raised when the plan is sent | this client 
before, at the call |
   |---|---|---|
   | `how="\ud800"` | `ValueError: '\ud800' isn't a valid unicode string and 
can't be encoded in UTF-8.` | `AssertionError: how should be a string` |
   | `direction="\ud800"` | the same `ValueError` | `UnicodeEncodeError` |
   | `direction=b"forward"` | no error, `forward` | `TypeError` |
   | `direction=b"\xff"` | `ValueError: b'\xff' has type bytes, but isn't valid 
UTF-8 encoding. ...` | `TypeError` |
   | `direction=1`, `direction=None` | `TypeError: Cannot set 
spark.connect.AsOfJoin.direction to 1: 1 has type <class 'int'>, but expected 
one of: (<class 'bytes'>, <class 'str'>)` | PyO3's `TypeError` |
   
   This client now raises PySpark's error class and message in each case, at 
the call. The timing differs, as for the option strings of #550.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, on unreleased changes: the errors above, and `direction` given as UTF-8 
bytes.
   
   ### How was this patch tested?
   
   - `test_join_as_of_sends_the_as_of_join_as_pyspark` 
(`python/tests/test_dropin_offline.py`) now covers each case of the table. It 
fails on an extension built from master and passes with the change. Each 
expected message was checked with official PySpark 4.3.0.
   - The offline drop-in and ML suites (2016 passed), the as-of join tests of 
`test_dropin_e2e.py` against a Spark 4.3.0 server, `cargo build -p pyspark-rs 
--release`, `cargo fmt --all -- --check`, `ruff check`, and 
`scripts/audit_no_stubs.sh`.
   
   ### 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