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

   ### What changes were proposed in this pull request?
   
   A follow-up of SPARK-61967 (#827), which vendored the 
`pyspark.sql.connect.avro`, `protobuf` and `streaming` packages verbatim, for 
two packages of the classic import path whose exports were the drop-in's own.
   
   **`pyspark.sql.types.__all__` is PySpark's list, in its order.** It listed 
36 names: PySpark's 32 and `UserDefinedType`, `_drop_metadata`, 
`_parse_datatype_json_string` and `_parse_datatype_json_value`, which `from 
pyspark.sql.types import *` brought in. The four stay names of the module, as 
in PySpark, so `from pyspark.sql.types import UserDefinedType` works as before. 
Nothing in the drop-in star-imports `pyspark.sql.types` but the vendored 
doctests (`sql/session.py`, `pandas/spark/utils.py`), which use PySpark's names 
only.
   
   **`pyspark/sql/streaming/__init__.py` is PySpark 4.3.0's file, verbatim.** 
The drop-in's file had an `__all__` of 17 names. It also exported:
   - `Trigger`, the native class of the drop-in's 
`pyspark.sql.streaming.readwriter`, a name that only the drop-in has 
(`docs/compatibility.md`), which stays there;
   - the read limits of `pyspark.sql.streaming.datasource`: `ReadLimit`, 
`ReadAllAvailable`, `ReadMinRows`, `ReadMaxRows`, `ReadMaxFiles`, 
`ReadMaxBytes` and `SupportsTriggerAvailableNow`.
   
   Nothing in the drop-in imported these from the package: the vendored 
`pyspark/sql/datasource.py` and `datasource_internal.py` import the read limits 
from `pyspark.sql.streaming.datasource`, and the extension imports the modules 
of the package (`query`, `readwriter`, `listener`, `stateful_processor_util`). 
The file is now in:
   - `VENDORED_FILES` of `scripts/check_vendored_upstream.sh`;
   - the vendored block of `pyproject.toml`, which 
`python/tests/test_ruff_excludes.py` checks.
   
   `python/.coveragerc` already omits `*/pyspark/sql/streaming/*`, which 
`scripts/tests/test_coverage_scope.py` checks. AGENTS.md has no list of the 
vendored files; it defers to `VENDORED_FILES`.
   
   **`pyspark.sql.pandas.group_ops` imports `GroupStateTimeout` and 
`StatefulProcessor`, as PySpark's module does.** Without an `__all__`, a star 
import of the package brings in its loaded submodules too. PySpark's `import 
pyspark.sql` loads `pyspark.sql.streaming.state` through `pyspark.sql.group`, 
whose `pyspark.sql.pandas.group_ops` imports `GroupStateTimeout` of it 
(`group_ops.py:25-26`). The drop-in's `group_ops` is a shim of the native 
`PandasCogroupedOps`, which imported neither name, so `state` was missing from 
the package. Its generated stub, `group_ops.pyi`, now re-exports the two names, 
as `scripts/gen_type_stubs.py` does for a name that PySpark's module imports 
and the drop-in's module has.
   
   **Docs:**
   - `dev/parity/4.3.0-module-audit.md` gave `pyspark.sql.streaming.state` as 
an example of a submodule attribute that differs by import order. It now says 
that the drop-in loads it as PySpark does.
   - `dev/parity/4.3.0-introspection-diff.md` said that the `__all__` sweep of 
`pyspark.sql.types` and `pyspark.sql.streaming` was clean. It now notes that 
the sweep looked for missing names only, and that the extra names are gone.
   
   ### Why are the changes needed?
   
   So that the two packages export PySpark's names. Code that star-imported 
them, or imported a read limit or `Trigger` from `pyspark.sql.streaming`, 
worked on the drop-in and failed or differed on `pyspark-client` 4.3.0.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as PySpark 4.3.0:
   - `pyspark.sql.types.__all__` has PySpark's 32 names, and `from 
pyspark.sql.types import *` no longer brings in `UserDefinedType` and the three 
private functions.
   - `from pyspark.sql.streaming import ReadLimit` raises `ImportError: cannot 
import name 'ReadLimit' from 'pyspark.sql.streaming'`, and so do `Trigger` and 
the other read limits. They stay importable from 
`pyspark.sql.streaming.datasource` and `pyspark.sql.streaming.readwriter`.
   - `pyspark.sql.streaming` has no `__all__`. Its star import brings in the 9 
classes and the 10 loaded submodules, `state` among them.
   
   ### How was this patch tested?
   
   - New tests in `python/tests/test_dropin_offline.py`, which fail on master 
and pass here:
     - `test_types_all_and_its_star_import_are_pysparks`: `__all__` and the 
star import are PySpark's 32 names in its order, and the four other names are 
still importable. It replaces `test_types_all_exports_spatial_and_variant`, 
which checked five names only.
     - `test_the_streaming_package_is_pysparks`: in a new process, the package 
has no `__all__`, and its names and its star import are those of 
`pyspark-client` 4.3.0's. The classes are those of their modules. `from 
pyspark.sql.streaming import <name>` raises PySpark's `ImportError` for 
`Trigger` and the 7 read limits, which their modules keep. Without the 
`group_ops` change it fails on the missing `state`.
   - Probes of `pyspark-client` 4.3.0 and the drop-in: `__all__`, the star 
imports and the `ImportError`s are the same. The only differences left are 
documented in `docs/compatibility.md`: `Trigger` of 
`pyspark.sql.streaming.readwriter`, and the readers, writers and queries, which 
are PySpark Connect's classes of `pyspark.sql.connect.streaming` under the 
classic names.
   - `scripts/check_vendored_upstream.sh`, run against the `v4.3.0` tag from a 
local clone of apache/spark: 168 paths match, the new file included.
   - The Rust gates:
     - `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 -p apache-spark-connect 
-p apache-spark-connect-core`;
     - `cargo test -p pyspark-rs --lib` as `rust.yml` runs it: 13 passed.
   - The Python gates:
     - ruff 0.14.0 `check` and `format --check`, `test_ruff_excludes.py` and 
`scripts/audit_no_stubs.sh`;
     - `scripts/tests`: 98 passed;
     - `gen_type_stubs.py --pyspark-src <v4.3.0>/python --check` and 
`gen_fn_dispatch.py --check`;
     - `test_type_stubs_offline.py` with mypy: 7 passed, 2 skipped (pyright is 
not installed here);
     - the guards of SPARK-61851.
   - The offline suite of `coverage.yml`: 6336 passed and 77 skipped. The 
skips: 68 for "not a public constructor", 8 that need `SPARK_REMOTE`, and 
`test_type_stubs_offline.py`, which needs mypy and ran above.
   - `test_dropin_e2e.py` against a Spark 4.3.0 server: 319 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]

Reply via email to