HyukjinKwon opened a new pull request, #849:
URL: https://github.com/apache/spark-connect-rust/pull/849
### What changes were proposed in this pull request?
From a review of the documented differences of DataFrames against PySpark
4.3.0, and the other session's review of SPARK-61971's GC helpers. Each item
was probed on both clients against a Spark 4.3.0 server, through a recording
proxy.
**1. DataFrames whose plan fails with an AttributeError pickle**, as
PySpark's do: a join on a tuple, or on conditions of a Row. Their unpickle
raises the error, `NOT_ITERABLE` of the schema request, as PySpark's does. The
errors that a plan carries now cover the builtin `AttributeError` and the
PySpark error classes. Columns of such errors pickle too, as in PySpark.
**2. A copy, deep copy or unpickle keeps the schema that it requests**, as
PySpark's `_cached_schema_serialized` (connect/dataframe.py:2024-2050).
- PySpark answers `schema`, `printSchema`, the set operations' merge and the
numeric aggregates of `groupBy` (`_numeric_agg`) from that schema.
- It answers `columns`, `dtypes`, `repr` and `dir` from the cached one.
- The drop-in answered all from the cached schema. So a view replaced
between the DataFrame and its copy gave other results, and the copy's `toArrow`
raised.
- A probe of 225 cases (copies, deep copies, unpickles, copies of copies,
every set operation, `filter`, `alias`, `limit`, `groupBy().sum()`, `toArrow`,
`to()` and the maps) gives the same results and the same requests in each phase
on both clients.
**3. A table argument pickles.**
- `df.asTable()` pickles and cloudpickles its relation, its partitioning and
ordering Columns, and its single partition, and loads through `_of_relation`
and the same calls.
- On a Python worker of the server, it loads as PySpark Connect's own
`TableArg`. The official client loads the drop-in's cloudpickled table
arguments, and a UDTF of them returns the same rows.
- `_subquery_expr` stays a property.
**4. A deep copy into the same session rebuilds its relation** at each
build, through its picklers, so its requests give the no-partition window
warning and the origins of a join's `and` at each build, as PySpark's do. A
pickle, and a copy into another session, carry the built relation as before.
**5. Window frame bounds** that the core holds, any int of a long and the
sentinels, raise `VALUE_NOT_BETWEEN` when the plan is built, as PySpark does,
not at `rowsBetween` or `rangeBetween`. A bound that the core cannot hold,
`True` or an int beyond a long, still raises PySpark's first error at the call.
This is documented.
**6. `Column._expr` and `TableArg._subquery_expr` are reported to Python's
garbage collector**, as SPARK-61971 did for the other holders, so a reference
cycle through a UDF of them is collected, as in PySpark. Their `copy.copy` and
`copy.deepcopy` copy the core Column, as a Column's do, where they raised
`TypeError: cannot pickle '_ColumnExpression' object`.
`docs/compatibility.md` and `dev/parity/known-differences.md` describe these
and the remaining differences:
- a table argument unpickles where the session of its ID is active;
- the `copy.py` call site of the schema requests of a copy.
### Why are the changes needed?
So that copies, pickles and table arguments behave as PySpark's, warnings
and origins are PySpark's, and reference cycles through Column expressions are
collected.
### Does this PR introduce _any_ user-facing change?
Yes, as above. In the Rust API: a doc-hidden
`TableArg::relation_with_levels`.
### How was this patch tested?
- **New and extended tests.**
- `test_dropin_offline.py`:
-
`test_copies_keep_the_schema_that_they_request_apart_from_the_cached_one_as_pyspark`;
- AttributeError joins in the unpickle test;
- deep copies in the window-warning and origin tests;
- the frame-bound tests at the build;
- `_expr` and `_subquery_expr` in the GC tests and the
creation-traversal test.
- `test_table_arg_pickles_as_pyspark` in
`test_dropin_window_tablearg_offline.py`.
- `raise_error` cases in `test_dropin_types_columns_offline.py`.
- Core unit tests in `dataframe.rs` and `table_arg.rs`.
- **Probes of both clients:** the pickles of failing plans (33 and 30
cases), the copy schemas (225 cases), the table-argument pickles at protocols
0-5 and their requests, the deep-copy warnings and origins, the frame bounds
(37 cases), and the GC of the expressions.
- **Rust.** `cargo test -p apache-spark-connect -p apache-spark-connect-core
--release`, and `--features wasm-udf`, and in a debug build; `cargo test -p
pyspark-rs --lib`, linked as `rust.yml` links it.
- **Python.** The offline suite of `coverage.yml` on pandas 2 and 3. Live
`test_dropin_e2e.py`.
- **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -p pyspark-rs
-p apache-spark-connect --all-targets -- -D warnings`, ruff 0.14.0,
`audit_no_stubs.sh` and `scripts/tests`.
### 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]