tdcmeehan opened a new pull request, #521: URL: https://github.com/apache/spark-connect-rust/pull/521
### What changes were proposed in this pull request? [SPARK-61435](https://issues.apache.org/jira/browse/SPARK-61435): createDataFrame of the Python client sends the bytes() of a bytes or bytearray subclass in a binary column, as PySpark does. - The `BinaryType` branch of `convert` (`crates/pyspark-rs/src/infer.rs`) read the buffer of any `bytes` or `bytearray`, subclasses included. - Now an exact `bytes` or `bytearray` is read as before, and a subclass goes through `bytes(value)`, which takes its `__bytes__`. ### Why are the changes needed? PySpark's `convert_binary` (`pyspark/sql/conversion.py`) first asserts that the value is `bytes` or `bytearray`, then returns an exact `bytes` as it is and calls `bytes(value)` on any other. For a subclass with its own `__bytes__`, the Python client sent the buffer instead, so the data differed with no error. ### Does this PR introduce _any_ user-facing change? Yes. A `bytes` or `bytearray` subclass with a `__bytes__` in a binary column is sent as the result of `bytes()`. Before, with `class B(bytes)` returning `b"other"` from `__bytes__`, `createDataFrame([(B(b"orig"),)], "b binary").collect()` gave `b'orig'`; PySpark and now the client give `b'other'`. ### How was this patch tested? - Python offline: `test_binary_subclasses_are_sent_as_the_bytes_of_pyspark` checks the Arrow data sent for a bytes subclass and a bytearray subclass with `__bytes__`, a subclass without it, plain bytes, bytearray and None, a subclass inside `array<binary>`, and the errors of a `__bytes__` that returns a non-bytes (`TypeError`) or raises (passed through). It fails on the base build (`b'orig'` against `b'other'`). - Python e2e (`test_dropin_e2e.py`): `test_binary_subclasses_are_sent_as_the_bytes_of_pyspark` against a local Spark 4.3.0 Connect server; it passes with pyspark-client 4.3.0 as well. - Rust library: 602 passed, and `-p apache-spark-connect-core` passes. Python offline suites: 3119 passed, 8 skipped. Python e2e suites: 292 passed, 1 skipped. `ruff check` passes. All Rust test targets compile with and without `wasm-udf`; `cargo fmt --all --check` passes, and clippy reports nothing in `infer.rs`. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 and Claude Sonnet 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]
