HyukjinKwon opened a new pull request, #831:
URL: https://github.com/apache/spark-connect-rust/pull/831
### What changes were proposed in this pull request?
A follow-up of #788 (SPARK-61876) and #798 (SPARK-61896), from a round-3
review of the Rust API (`crates/spark-connect`) and of DataFrames against
pyspark-client 4.3.0. Where PySpark and the Python binding do one thing, the
Rust API did another. Each item was probed against a Spark 4.3.0 server.
**Requests**
- **Model deletions.** The deletion of a dropped native ML model is built on
the dropping thread, with its tags and user-context extensions, and sent
reattachable through the hooks, as PySpark's `_delete_ml_cache`
(client/core.py:2539-2577). It was built on a runtime worker, with none of
them. This uses the new doc-hidden
`SparkConnectClient::spawn_execute_plan_reattachable`.
- **Listener registration.** The listener-bus registration carries the
session's tags, as PySpark's `execute_command_as_iterator`.
- **Stars.** `DataFrame::col("*")` is a star, as PySpark's `df["*"]`
(connect/dataframe.py:1900-1910). It was an attribute named `*`, which the
server refused. The doc-hidden `DataFrame::column_reference` keeps `_col`'s
plain reference.
- **reduce.** `functions::reduce` sends `reduce`, as PySpark's
(builtin.py:1697-1707); it sent `aggregate`. `reduce_with_finish` is added. The
HOF golden captures both, and requires a case of each golden, as the other
goldens do.
- **Frame bounds.** A bound of 0 is the current row, and bounds past
PySpark's thresholds are unbounded (connect/expressions.py:1143-1197,
window.py:99-121), so `rangeBetween(0, 0)` over a string order works. A
row-frame offset outside int32 raises `VALUE_NOT_BETWEEN`, as PySpark's.
- **Bucketing.** `bucket_by` of a count of 0 or less sends no bucketing
(plan.py:2155-2157).
- **foreach sinks.** foreach and foreachBatch send only the command and the
Python version (streaming/readwriter.py:642-673), with no `output_type`. This
also applies to the binding.
- **Empty Arrow data.** `create_dataframe_from_arrow` of batches of no rows
and a schema sends the schema alone (connect/session.py:524-528). The server
refused its data.
- **Cross-session subqueries.** WithRelations references are serialized with
the plan ids of their own session. So subqueries and table arguments of a
DataFrame of another session resolve, as PySpark's (plan.py:68-104,
expressions.py:1294, plan.py:176-193). For example,
`s2.range(5).where(col("id").isin(spark.range(2).select("id")))` raised
`Missing relation in WithRelations`, also in the binding.
- **corr.** `corr` sends PySpark's `method`, `pearson` by default, and
refuses others with `VALUE_NOT_ALLOWED`. This changes the Rust signature:
`corr(col1, col2, method: Option<&str>)`.
- **unpersist.** `unpersist(blocking=None)` sends no `blocking`, as PySpark
(client/core.py:1637-1640); it sent `false`. This uses the new `unpersist_opt`.
- **Lateral joins.** `lateral_join` refuses with `UNSUPPORTED_JOIN_TYPE` the
types other than inner, left and cross (plan.py:1280-1313).
**PySpark's client-side errors, at the request** (as `mode()` defers its
error):
- `changes()` with a schema raises `_LEGACY_ERROR_TEMP_1189`;
- `await_termination` and `await_any_termination` of a timeout that is not
positive raise `VALUE_NOT_POSITIVE`, and PySpark's errors of NaN, infinity and
too large a value;
- `create_table_with` of a schema that is not a struct raises
`NOT_EXPECTED_TYPE`;
- `DataStreamReader::name` checks PySpark's regex
(`INVALID_STREAMING_SOURCE_NAME`).
`docs/compatibility.md` lists the Rust API changes, and
`dev/parity/known-differences.md` the model deletion's paragraph.
### Why are the changes needed?
So that the Rust API sends PySpark's requests and raises PySpark's errors,
as the binding does, and cross-session subqueries work.
### Does this PR introduce _any_ user-facing change?
Yes, as above. Two changes to the Rust API:
- `StatFunctions::corr` takes a `method`;
- `LogicalPlan::StatCorr` has a `method` field.
### How was this patch tested?
- **New tests next to the existing ones.**
- Core unit and integration tests of each item.
- Two-session tests of subqueries and table arguments.
- The HOF golden's reduce cases; the 12 existing goldens are unchanged.
Each new test fails with its fix reverted.
- **Probes of both clients:**
- the requests of the model deletion and of the listener registration;
- the foreach payloads;
- the cross-session subqueries (all identical now);
- `corr` and `unpersist(None)`.
The Rust-only items pin PySpark's values in tests: the reduce column
names, `rangeBetween(0, 0)` giving `[1, 5, 5]`, the reprs, the errors, and `[]
struct<x,y>`.
- **Rust.**
- `cargo test -p apache-spark-connect -p apache-spark-connect-core
--release`, and `--features wasm-udf`;
- the live Rust e2e tests (`e2e_columns`, `e2e_dataframe`,
`e2e_functions`, `e2e_coverage`, `e2e_new_methods`, `e2e_session_catalog`,
`e2e_streaming`, `e2e_ops_breadth`, `e2e_integration`, `e2e_ml_object`,
`execute_plan_hook`, `arrow_map_input`, `checkpoint_release`,
`ml_golden_replay`);
- `cargo test -p pyspark-rs --lib`, linked as `rust.yml` links it.
- **Python.**
- The offline suite of `coverage.yml`.
- Live `test_dropin_e2e.py`.
- The type-stub drift check and test, with mypy and pyright.
- **Lint.**
- `cargo fmt --all --check`, `cargo +1.100.0 clippy -p pyspark-rs -p
apache-spark-connect -p apache-spark-connect-core --all-targets -- -D
warnings`, ruff 0.14.0, `audit_no_stubs.sh`, `scripts/tests` and
`gen_fn_dispatch.py --check`;
- `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps`.
### 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]