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

   ### What changes were proposed in this pull request?
   
   A follow-up of #837 (SPARK-61962) and SPARK-61951, from a review of the last 
100 commits.
   
   PySpark's `PythonUDTF.to_plan` converts the return type of a UDTF with 
`pyspark_types_to_proto_types` each time it builds a plan of a call, of the 
type object that the call kept, and pickles the handler class then. #837 did 
this for the output types of UDFs; the drop-in still converted a valid UDTF 
return type at the call, and only checked it at the build.
   
   **1. The return type is converted at each build.**
   - A UDTF's build-time pickler is now a `CommandPickler::with_output_type` of 
the type object that the call kept: each build converts the return type and 
pickles the handler class, and the plan sends that `PythonUdtf`'s return type 
and command (`udtf_return_type_and_command` in 
`crates/spark-connect/src/udf.rs`).
   - So after `rt = StructType([StructField("a", LongType())]); d = udtf(H, 
returnType=rt)(lit(1)); rt.add("b", LongType())`:
   
     | | PySpark | before |
     |---|---|---|
     | `d.schema` | `struct<a:bigint,b:bigint>` | `struct<a:bigint>` |
     | `d.collect()` | `[Row(a=1, b=2)]` | `PythonException` |
     | a `lateralJoin` of the call: `columns` | `['id', 'a', 'b']` | `['id', 
'a']` |
   
   - This holds for a call, a `lateralJoin`, a table argument, a UDTF inside a 
table argument, `asDeterministic`, `useArrow`, `arrow_udtf`, `copy.copy`, 
`copy.deepcopy` and pickles.
   
   **2. The call keeps what PySpark's `PythonUDTF.__init__` keeps**: the 
handler, its `__name__` and the type object, with a str wrapped as an 
`UnparsedDataType`. So:
   - a str assigned to the UDTF's `returnType` after `udtf()` is parsed, where 
it raised `UNSUPPORTED_OPERATION`;
   - `UDTF_SERIALIZATION_ERROR` names a handler class renamed after the call by 
its name at the call, as PySpark reads `__name__` then.
   
   The errors of a return type that does not convert (`returnType=5`, a bad DDL 
string, `IntegerType()`) keep PySpark's order: the arguments, then the type, 
then the handler pickle. `spark.udtf.register` and `client.register_udtf` 
already converted the type once at the registration, as PySpark does, and do 
not change.
   
   `docs/compatibility.md` describes when the type is converted, and what a 
copy and a pickle keep.
   
   ### Why are the changes needed?
   
   So that a UDTF whose return type is changed after the call, or a UDTF whose 
type or handler changes, behaves as in PySpark, instead of failing on the 
server's Python worker.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as above. The Rust API does not change: the pickler is doc-hidden.
   
   ### How was this patch tested?
   
   - **New tests in `test_dropin_offline.py`**, next to #837's output-type 
tests:
     - 
`test_the_return_types_of_udtfs_are_converted_when_their_plans_are_built_as_pyspark`,
 of 7 paths;
     - `test_udtf_calls_keep_the_return_type_object_of_the_call_as_pyspark`;
     - the rename case in the test of handler pickles, and an `AtomicType` 
field added after the call in the test of the conversion errors.
   - A core unit test of the pickler in `udf.rs`.
   - **Probes of both clients** against a Spark 4.3.0 server: 41 path cases, 
identical (31 differed before); and the requests, normalized plans and results 
of 19 operations through a recording proxy, identical.
   - **Rust.** `cargo test -p apache-spark-connect -p apache-spark-connect-core 
--release`, and `--features wasm-udf`; `cargo test -p pyspark-rs --lib`, linked 
as `rust.yml` links it.
   - **Python.** The offline suite of `coverage.yml` on pandas 2 and 3, and 
live `test_dropin_e2e.py -k udtf`.
   - **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -p pyspark-rs 
-p apache-spark-connect --all-targets -- -D warnings`, ruff 0.14.0, 
`audit_no_stubs.sh` and `scripts/tests`.
   
   ### 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