HyukjinKwon opened a new pull request, #369: URL: https://github.com/apache/spark-connect-rust/pull/369
### What changes were proposed in this pull request? [SPARK-61189](https://issues.apache.org/jira/browse/SPARK-61189): Send the metadata edited in place of a StructType in the schemas of mapInPandas, mapInArrow, applyInPandas and transformWithState, as PySpark does. `resolve_datatype` read the base snapshot of a `StructType` (refreshed only by `add`), so an edit of a field's metadata after the struct was built, such as `st["a"].metadata["comment"] = "the a"`, was not sent to the server. It now converts the schema through `py_to_data_type`, which reads the live fields of a `StructType`, as the other schema arguments already do. Official PySpark keeps the edit in the schemas of these functions. ### Why are the changes needed? With `st = StructType([StructField("a", IntegerType())]); st["a"].metadata["comment"] = "the a"`, `df.mapInPandas(f, st).schema["a"].metadata` was `{}` (and `applyInPandas` and `mapInArrow` likewise), where official PySpark gives `{'comment': 'the a'}`. The data is unaffected; only the schema metadata differs. ### Does this PR introduce _any_ user-facing change? Yes. The schemas of mapInPandas, mapInArrow, applyInPandas and transformWithState carry the metadata edited in place after a StructType was built. ### How was this patch tested? - `test_map_schemas_keep_the_metadata_edited_in_place_as_pyspark` (offline, mock server): reads the schema sent for mapInPandas, mapInArrow and applyInPandas, for a struct edited after construction and after `add`, and checks the field metadata in the proto. Fails without the fix. - `test_map_schemas_keep_the_metadata_edited_in_place_on_the_server_as_pyspark` (live): the result schema of mapInPandas, mapInArrow and applyInPandas has the edited metadata. Fails without the fix. - The same cases give the same metadata with official PySpark 4.3.0. - The lib tests of both crates (599 passed), the build of all tests, also with `wasm-udf`, and the offline Python suites (2228 passed, 8 skipped), and the live tests of the map, grouped and stateful functions, schemas and metadata (45 passed) against a local Spark 4.3.0 server; rustfmt passes, and 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]
