HyukjinKwon opened a new pull request, #815:
URL: https://github.com/apache/spark-connect-rust/pull/815
### What changes were proposed in this pull request?
These are follow-ups of #779 (SPARK-61856), from its review against
pyspark-client 4.3.0. Each was checked on both clients against a Spark 4.3.0
server.
| | pyspark-client 4.3.0 | drop-in before |
|---|---|---|
| `client.cache_artifact(memoryview(b"x"))`, or of an `array.array` | its
SHA-256 hash | `TypeError: 'memoryview' object is not an instance of 'bytes \|
bytearray'` |
| `client.cache_artifact("x")` / `(None)` | `TypeError: Strings must be
encoded before hashing` / `object supporting the buffer API required` | the
transport's `TypeError` |
| `client.register_udf(f, None)`, `register_udtf(cls, 5, "t")` |
`PySparkValueError [UNSUPPORTED_OPERATION] data type None is not supported.` |
`TypeError: expected a DataType or a DDL type string` |
| `client.global_user_context_extensions` | a list attribute of the client,
whose changes its requests carry | a read-only property of a new list each time
|
- **`cache_artifact` and `cache_artifacts`.** PySpark's `ArtifactManager`
hashes each blob with `hashlib` before it sends anything. The drop-in does too,
so it takes any bytes-like object and raises hashlib's `TypeError` for another.
- **`register_udf` and `register_udtf`.** They raise the
`UNSUPPORTED_OPERATION` of `pyspark_types_to_proto_types` for a return type
that is neither a `DataType` nor a DDL string, before the function is pickled,
as PySpark's `PythonUDF.to_plan` and `PythonUDTF.to_plan` do. The other
argument errors of #779's review are PySpark's since SPARK-61911: the tags and
the operation IDs of the interrupts, and the names and the class names of the
registrations.
- **`global_user_context_extensions`.** It is an instance attribute, as
PySpark's, not a member of the class:
- `add_global_user_context_extension` appends `(id, extension)` to it, the
extension itself, of an ID of `global_` and a UUID, generated in Python;
- `remove_user_context_extension` and `clear_user_context_extensions`
rebind it to a new list;
- a change of the list, or a list that it is set to, is what the session
takes for the requests of all its threads;
- its copies and pickles are plain lists.
The core and the Rust API get `set_global_user_context_extensions`, which
replaces them.
**The docs** describe what stays different:
- **The errors that PySpark leaves to grpc.** PySpark raises the errors of
the RPCs of `clone` (and `cloneSession`) and of `copy_from_local_to_fs` (and
`copyFromLocalToFs`) as grpc's `RpcError` (`_InactiveRpcError`). The drop-in,
which has no grpc, converts them to the exceptions of their error classes, as
for its other RPCs, such as `UnknownException` and
`UnsupportedOperationException`. See `docs/compatibility.md` and
`dev/parity/known-differences.md`.
- **The retry policy of a core client** is shared by its clones. So
`set_retry_policy` of a clone changes the policy of the client it was cloned of
too, and a client of a new session has the default one. See the doc comment of
`SparkConnectClient::set_retry_policy` and `known-differences.md`.
### Why are the changes needed?
So that `SparkSession.client` takes PySpark's arguments and raises PySpark's
errors, so that its `global_user_context_extensions` is PySpark's list, and so
that the docs say what stays different.
### Does this PR introduce _any_ user-facing change?
Yes:
- `cache_artifact(s)` take any bytes-like blob and raise hashlib's errors
for others;
- `register_udf` and `register_udtf` raise PySpark's `UNSUPPORTED_OPERATION`
of a return type of another type;
- `global_user_context_extensions` is a list attribute whose changes the
requests carry.
### How was this patch tested?
- **Probes of both clients** against a Spark 4.3.0 server give identical
output:
- 20 argument cases of `cache_artifact(s)`, the registrations and the
interrupts;
- the list attribute's class membership, `vars`, the identity of the
appended extension and of the list, and its rebinding by
`remove_user_context_extension`.
- **New tests:**
- `test_client_raises_the_argument_errors_of_pyspark` in
`test_dropin_offline.py`;
-
`test_global_user_context_extensions_are_a_list_that_the_requests_take_as_pyspark`
in `test_ml_offline.py`, on the mock server: appends, deletions and an
assigned list are what the requests carry;
- `test_client_caches_bytes_like_artifacts_as_pyspark` in
`test_dropin_e2e.py`, which also passes on pyspark-client 4.3.0.
- **Rust tests:**
- `cargo test -p apache-spark-connect-core --release`: 312 passed;
- `-p apache-spark-connect --release --lib`: 772 passed;
- `cargo test -p pyspark-rs --lib`: 12 passed.
- The offline suite of `coverage.yml`: 6200 passed, 77 skipped.
- `test_dropin_e2e.py` against a Spark 4.3.0 server: 306 passed.
- **Lint:**
- `cargo fmt --all --check`;
- `cargo +1.100.0 clippy -p apache-spark-connect-core -p
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`;
- `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p apache-spark-connect
-p apache-spark-connect-core`;
- ruff 0.14.0, `test_ruff_excludes.py`, `scripts/audit_no_stubs.sh`;
- the guards of `coverage.yml` and `build_python_connect.yml`.
### 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]