HyukjinKwon opened a new pull request, #534:
URL: https://github.com/apache/spark-connect-rust/pull/534
### What changes were proposed in this pull request?
The Column operators and methods of the Python client now take their operand
as PySpark's `_bin_op` does, and raise PySpark's errors for the rest:
- An operand of `+ - * / %`, their reverse forms, `**` (both ways), the
comparisons, `&`, `|`, `between`, `eqNullSafe`, `bitwiseAND`/`OR`/`XOR`,
`contains`, `startswith`, `endswith`, `like`, `rlike` and `ilike` is a Column,
or a literal of the types `_bin_op` takes after `enum_to_value`: None, bool,
int, float, str, date, time, datetime, timedelta or Decimal (`__eq__` takes no
timedelta, as PySpark's `Column.__eq__`). For any other operand, the client
looks up its `_expr`, as PySpark does, so PySpark's error is raised:
`AttributeError: 'list' object has no attribute '_expr'`, or a Row's
`PySparkAttributeError [ATTRIBUTE_NOT_SUPPORTED]`.
- `Column.otherwise`, `Column.when`, `isin`, `getItem` and `__getitem__`
raise `PySparkTypeError [UNSUPPORTED_DATA_TYPE]` for a NumPy array, as
PySpark's `LiteralExpression._from_value` does. `lit` and `functions.when`
still take one, as PySpark's do.
### Why are the changes needed?
The drop-in turned operands that PySpark rejects into literals, or raised a
different error. A probe of 14 operator families against 16 kinds of operand
gave these differences with PySpark 4.3.0:
```python
F.col("a") + [2] # before: +(a, array(2)), which the server
rejects later
F.col("a") == b"x" # before: a binary literal
F.col("a") == np.int64(2) # before: a literal (np.int64 is not an int, so
PySpark rejects it)
F.col("a") + (2,) # before: PySparkTypeError
[UNSUPPORTED_DATA_TYPE] `tuple`
# PySpark 4.3.0, each: AttributeError: '<type>' object has no attribute
'_expr'
F.col("id").isin(np.array([0, 1])) # before: an AnalysisException from the
server
F.when(c, 1).otherwise(np.array([1, 2])) # before: an array literal
# PySpark 4.3.0: PySparkTypeError [UNSUPPORTED_DATA_TYPE] Unsupported
DataType `ndarray`.
```
A program that worked on the drop-in failed on PySpark. After this change,
the probe gives no difference.
### Does this PR introduce _any_ user-facing change?
Yes. These operands are now rejected with PySpark's error, as above. The
operands that PySpark takes, including `np.float64`, which is a float, and Enum
members, build the same expressions as before.
### How was this patch tested?
- Three new offline tests in `python/tests/test_dropin_offline.py`:
`test_column_operators_take_their_operands_as_pyspark` (each rejected kind for
every operator family),
`test_column_operators_take_the_literals_that_pyspark_takes` (each accepted
kind, including the `==`/`!=` timedelta difference), and
`test_column_value_methods_take_no_numpy_array_as_pyspark`. They fail without
this change and pass with it.
- The operator probe (224 cases) and the literal probe match PySpark 4.3.0.
- The offline suites (`test_dropin_offline.py`, `test_ml_offline.py` and
`test_arrow_handoff.py`, 3137 passed), the e2e suites against a Spark 4.3.0
server (`test_dropin_e2e.py`, `test_arrow_e2e.py` and `test_ml_e2e.py`, 291
passed), the Rust library tests, the `--no-run` builds (with and without
`wasm-udf`), `cargo fmt --check`, `scripts/audit_no_stubs.sh` and the ruff
gates.
### 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]