HyukjinKwon opened a new pull request, #890:
URL: https://github.com/apache/spark-connect-rust/pull/890
### What changes were proposed in this pull request?
A sweep compared the docstrings of pyspark-client 4.3.0 and of the drop-in
by their exact text. It covered the modules of `pyspark.sql` (but
`pyspark.sql.functions`) and of `pyspark.errors` that both import, 121 of them:
each module, each public class and function that it defines, and each public
member of such a class, as Python finds it on the class. Of 4978 objects of
PySpark:
| | Same | Differ | Missing in the drop-in |
|---|---|---|---|
| Before, master baca16f0 | 2511 | 1424 | 1043 |
| After, this PR on master 682c3014 | 3468 | 467 | 1043 |
The "after" counts include SPARK-62082 (#889), which made the Connect
functions PySpark's (567 of the difference). The full table, by module, is in
`sweep-types-docstrings.md`; details are in
`jira-SPARK-62085-types-docstrings.txt`. The PR has two commits.
**First commit: the docstrings.**
- **`gen_connect_docstrings.py` generates the docstrings of
`pyspark.sql.types` too.**
- It emits a docstring for each class, and for each public member of each
class, its own or of a base of it in PySpark, as Python finds it on the class.
`IntegerType.fromInternal` refers to the docstring of `DataType.fromInternal`.
- A member of no docstring in PySpark gets none.
- The classes of the connect modules take their own docstrings, and an
alias member takes the docstring of its member: `GroupedData.mean` is that of
`avg`.
- `generated-drift.yml` already checks the generated file.
- **The native types of `types.rs` are built with them.** Each class, and
the abstract ones of its `abstract_type!` macro (whose class name is now a
`tt`, which `connect_doc!` matches), takes its `connect_doc!`. Each method of a
member that PySpark's class has takes its `connect_doc!`, or no docstring where
PySpark's has none. Their doc comments, which were the docstrings, are now
plain comments.
- **The same in the other native classes:**
- `DataSourceRegistration` and `GroupedData.mean` take PySpark's
docstrings;
- `DataFrameWriter`, `DataFrameWriterV2` (in the writer region of
`dataframe.rs`, doc lines only), `StreamingQuery`, `StreamingQueryManager`,
`DataStreamWriter` and `StreamingQueryManager.close` now have no docstring, as
PySpark's.
- **The Python modules have PySpark's module docstrings, or none.** That
covers 27 modules of `pyspark.sql.connect`, the avro and protobuf functions,
`pyspark.sql.tvf_argument` and `pyspark.errors.exceptions`; the drop-in's
former text stays as a comment. The same holds for:
- `UserDefinedType`;
- the `SQLContext` and `HiveContext` of `pyspark.sql.connect.context`;
- `from_avro`, `to_avro`, `from_protobuf` and `to_protobuf`;
- the classes and functions of `pyspark.sql.connect.expressions`, `shell`,
`types` and `udtf` that differed.
- **A golden of PySpark's docstrings.**
`tests/golden/runtime_docstrings.json` holds the digests of PySpark's
docstrings of 111 modules. `scripts/capture_runtime_docstrings_golden.py`
writes it, run with pyspark-client, and `python/tests/_runtime_docstrings.py`
is the sweep that both sides use. The golden leaves out the modules of others'
work, whose docstrings are not all PySpark's yet: the DataFrame, the Column,
the window, the table argument, the session and its client, and the functions.
- **Docs:** `dev/parity/known-differences.md` describes what remains, and
`docs/compatibility.md` says which docstrings are PySpark's.
**Second commit: the spatial types' own methods.** PySpark's `GeographyType`
and `GeometryType` define their own `needConversion` and `fromInternal`
(`types.py:623-635`), with no docstring. The drop-in's native types inherited
those of `DataType`, whose docstrings are now `DataType`'s. Now:
- The native types define both methods, with no docstring, and the methods
call those of `DataType`. So `vars()` and `__doc__` are PySpark's, and the
conversions are as before:
- a dict of `"srid"` and `"bytes"` makes a `Geography` or `Geometry`;
- a dict without either makes None;
- `toInternal` makes the dict back.
- A probe of both clients is identical.
**What remains:**
- **Inherent:**
- the `__init__` of a native class, CPython's slot, keeps CPython's
docstring: 13 types and 15 classes of `pyspark.sql.connect`;
- the 1043 missing names, mostly PySpark Connect's plan and expression
classes (798 and 145), which the drop-in builds in Rust, and the 7 py4j
converters of `pyspark.sql.types` (28 objects).
- **Of other work, listed for their owners:**
| Owner | What still differs |
|---|---|
| A, item 1 | `pyspark.sql.column` and `pyspark.sql.connect.column` (2 and
30); `pyspark.sql.window` and `pyspark.sql.connect.window` (7 and 11);
`pyspark.sql.table_arg` and `pyspark.sql.connect.table_arg` (2 and 7); the
`DataFrameNaFunctions` and `DataFrameStatFunctions` of both DataFrame modules
(15) |
| e3 | the `DataFrame` of both DataFrame modules (about 240);
`pyspark.sql.connect.session` (43); `pyspark.sql.connect.client` and
`client.core` (80) |
| A2, functions | `pyspark.sql.connect.functions` and `builtin` (2 left
after #889) |
### Why are the changes needed?
So that `help()` of the types and of the modules of Spark Connect shows
PySpark's documentation, as with pyspark-client, and so that a test guards each
docstring that is PySpark's.
### Does this PR introduce _any_ user-facing change?
Yes. The `__doc__` of 392 more objects is PySpark's, as with pyspark-client:
- the types;
- the module docstrings;
- the SQLContext of Spark Connect;
- the avro and protobuf functions.
### How was this patch tested?
- **New tests** in `test_dropin_class_modules_offline.py`:
- `test_the_docstrings_of_the_modules_are_pysparks` compares the drop-in's
docstrings with the golden: 2720 objects; the `__init__` slots and the names
that the drop-in does not have are not compared. On master 388 of them differ
(392 with the spatial types); on this branch none.
- `test_the_spatial_types_convert_of_their_own_methods_as_pysparks`
(second commit) checks the members of the classes of the spatial types and
their conversions. It fails on master and on the first commit.
- **The sweep of both clients**, before and after, in
`sweep-types-docstrings.md`.
- **Official suites** against the drop-in (`run_official_tests.py --dropin
--only`), the same on master and on this branch:
| Suite | Passed (skipped) |
|---|---|
| `test_parity_types` | 70 (21) |
| `test_connect_context` | 10 |
| `test_parity_errors` | 7 |
| `test_connect_error` | 12 (1) |
| `test_parity_catalog` | 27 |
| `test_parity_conf` | 5 |
| `test_parity_group` | 8 |
| `test_parity_readwriter` | 22 |
| `test_parity_tvf` | 24 |
| `test_parity_observation` | 13 |
| `test_parity_python_datasource` | 37 (4) |
| `test_parity_udtf` | 387 (21) |
| `test_parity_udf` | 73 (15) |
| `test_parity_listener` | 9 |
The one failure of `test_parity_udf`, on both, is `input_file_name`, as
the server cannot read the local data path.
- **The gates.** The first commit was gated on master baca16f0; after the
second commit, the PR was rebased onto master 682c3014, and all of the gates
below ran again except the official suites, which are of the first commit:
- `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`, `scripts/check_vendored_upstream.sh`;
- ruff 0.14.0, the no-stub audit, the guards and
`test_type_stubs_offline.py` (14 passed, 4 skipped);
- the offline suite of `coverage.yml`: 6799 passed, 77 skipped;
- the coverage step of `coverage.yml`, with its commands and its
`.coveragerc`: 6813 passed, 80 skipped, 93.33% (floor 93.00%). No changed
Python line is uncovered; the total moved with master's #889;
- `test_dropin_e2e.py -k "type or schema or udt or context or error or
catalog or avro or protobuf or stream or udf or udtf"` against a Spark 4.3.0
server: 114 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]