HyukjinKwon opened a new pull request, #772:
URL: https://github.com/apache/spark-connect-rust/pull/772

   ### What changes were proposed in this pull request?
   
   The `pyspark-client` 4.3.0 package ships 22 modules that the drop-in lacked. 
Importing any of them raised `ModuleNotFoundError` here, while it works on 
`pyspark-client`. This PR vendors them verbatim from Apache Spark v4.3.0, at 
the same paths under `python/pyspark`:
   
   | modules | what they are | they import |
   |---|---|---|
   | `pyspark.join`, `rddsampler`, `resultiterable`, `shuffle`, `statcounter` | 
PySpark's RDD helpers | as they are |
   | `pyspark.errors_doc_gen`, `install`, `threaddump`, 
`pyspark.sql.transpile`, `pyspark.sql.connect.local_server` | PySpark's tools; 
the classic `UserDefinedFunction` and the builder of the classic `SparkSession` 
use the last two | as they are |
   | `pyspark.worker`, `daemon`, `worker_message`, 
`pyspark.sql.streaming.python_streaming_source_runner`, 
`pyspark.sql.connect.streaming.worker.{foreach_batch_worker,listener_worker}` | 
the modules that the server runs in Python | as they are |
   | `pyspark.sql.streaming.proto.StateMessage_pb2` (and its `.pyi`) | the 
messages of transformWithState's state API, which protoc generates | where 
`protobuf` is installed |
   | `pyspark.sql.connect.client.retries`, `artifact`, `reattach`, 
`pyspark.sql.connect.proto.base_pb2_grpc` | PySpark's gRPC client | where 
grpcio is installed (`retries` and `reattach` also need grpcio-status and 
googleapis-common-protos) |
   
   - `pyspark-client` requires grpcio; this client does not, and the Rust 
transport does not use these modules. `base_pb2_grpc` builds its stub and 
servicer on the messages of the Rust protobuf runtime's `base_pb2`.
   - Importing them leaves the names that `pyspark.sql.connect.client` exports 
as they are.
   - The packages `pyspark.sql.streaming.proto` and 
`pyspark.sql.connect.streaming.worker` are now upstream's `__init__.py` too. 
One had a placeholder docstring and the other a changed one, so both 
directories are whole vendored dirs.
   
   The files are added to:
   - the drift gate (`scripts/check_vendored_upstream.sh`);
   - the vendored block of `pyproject.toml`, which 
`python/tests/test_ruff_excludes.py` checks;
   - the coverage omit list (`python/.coveragerc`, which 
`scripts/tests/test_coverage_scope.py` checks).
   
   `join.py` is BSD 3-Clause (Douban Inc.), so `LICENSE` and the generated 
`LICENSE-binary` list it with its text, as Apache Spark's own `LICENSE` does. 
`dev/parity/4.3.0-module-audit.md` gets a "Vendored modules" section in place 
of the "Not gaps" entries of these modules, and 
`dev/parity/known-differences.md` no longer says that `client.retries` and 
`client.reattach` are not provided.
   
   ### Why are the changes needed?
   
   The completeness rule of AGENTS.md (section 10) is that every module of the 
`pyspark-client` package is either vendored verbatim or has Rust-backed 
equivalents. These modules had neither, so code and tools that import them 
failed on the drop-in. For example:
   - `from pyspark.sql.connect.client.retries import RetryPolicy`;
   - `from pyspark.resultiterable import ResultIterable`;
   - the vendored classic builder's local-server reuse, 
`pyspark.sql.connect.local_server`;
   - the official tests that import `pyspark.sql.connect.client.artifact` or 
`retries`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes: these modules import, as on `pyspark-client` 4.3.0. `pyspark-client` 
requires Python 3.11; on Python 3.9, which this package also allows, 
`pyspark.worker_message` and `pyspark.sql.transpile` need Python 3.10, and so 
do `pyspark.worker` and the two streaming workers, which import 
`worker_message`.
   
   ### How was this patch tested?
   
   - `bash scripts/check_vendored_upstream.sh`: all 172 paths match v4.3.0.
   - `python python/tests/test_ruff_excludes.py`, `python3 -m unittest discover 
-s scripts/tests`, `scripts/gen_binary_licenses.py --check`, and `ruff check` / 
`ruff format --check` (0.14.0).
   - New `test_vendored_modules_of_pyspark_client_import` in 
`test_dropin_offline.py`, in two subprocesses:
     - with grpcio, grpcio-status, googleapis-common-protos, protobuf, py4j and 
zstandard all blocked: the plain modules import, and none of the blocked 
packages is loaded. The gRPC modules fail at `grpc`, and `StateMessage_pb2` at 
protobuf;
     - with the installed packages:
       - `StateMessage_pb2` imports before `pyspark.sql.connect.proto`, and the 
`spark/connect` files that the Rust runtime adds to protobuf's pool keep their 
bytes;
       - `pyspark.sql.connect.client`'s exports are unchanged, and only its 
three submodule attributes are added;
       - `SparkConnectServiceStub` and the servicer construct on a lazy channel.
   
     It passes in an environment with grpcio and protobuf, and in one with 
neither.
   - Every vendored module has the same `dir()` on both clients.
   - A no-network probe gives byte-identical output on both clients:
     - the kinds of the 12 stub methods;
     - the bytes of the requests of `ArtifactManager._create_requests`;
     - the requests of the reattachable iterator over an in-memory stub.
   - The offline suite of `coverage.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]

Reply via email to