tdcmeehan opened a new pull request, #453: URL: https://github.com/apache/spark-connect-rust/pull/453
### What changes were proposed in this pull request? [SPARK-61289](https://issues.apache.org/jira/browse/SPARK-61289): The Python client's higher-order functions now check their column arguments as PySpark 4.3.0 does. `_invoke_higher_order_function` in `python/pyspark/sql/functions.py` converts each column argument with the `_column_or_name` helper (PySpark Connect's `_to_col`, already defined in that module) instead of the local `_to_col`. A Column and a column name are unchanged. Any other value, such as a Python list, raises `PySparkTypeError` with the error class `NOT_EXPECTED_TYPE` and the message parameters `expected_type="Column or str"`, `arg_name="col"` and the type name of the value, whatever the position of the argument. The change covers `aggregate`, `array_sort`, `exists`, `filter`, `forall`, `map_filter`, `map_zip_with`, `reduce`, `transform`, `transform_keys`, `transform_values` and `zip_with`, which all go through that helper. ### Why are the changes needed? The local `_to_col` returns anything that is not a str unchanged, so `F.transform([1, 2, 3], lambda x: x * 10)` sent the list as a literal and returned `[Row(t=[10, 20, 30])]`. PySpark 4.3.0 raises `[NOT_EXPECTED_TYPE] Argument \`col\` should be Column or str, got list.` for the same call, so code written against the Python client could fail on PySpark. The helper of `functions_generated.py` already has PySpark's behavior and is reused, so the fix is limited to the higher-order path and `_to_col` keeps its leniency for its other callers. ### Does this PR introduce _any_ user-facing change? Yes. In the Python client, a value that is neither a Column nor a column name at a column position of one of the higher-order functions now raises `PySparkTypeError` (`NOT_EXPECTED_TYPE`) at call time, instead of being sent to the server as a literal. For example, `F.transform([1, 2, 3], lambda x: x * 10)` and `F.exists([1, 2], lambda x: x > 1)` raise, as they do on PySpark 4.3.0. Columns and column names are unaffected. ### How was this patch tested? - Offline, `python/tests/test_dropin_offline.py::test_higher_order_functions_check_their_column_arguments_as_pyspark`: for each of the 12 functions, at every column position (including `initialValue` of `aggregate` and `reduce`, and both `array_sort` forms), a list raises `NOT_EXPECTED_TYPE` with the message parameters of PySpark, and a Column and a column name still build a Column whose repr starts with the function name. It fails without the change (`DID NOT RAISE`). - Live, `python/tests/test_dropin_e2e.py::test_higher_order_functions_take_columns_and_reject_lists_as_pyspark`, against a Spark 4.3.0 Connect server: `transform` and `exists` with lists raise, and with array columns they return `[Row(t=[10, 20, 30])]` and `[Row(e=True)]`, as PySpark does. - Offline Python suites: `tests/test_dropin_offline.py`, `tests/test_ml_offline.py`, `tests/test_arrow_handoff.py`. - Live Python suites: `tests/test_arrow_e2e.py`, `tests/test_dropin_e2e.py`, `tests/test_ml_e2e.py`. - Rust (no Rust code changed): `cargo test -p apache-spark-connect --release --lib` (528 passed), `--no-run` and `--features wasm-udf --no-run` (both compile), `cargo fmt --all --check` (clean). `cargo clippy --workspace --all-targets --release` stops with `approx_constant` errors in `crates/spark-connect/tests/e2e_integration.rs` and `e2e_functions.rs` that are not in this change. ### 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]
