HyukjinKwon opened a new pull request, #884:
URL: https://github.com/apache/spark-connect-rust/pull/884
### What changes were proposed in this pull request?
PySpark Connect's modules give the methods of their classes the docstrings
of PySpark's classic classes, as in `register.__doc__ =
PySparkUDFRegistration.register.__doc__` (connect/udf.py) and `format.__doc__ =
PySparkDataStreamReader.format.__doc__` (connect/streaming/readwriter.py).
There are 49 of them in the modules that SPARK-62071 moved code into:
| Class | Members |
|---|---|
| `UDFRegistration` | 3: `register`, `registerJavaFunction`,
`registerJavaUDAF` |
| `UDTFRegistration` | 1: `register` |
| `StreamingQuery` | 12 |
| `StreamingQueryManager` | 6 |
| `DataStreamReader` | 14, and the class |
| `DataStreamWriter` | 12 |
The drop-in's members had docstrings of their own, or none. Details are in
`jira-SPARK-62078-registration-docstrings.txt`. Now:
- **The registrations** (Python classes of `pyspark.sql.connect.udf` and
`pyspark.sql.connect.udtf`) assign the docstrings of the classic registrations
of `pyspark.sql.udf` and `pyspark.sql.udtf`, as PySpark Connect's do.
SPARK-62071 vendored those classic modules, so they are there to copy from. The
modules import the classic classes under private names, as they already import
PySpark's classic `UserDefinedFunction`, so the stubs need no new name.
- **The streaming classes are native**, so their docstrings are those of the
`#[doc]` attributes that the extension is built with:
- A new generator, `scripts/gen_connect_docstrings.py`, writes
`crates/pyspark-rs/src/connect_docs_generated.rs` from PySpark's source at the
tracked tag. It reuses the `Docs` of `scripts/gen_type_stubs.py`, which works
out PySpark's docstrings at run time, the `__doc__` assignments included.
- The generated `connect_doc!` gives the docstring of each object that
PySpark Connect's streaming modules assign one.
- Each method, getter and the `DataStreamReader` class in `streaming.rs`
takes it (`#[doc = connect_doc!(DataStreamReader.format)]`). Their former doc
comments, which were the docstrings, are now plain comments.
- **Checks:**
- `.github/workflows/generated-drift.yml` runs `gen_connect_docstrings.py
--check`, as it runs the check of the type stubs;
- the no-stub audit (`scripts/audit_no_stubs.sh`) skips the generated
file. Its words are PySpark's, such as the "which for now can be 'parquet'" of
`DataStreamWriter.format`.
- **Docs:** `docs/compatibility.md` says which docstrings are PySpark's.
### Why are the changes needed?
So that `help(spark.udf.register)`, `help(spark.readStream.format)` and the
documentation tools show PySpark's documentation of these methods, as with
pyspark-client.
### Does this PR introduce _any_ user-facing change?
Yes. The `__doc__` of these 49 members is PySpark Connect's. For example:
| | pyspark-client and this PR | before |
|---|---|---|
| `UDFRegistration.register` | 4536 characters | 789 characters of the
drop-in's own |
| `DataStreamReader.format` | 1161 characters | 97 |
| `StreamingQueryManager.active` | 793 characters | None |
### How was this patch tested?
- **New test**, which fails on master for all 49 members:
`test_the_connect_classes_have_the_docstrings_that_pyspark_connect_copies` in
`test_dropin_class_modules_offline.py`. It compares the `__doc__` of each
member with that of PySpark's classic class, vendored as it is.
- **Probe of both clients:** the SHA-256 of the 49 docstrings matches
between pyspark-client and this branch; all 49 differ on master.
- **Official suites** against the drop-in (`run_official_tests.py --dropin
--only`), the same on master and on this branch:
| Suite | Passed | Failed |
|---|---|---|
| `test_parity_udf` | 73 | 1 |
| `test_parity_udtf` | 387 | 0 |
| `test_parity_streaming` | 18 | 12 |
| `test_parity_foreach` | 10 | 0 |
| `test_parity_foreach_batch` | 6 | 17 |
| `test_parity_listener` | 9 | 0 |
The same 30 tests fail on both. They are environmental: `input_file_name`,
and `PATH_NOT_FOUND` of `python/test_support/sql/streaming`, which the server
does not have.
- **The gates**, on master 6e3a3fc2:
- `cargo fmt --all --check`;
- `cargo +1.100.0 clippy -p apache-spark-connect-core -p
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`;
- `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps` of the four crates,
also `--features apache-spark-connect/wasm-udf`;
- `cargo test -p pyspark-rs --lib`: 15 passed;
- `gen_connect_docstrings.py --check`, `gen_type_stubs.py --check`,
`gen_fn_dispatch.py --check`;
- ruff 0.14.0, the no-stub audit, the guards and
`test_type_stubs_offline.py` (13 passed, 3 skipped);
- the offline suite of `coverage.yml`: 6608 passed, 77 skipped;
- the coverage step of `coverage.yml`, with its commands and its
`.coveragerc`: 6621 passed, 79 skipped, 93.43% (floor 93.00%);
- `test_dropin_e2e.py -k "stream or udf or udtf or foreach or listener"`
against a Spark 4.3.0 server: 47 passed.
### 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]