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

   ### What changes were proposed in this pull request?
   
   [SPARK-61485](https://issues.apache.org/jira/browse/SPARK-61485): follow-ups 
of a post-hoc review of SPARK-61402 (#476) and SPARK-61405 (#478), checked 
against PySpark 4.3.0.
   
   - **Methods of `Row`, `VariantVal`, `Geometry` and `Geography`** 
(`crates/pyspark-rs/src/row.py`, `values.py`): the embedded modules set the 
`__module__` of their methods to `pyspark.sql.types`, as they did for the 
classes. This covers functions, classmethods, staticmethods and properties, as 
PySpark's methods are of `pyspark.sql.types`.
   - **The invalid-UTF-8 scan of a result** 
(`crates/spark-connect/src/dataframe.rs`, `read_strings_as_binary`) reads a 
stream of one schema only, as a valid Arrow IPC stream is. A stream with 
another schema message is not read there, and the decoding error is reported as 
it is.
   - **Docs** (`docs/compatibility.md`): SPARK-61405's changes:
     - the strata that `sample_by` rejects;
     - the seed that it draws on the client;
     - the `Value::Map` fill of `fillna_value`.
   
   ### Why are the changes needed?
   
   - **UDF methods fail on the server.** A UDF that is, or captures, a method 
of these classes failed on the server, for example:
     - `F.udf(Geography.getSrid, "int")`;
     - `F.udf(VariantVal.toJson, "string")`;
     - `F.udf(variant.toJson, "string")`;
     - a UDF that captures `Row.asDict`.
   
     It raised `PythonException: ... ModuleNotFoundError: No module named 
'pyspark._values'` (or `'pyspark._row'`). cloudpickle pickles a method by 
reference to its module, and `pyspark._values` and `pyspark._row` exist on the 
client only; official PySpark's methods are of `pyspark.sql.types`, which the 
server's Python workers import. Official PySpark returns `4326`, `{"b":2}`, 
`{"a":1}` and the dict.
   - **A panic on a malformed stream.** The scan took the column count from the 
first batch and the field types from the last schema message. A stream with a 
second, narrower schema therefore panicked with an index out of bounds 
(`arrow-schema` `schema.rs`). Spark never sends such a stream, but a server 
response should not panic the client.
   - **Stale docs.** They did not describe the SPARK-61405 changes.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. UDFs of these methods run on the server, as with PySpark, and a 
malformed stream raises its decoding error instead of panicking.
   
   ### How was this patch tested?
   
   - Offline (`python/tests/test_dropin_offline.py`, placed before 
`test_spatial_values_copy_pickle_and_are_subclassed_as_pyspark`): 
`test_methods_of_rows_and_values_pickle_by_reference_to_pyspark_sql_types_as_pyspark`.
 The cloudpickles of their functions and bound methods name `pyspark.sql.types` 
and not `pyspark._values` or `pyspark._row`. A classmethod pickles by value, as 
PySpark's does.
   - Live (`python/tests/test_dropin_e2e.py`, placed after 
`test_udfs_that_refer_to_variant_and_spatial_values_run_on_the_server_as_pyspark`):
 `test_udfs_of_methods_of_rows_and_values_run_on_the_server_as_pyspark`. It 
runs UDFs of `Geography.getSrid` and `VariantVal.toJson`, and one that captures 
`Row.asDict`, against a local Spark 4.3.0 server.
   - Rust (`dataframe.rs`): 
`a_stream_of_two_schemas_has_no_invalid_utf8_to_report`.
   - Each new test fails without its change: the live test with the server's 
`ModuleNotFoundError: No module named 'pyspark._values'`, and the Rust test 
with the index-out-of-bounds panic.
   - Checks:
     - the lib tests of both crates (806 passed);
     - the build of all tests, also with `wasm-udf` and `datafusion,polars`, 
without warnings;
     - `cargo fmt --all --check`, and clippy with no diagnostics on the changed 
lines;
     - `ruff check` and `ruff format --check` on `row.py`;
     - a full trial on master, chained after #495, before the merge.
   
   ### 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