HyukjinKwon opened a new pull request, #407: URL: https://github.com/apache/spark-connect-rust/pull/407
### What changes were proposed in this pull request? [SPARK-61225](https://issues.apache.org/jira/browse/SPARK-61225): Collect maps whose keys have a user-defined type with their deserialized keys, as PySpark does. - The Rust client built the Python dict of a map from the raw storage key before the UDT converter ran. For a key of a user-defined type the storage key is a list, which cannot be a dict key, so `collect()`, `toLocalIterator()`, `head()`, `first()` and `take()` raised `TypeError: unhashable type: 'list'`. - A map whose key type has a user-defined type (at any depth, also in arrays, structs and map values) is now passed to the converter as its (key, value) pairs. `pyspark.sql.types._udt_converter` deserializes each key and builds the dict, as PySpark does, so `{(1.0, 2.0): 1}` is returned. - Maps without a user-defined key are unchanged, and a plain array-keyed map still raises the same `TypeError` as PySpark. ### Why are the changes needed? A DataFrame whose map key is a user-defined type cannot be collected. For example, with `MapType(PointUDT(), IntegerType())` where `PointUDT` serializes to a list and deserializes to a tuple, `df.collect()` raises `TypeError: unhashable type: 'list'`. PySpark returns `[Row(m={(1.0, 2.0): 1})]`. Map values of a user-defined type already work. ### Does this PR introduce _any_ user-facing change? Yes. Collecting a map whose keys have a user-defined type returns the deserialized keys, as PySpark does, instead of raising `TypeError`. ### How was this patch tested? - `test_map_with_user_defined_keys_is_built_from_the_deserialized_keys` (offline): the converter of a map with user-defined keys builds the dict from the (key, value) pairs with the keys deserialized, and handles None and empty maps. - `test_maps_with_user_defined_keys_collect_their_deserialized_keys_as_pyspark` (live): a map with user-defined keys at the top level, in a struct, in an array and in a map value, through `collect`, `toLocalIterator`, `head`, `first` and `take`, and a plain array-keyed map still raising `TypeError`. The same results come from official PySpark 4.3.0. - The lib tests of both crates (658 passed), the build of all tests, also with `wasm-udf`, the offline Python suites (2704 passed, 8 skipped), and the live drop-in and Arrow suites (225 passed) and live cases (12 passed) against a local Spark 4.3.0 server. Clippy reports no diagnostics in the changed lines. ### 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]
