HyukjinKwon opened a new pull request, #799:
URL: https://github.com/apache/spark-connect-rust/pull/799
### What changes were proposed in this pull request?
A follow-up of #775 (SPARK-61852), from a round-2 review of the session's
objects against PySpark 4.3.0. Each item was probed on both clients against a
Spark 4.3.0 server.
**1. `spark.catalog` is one object per session.** PySpark's is a
`functools.cached_property` (connect/session.py:871-875). The drop-in made a
new one at each access, so:
- `spark.catalog is spark.catalog` was False;
- attributes set on it were lost;
- `mock.patch.object(spark.catalog, "currentDatabase",
return_value="patched")` did nothing.
It is now kept in the session, as `streams` is. `Catalog(spark)` constructs,
as PySpark's does, and a copy or pickle is a new catalog of the session. conf,
read, readStream, udf, udtf, tvf and dataSource stay new objects at each
access, as in PySpark.
**2. PySpark's public names, and only them.**
- **`DataFrame.column_names`**, a helper of the drop-in, was a public
method. So it hid a column of that name, which PySpark's `__getattr__` gives
(connect/dataframe.py:1871-1892): `df.column_names` is now that Column.
- **No longer public**, as PySpark lacks them:
- `SparkSession.sessionId()` is removed, and `buildResourceProfile()` is
now the private `_build_resource_profile`;
- `StreamingQueryManager.streamListenerEvents()` is now
`_stream_listener_events`;
- a UDTF's `command` and `python_ver` are removed;
- `operation_id` is on `SparkConnectException` only, as in PySpark
(errors/exceptions/connect.py:56-62), not on every error class.
- **New, as PySpark has them:**
- the `writer` of `WhenMatched`, `WhenNotMatched` and
`WhenNotMatchedBySource` (merge.py:123-125, 160-162 and 188-190);
- `TableArg.to_plan` (table_arg.py:105);
- `Column.__getattr__` as a class attribute (column.py:596-605), so
`Column.__getattr__(c, "a")` works.
**3. The repr of a literal of a bytearray** is PySpark's,
`Column<'bytearray(b'xy')'>`, where it was `Column<'b'xy''>`. The core gets a
doc-hidden `LiteralExpression::ByteArray`, which is sent as binary.
**4. Subclassing.** These were not acceptable base types in the drop-in,
where PySpark's are plain classes:
- The connect `Observation` is subclassable. A subclass's `__init__` checks
the name, and a second `__init__` resets it. Copies and pickles keep the
subclass.
- `DataFrameReader` and `DataStreamReader` construct as PySpark's,
`DataFrameReader(spark)`, as PySpark's own test_connect_plan.py does. They are
subclassable, and keep their class in copies and pickles.
- `PythonEvalType` is PySpark's plain class (`pyspark/util.py`).
- The classes that stay neither subclassable nor constructible are listed in
`docs/compatibility.md` and `dev/parity/known-differences.md` ("Subclasses"),
each with a reason. The data types are among them, as their subclassing would
collide with the open #780.
**5. Docs.** These are corrected or added in `docs/compatibility.md`:
- the pickles of Observation subclasses;
- StorageLevel at protocols 0 and 1;
- the type-valued attributes (`elementType`, `keyType`/`valueType`,
`dataType`): the drop-in parses a DDL string, where PySpark keeps the value as
given;
- the subquery repr `<plan N>`;
- `inputFiles()` returning a list.
### Why are the changes needed?
So that the session's objects behave as PySpark's: tests that patch the
catalog work, a column named `column_names` is given, and code that subclasses
the Observation or the readers works.
### Does this PR introduce _any_ user-facing change?
Yes, as above. The removed or renamed names (`sessionId()`,
`buildResourceProfile()`, `streamListenerEvents()`, a UDTF's
`command`/`python_ver`, and `operation_id` of the non-Connect errors) were not
PySpark's.
Remaining differences, documented:
- `DataFrame.__getattr__` is not a class attribute;
- `TableArg.to_plan` is a builtin of no annotations;
- the readers need a session in `__new__`, so PySpark's pickle of a reader
does not load in the drop-in.
### How was this patch tested?
- **New tests in `test_dropin_offline.py`:**
- the public names, `operation_id` and a UDTF's attributes;
- `Column.__getattr__`, the clauses' `writer` and the bytearray reprs;
- the `column_names` column;
- the cached catalog, including a reference cycle through it;
- Observation subclasses, and reader subclasses (parametrized).
Also `TableArg.to_plan` in `test_dropin_window_tablearg_offline.py`. The
tests that used the removed names are updated.
- **Probes of both clients** give no difference for the catalog, its
patches, the names, `to_plan`, the bytearray reprs, the subclasses'
construction, copies and pickles at protocols 0 to 5, and `inputFiles()`. The
other differences are the documented ones.
- **Rust.**
- `cargo test -p apache-spark-connect -p apache-spark-connect-core
--release` (1618 passed);
- `cargo test -p apache-spark-connect --release --features wasm-udf` (1328
passed);
- after the rebase on master, `--lib` (763 passed).
- **Python.**
- The offline suite of `coverage.yml` on pandas 3 (6111 passed).
- After the rebase on master, the touched offline files on pandas 3 (2514
passed).
- Live `test_dropin_e2e.py` and `test_misc_api_e2e.py` (305 passed).
- **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -D warnings`,
ruff 0.14.0, `audit_no_stubs.sh`, `scripts/tests` and
`check_vendored_upstream.sh`.
### 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]