HyukjinKwon opened a new pull request, #768:
URL: https://github.com/apache/spark-connect-rust/pull/768
### What changes were proposed in this pull request?
This closes five small gaps of the drop-in against `pyspark-client` 4.3.0.
Each was checked on both clients.
1. **`from pyspark import is_remote_only`** now works. Upstream's
`pyspark/__init__.py` imports it, with `sys`. The drop-in raised `ImportError`,
which fails the collection of the official pandas-on-Spark tests
`frame/test_parity_take.py` and `test_parity_take_adv.py`.
2. **`SpecialLengths.START_OF_INIT_MESSAGE` (`-8`)**.
`pyspark/serializers.py` was upstream's file except for three lines: this
constant, `import codecs`, and one `decode` call. The vendored
`pyspark.messages.socket.spark_socket_message_receiver` reads the constant, so
its `get_init_message()` raised `AttributeError`. The file is now upstream's
verbatim.
3. **The two `ResourceProfile` classes are PySpark's.** Before,
`pyspark.sql.connect.resource.profile.ResourceProfile` was the classic class,
and both had the drop-in's signature `(_exec_req=None, _task_req=None)`.
- `pyspark.resource.ResourceProfile` now takes
`(_java_resource_profile=None, _exec_req=None, _task_req=None)`.
- `pyspark.sql.connect.resource.profile.ResourceProfile` takes
`(exec_req=None, task_req=None)` and creates the profile on the server.
- Both modules, and `pyspark.sql.connect.resource`, are now upstream's
files verbatim. The connect class sends its `spark.connect.ResourceProfile`
through `SparkSession.client._create_profile`, which this PR adds as PySpark's:
a `CreateResourceProfileCommand` over the Rust transport, returning the
server's profile ID.
- `pyspark.sql.connect.resource` no longer re-exports the classes of
`pyspark.resource`, as PySpark's package has none.
4. **The names that the official doctests read from module namespaces.**
Each connect module's `_test()` takes a module's namespace as the doctests'
globals, so the examples need these names there:
- `Row`, `StructType` and `StorageLevel` in `pyspark.sql.dataframe`;
- `StorageLevel` in `pyspark.sql.catalog` and
`pyspark.sql.connect.catalog`;
- `sys` in `pyspark.sql.connect.functions.builtin`.
They are imported as upstream's modules import them.
5. **`import pyspark.sql.connect.streaming.readwriter`** now also loads
`pyspark.sql.connect.readwriter`, as upstream's module does. That module's
`_test()` reads `pyspark.sql.connect.readwriter.__dict__`.
The seven verbatim files are added to `VENDORED_FILES` of
`scripts/check_vendored_upstream.sh`, and to the vendored block of
`pyproject.toml` that `python/tests/test_ruff_excludes.py` checks. Three of
them were already byte-identical but not in the gate.
### Why are the changes needed?
These names and signatures are part of `pyspark-client`'s API. Code written
against PySpark failed on the drop-in:
- `from pyspark import is_remote_only` raised `ImportError`;
- `ResourceProfile(exec_req=...)` raised `TypeError`;
- `SparkSocketMessageReceiver.get_init_message()` raised `AttributeError`.
The official doctests of the Connect modules (18 goal modules of
`dev/sparktestsupport/modules.py`, 876 DocTests) also failed on the drop-in: 8
of them with `NameError`, and the stream reader's whole `_test()` with
`AttributeError`.
### Does this PR introduce _any_ user-facing change?
Yes, as PySpark 4.3.0 behaves:
- `from pyspark import is_remote_only` works.
- `pyspark.serializers.SpecialLengths.START_OF_INIT_MESSAGE` is `-8`.
- `pyspark.sql.connect.resource.profile.ResourceProfile` is PySpark
Connect's class: `ResourceProfile(exec_req=None, task_req=None)` creates the
profile on the server of the active session when it is constructed. Before, it
was `pyspark.resource.ResourceProfile`.
- `pyspark.resource.ResourceProfile` takes `_java_resource_profile` first.
- `from pyspark.sql.connect.resource import ResourceProfile`, which PySpark
doesn't have, now raises `ImportError`.
### How was this patch tested?
- New tests in `python/tests/test_dropin_offline.py`:
- `test_connect_resource_profile_module_offline` checks both classes and
signatures, and the `CreateResourceProfileCommand` that `id` sends, against the
mock server.
- `test_module_namespaces_of_the_official_doctests_as_pyspark` checks the
names, and that a fresh interpreter's import of the stream reader's module
loads `pyspark.sql.connect.readwriter`.
- `test_special_lengths_of_the_messages_of_spark_as_pyspark` drives the
vendored `SparkSocketMessageReceiver`.
- The official doctests of the 18 Spark Connect doctest goals, collected on
the official client and replayed on the drop-in against fresh Spark 4.3.0
servers. Before: 8 of the 876 DocTests failed, and the stream reader's 27 did
not run. After: 875 of 876 pass. The one left is
`StreamingQuery.processAllAvailable`'s `<built-in method ...>` repr, a limit of
PyO3's native methods.
- Against a Spark 4.3.0 server, both clients give the same results:
- the profile ids of both `ResourceProfile` classes come from the server;
- the connect class raises the same `RuntimeError` without a session;
- the names and signatures match.
- `scripts/check_vendored_upstream.sh`,
`python/tests/test_ruff_excludes.py`, and `ruff check` / `ruff format --check`
with ruff 0.14.0, as CI pins it.
- The offline suite of `coverage.yml` (25 files).
### 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]