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

   ### What changes were proposed in this pull request?
   
   [SPARK-61245](https://issues.apache.org/jira/browse/SPARK-61245): Cover the 
uncovered Python shim paths of the drop-in, and read protobuf options as a 
mapping as PySpark does.
   
   This adds 33 offline test functions (55 cases with their parameters) to 
`python/tests/test_dropin_offline.py`, under a comment header just before 
`test_numpy_numeric_aliases_match_reference_scalar_classes`. They cover:
   
   - pandas Arrow input: customized frames keep their values, a struct of 
repeated field names, NaT in a non-nullable timestamp field, nanoseconds that 
do not fit a microsecond timestamp, object Decimal columns that overflow or mix 
types (with and without a schema), and an empty dict map under 
`inferPandasDictAsMap`.
   - UDFs and functions: the return-type checks of each UDF kind, the argument 
checks of the UDF constructor, the registration of UDF objects, the lambda 
parameter checks of higher-order functions, `months`/`days`/`hours`, 
`string_agg_distinct`, `reduce`, `broadcast`, and the avro and protobuf 
functions.
   - `SQLContext`: delegation to its session, `tables()`, and session identity.
   - The client: configuration reads, observed metrics, the ML cache 
re-entrancy guards and the metrics attached by `to_pandas`.
   - Literals (values decoded from protos, and reprs), SQL string formatting, 
dependency checks, and the finalizer of a cached relation.
   
   One shim fix is included. `_dict_to_options_column` in 
`python/pyspark/sql/functions.py` passed a non-dict value through as the 
options map. So `from_protobuf("b", "M", None, col("x"))` built an expression 
from a Column. PySpark reads the options through `items()`, so a Column raises 
`TypeError`. The helper now reads `items()` directly. Avro and protobuf already 
validate or pass dicts, so their behavior is unchanged.
   
   ### Why are the changes needed?
   
   The Python shims of the drop-in had 382 uncovered lines and branches in the 
files of this area, which CI measures with `python/.coveragerc`. Covering them 
with tests checks the behavior that they implement, against PySpark 4.3.0 where 
the behavior is PySpark's.
   
   The protobuf case is a real divergence. `from_protobuf("b", "M", None, 
col("x"))` returned a Column in the drop-in, while PySpark 4.3.0 raises 
`TypeError: 'Column' object is not callable`. A Column given as options 
silently became part of the plan.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, a small one. `from_protobuf` and `to_protobuf` given a non-mapping 
value as options now raise `TypeError`, as PySpark does, instead of building an 
expression from it. Valid dict options are unchanged.
   
   ### How was this patch tested?
   
   - The new tests cover the uncovered paths listed above. Their expected 
results were checked against PySpark 4.3.0 on a Spark Connect server, for 
example the UDF and registration errors, the lambda parameter errors, the avro 
and protobuf expression reprs, the literal reprs, the SQL formatting, the 
`tables()` rows and the `getConf` defaults. The pandas error cases were checked 
the same way.
   - `test_protobuf_options_must_be_a_map_as_pyspark` fails without the fix 
(the call returned a Column instead of raising).
   - The message of the `TypeError` names the PyO3 class of the drop-in 
(`pyspark.sql.connect.column.Column`), while PySpark names `Column`. The test 
accepts both.
   - The lib tests of both crates (664 passed), the build of all tests, also 
with `wasm-udf`, the offline Python suites (2874 passed, 8 skipped), and the 
live drop-in and Arrow suites (233 passed) and live cases (13 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 and Claude Haiku 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