HyukjinKwon opened a new pull request, #827:
URL: https://github.com/apache/spark-connect-rust/pull/827
### What changes were proposed in this pull request?
A follow-up of SPARK-61846 (#768). That PR made
`pyspark.sql.connect.resource` PySpark's file, without its re-exports of
`pyspark.resource`, and made `pyspark.resource` PySpark's module.
**`pyspark.sql.connect.avro`, `pyspark.sql.connect.protobuf` and
`pyspark.sql.connect.streaming` are PySpark 4.3.0's `__init__.py`, verbatim.**
The drop-in's own files re-exported names that PySpark's packages do not have,
each with an `__all__`:
- `from_avro` and `to_avro`;
- `from_protobuf` and `to_protobuf`;
- `StreamingQuery`, `StreamingQueryManager`, `DataStreamReader`,
`DataStreamWriter`, `StreamingQueryListener`, `StatefulProcessor`,
`StatefulProcessorHandle`, `TwsTester` and `StreamingQueryException`.
PySpark's files hold a docstring or the license header only. The functions
and the classes stay in their modules: `pyspark.sql.connect.avro.functions`,
`protobuf.functions`, `streaming.query` and `streaming.readwriter`. Nothing in
the drop-in imported the re-exported names. The three files are now in:
- `VENDORED_FILES` of `scripts/check_vendored_upstream.sh`;
- the vendored block of `pyproject.toml`, which
`python/tests/test_ruff_excludes.py` checks;
- the omit list of `python/.coveragerc`, which
`scripts/tests/test_coverage_scope.py` checks.
**The extension has no resource profile classes of its own any more.**
`crates/pyspark-rs/src/resource.rs` registered `ResourceProfile`,
`ResourceProfileBuilder`, `ExecutorResourceRequests` and `TaskResourceRequests`
in `pyspark._pyspark`. Since SPARK-61846 no module exported them:
- they claimed to be of `pyspark.resource.profile`, whose classes of those
names are others;
- a native `ResourceProfile` did not pickle.
The module and its registration in `lib.rs` are removed. Nothing else used
them: no test, stub or doc. The Rust API, `spark_connect::resource` and
`SparkSession::build_resource_profile`, is unchanged.
**Docs:**
- AGENTS.md classified `resource/profile.py` and `serializers.py` as
Rust-backed shims to keep. Both are PySpark's files in the drift gate, as the
rest of `resource/` and `sql/connect/resource/` are. It now lists them as
vendored, and says that `VENDORED_FILES` lists the vendored files of a
directory of shims, such as most of `errors/` and `sql/session.py`.
- The two rows of the connect `ResourceProfile` in the parity ledger named
`PyResourceProfile` of `resource.rs`. They now name the vendored module and
`SparkSession.client._create_profile`.
### Why are the changes needed?
So that the three packages are PySpark's. Code that imported these names
from them worked on the drop-in and failed on `pyspark-client` 4.3.0, as `from
pyspark.sql.connect.resource import ResourceProfile` did before SPARK-61846.
Also, the extension should have no dead classes that claim another module.
### Does this PR introduce _any_ user-facing change?
Yes, as PySpark 4.3.0:
- `from pyspark.sql.connect.avro import from_avro` raises `ImportError:
cannot import name 'from_avro' from 'pyspark.sql.connect.avro'`, and so do the
other re-exported names. The three packages have no `__all__`. The names stay
importable from their modules.
- `pyspark._pyspark` has no `ResourceProfile`, `ResourceProfileBuilder`,
`ExecutorResourceRequests` or `TaskResourceRequests`. The classes of
`pyspark.resource` are unchanged.
### How was this patch tested?
- New tests in `python/tests/test_dropin_offline.py`, which fail on master
and pass here:
- `test_the_connect_avro_protobuf_and_streaming_packages_are_pysparks`:
the packages have no `__all__` and no names but their submodules, `from
<package> import <name>` raises `ImportError`, and the modules keep the names;
- `test_the_resource_classes_are_pysparks_alone`: the extension has none
of the four classes, and those of `pyspark.resource` are the classes of their
modules.
- Probes of `pyspark-client` 4.3.0 and the drop-in: the namespaces of the
three packages and the `ImportError` are the same.
- `scripts/check_vendored_upstream.sh`, run against the `v4.3.0` tag from a
local clone of apache/spark: 167 paths match, the three new files included.
- The Rust gates:
- `cargo +1.100.0 fmt --all --check`;
- `cargo +1.100.0 clippy -p apache-spark-connect -p
apache-spark-connect-core -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: 12 passed.
- The Python gates:
- ruff 0.14.0 `check` and `format --check`, `test_ruff_excludes.py` (164
vendored paths) and `scripts/audit_no_stubs.sh`;
- `scripts/tests`: 98 passed;
- `gen_type_stubs.py --pyspark-src <v4.3.0>/python --check`;
- `test_type_stubs_offline.py` with mypy 2.4.1: 7 passed;
- the guards of SPARK-61851.
- The offline suite of `coverage.yml`, with upb: 6236 passed and 77 skipped.
Python coverage is 94%. The skips: 68 for "not a public constructor", 7 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: 310 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]