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

   ### What changes were proposed in this pull request?
   
   [SPARK-60967](https://issues.apache.org/jira/browse/SPARK-60967): a 
collected value of a user-defined type is now the object that its UDT 
deserializes, as PySpark's `ArrowTableToRowsConversion` makes it. A value of a 
`VectorUDT` is a `DenseVector`, in arrays, maps and structs too.
   
   - `collect`, `first`, `head`, `take`, `tail` and `toLocalIterator` read the 
schema of the result that the server sends with the rows, 
`ExecutePlanResponse.schema`. Unlike the Arrow schema of the rows, it has the 
user-defined types. They read it through the new 
`DataFrame::collect_with_schema`, `first_with_schema`, `take_with_schema` and 
`LocalRowIterator::schema` of the Rust core.
   - For a result with a user-defined type, 
`pyspark.sql.types._udt_field_converters` gives a converter per field, which 
the rows apply to their values when they are first read. Other results are 
unchanged.
   - `dtypes`, and `simpleString()` of an array, map, struct or field of a 
user-defined type, name the type by the `simpleString()` of its Python class, 
such as `vector` and `array<vector>`.
   
   ### Why are the changes needed?
   
   With `df = spark.sql("SELECT array(1.5D, 2.0D) AS 
a").select(array_to_vector("a").alias("vec"))` of `pyspark.ml.functions`:
   
   | | PySpark 4.3.0 and now | Before |
   | --- | --- | --- |
   | `df.first().vec` | `DenseVector([1.5, 2.0])` | `Row(type=1, size=None, 
indices=None, values=[1.5, 2.0])` |
   | `df.dtypes` | `[('vec', 'vector')]` | `[('vec', 'udt')]` |
   | `ArrayType(VectorUDT()).simpleString()` | `array<vector>` | `array<udt>` |
   
   The field type of `df.schema` was already the `VectorUDT`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, collected values of user-defined types and their names are those of 
PySpark 4.3.0.
   
   ### How was this patch tested?
   
   - Against a local Spark 4.3.0 server, `dtypes`, `first`, `collect`, `take`, 
`head`, `tail` and `toLocalIterator` (with and without prefetching) of vectors 
give the same results as official PySpark 4.3.0. So do `NULL` vectors, vectors 
in arrays, structs and maps, `asDict(recursive=True)`, `printSchema()` and 
`schema.simpleString()`. Before this change, all but `printSchema()` differed.
   - A new live test checks these. A new offline test checks the names of 
nested user-defined types. Both also pass with official PySpark 4.3.0, and fail 
without this change. A new offline test checks the converters.
   - The lib tests and every integration test, e2e included, against the local 
server (652 passed, and 123 of the transport crate), the build of all tests 
with `wasm-udf`, the offline Python suites (880 passed, 9 skipped), and the 
live drop-in and Arrow suites (82 passed) and live cases (10 passed). In the 
changed lines, clippy reports only the `result_large_err` of the `py.detach` 
closures, which every action of the Python `DataFrame` has.
   
   `toPandas()` of a user-defined type, and of timestamps and maps, is 
[SPARK-61000](https://issues.apache.org/jira/browse/SPARK-61000).
   
   ### 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