[
https://issues.apache.org/jira/browse/SPARK-61435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tim Meehan updated SPARK-61435:
-------------------------------
Fix Version/s: connect-rust-4.3.0
> Send the bytes() of a bytes or bytearray subclass in a binary column of
> createDataFrame in the Python client, as PySpark does
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: SPARK-61435
> URL: https://issues.apache.org/jira/browse/SPARK-61435
> Project: Spark
> Issue Type: Bug
> Components: Connect
> Affects Versions: connect-rust-4.3.0
> Reporter: Tim Meehan
> Priority: Major
> Fix For: connect-rust-4.3.0
>
>
> createDataFrame of the Python client of spark-connect-rust, for a column of
> BinaryType, reads the buffer of a bytes or bytearray subclass. PySpark's
> LocalDataToArrowConversion calls bytes() on it, which takes the __bytes__ of
> the subclass. A subclass with its own __bytes__ is sent with other bytes, and
> no error is raised.
> {code:python}
> from pyspark.sql import SparkSession
> class B(bytes):
> def __bytes__(self):
> return b"other"
> spark = SparkSession.builder.remote("sc://localhost:15002").getOrCreate()
> print(spark.createDataFrame([(B(b"orig"),)], "b binary").collect())
> {code}
> Against an OSS Spark 4.3.0 Connect server on loopback:
> * pyspark-client 4.3.0: [Row(b=b'other')].
> * spark-connect-rust master 125654b: [Row(b=b'orig')].
> The same holds for a bytearray subclass with a __bytes__ (b'other' against
> b'orig'). A subclass without a __bytes__, and bytes and bytearray themselves,
> give the same bytes in both clients.
> From source, at 125654b: the BinaryType branch of convert
> (crates/pyspark-rs/src/infer.rs:1217-1224) casts the value to PyBytes or
> PyByteArray, which also succeeds for a subclass, and copies the buffer.
> PySpark's convert_binary (pyspark/sql/conversion.py) returns an exact bytes
> as it is and calls bytes(value) on any other bytes or bytearray.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]