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

   ### What changes were proposed in this pull request?
   
   Two follow-ups of SPARK-62023 (#863), each matching pyspark-client 4.3.0. 
Details are in `jira-SPARK-62061-client-leftovers.txt`.
   
   **1. A path of `addArtifacts` that is not a str.** PySpark's client reads, 
checks and uploads its paths one after the other 
(`connect/client/core.py:2461-2470`). Its `ArtifactManager._parse_artifacts` 
parses each path with `urlparse` (`artifact.py:184-203`), after 
`SparkSession.addArtifacts` has checked its flags. The drop-in took the paths 
as a list of str, so any other object raised PyO3's `TypeError`. That happened 
before the flags were checked and before any path was uploaded. Now:
   - the binding reads each path of `addArtifacts`, `addArtifact` and 
`client.add_artifacts` as PySpark's `ArtifactManager` does:
     - a str is taken as it is;
     - a Windows absolute path of another object becomes the file URI that 
`PureWindowsPath` and `Path.resolve` make of it;
     - any other object raises the error of `urlparse` itself, such as the 
`AttributeError` of a `pathlib.Path` or an int, or `UNSUPPORTED_OPERATION` of a 
scheme of bytes, for bytes or a falsy object;
   - each path is uploaded before the next is read.
   
   **2. The names of `pyspark.sql.connect.client`.** PySpark's package is the 
`import *` of its core plus `getLogLevel`, with no `__all__`. The drop-in's 
package is the module of its client. Now:
   - `AnalyzeResult`, `ConfigResult` and `PlanObservedMetrics` are defined in 
`pyspark.sql.connect.client.core`, as PySpark's are, and not in the package. 
The package imports them under private names.
   - The core module also has the metrics classes of PySpark's core.
   - The package's `__all__` gives what PySpark's `import *` of it gives: the 
four classes, `core` and `getLogLevel`. The gRPC modules are the exception: 
`artifact` and `reattach` are replaced by the transport, and `retries` imports 
grpc, so it is imported only when read.
   - The package sets the four classes in its core once it has defined them. 
The binding reads `PlanObservedMetrics` there.
   - The rest of the package's namespace is the module of the client until 
`SparkConnectClient` moves into `client/core.py`, which a later change does.
   
   **Also checked, with no change needed.** Both clients behave the same on 
master for:
   - a name that is not a str given to `registerJavaFunction`, 
`registerJavaUDAF`, `udtf.register` and `udf.register`: protobuf's `TypeError` 
(SPARK-61911, SPARK-62023);
   - the return-type errors of a UDF that is not Arrow-optimized, which are 
raised at the first request, not at the call (#837).
   
   `docs/compatibility.md` now notes one consequence of the native singleton 
types. An error that names the type of such a class, as the `NOT_EXPECTED_TYPE` 
of `udf(f, IntegerType)`, names `type`, where PySpark's names 
`DataTypeSingleton`.
   
   ### Why are the changes needed?
   
   So that the paths of `addArtifacts` and the names of 
`pyspark.sql.connect.client` are PySpark Connect's. A program that passes a 
`pathlib.Path` gets PySpark's error, in PySpark's order, after the paths before 
it are uploaded. A program that imports from the package gets PySpark's names, 
and the result classes only from `core`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as pyspark-client 4.3.0:
   - `spark.addArtifacts(pathlib.Path(...))` raises `AttributeError: 
'PosixPath' object has no attribute 'decode'`.
   - Bytes, `None` and `0` raise `UNSUPPORTED_OPERATION` of `b'' scheme`.
   - The flags are checked first, and the paths before a bad one are uploaded.
   - `from pyspark.sql.connect.client import AnalyzeResult` raises 
`ImportError`.
   - `from pyspark.sql.connect.client import *` gives `getLogLevel` and `core` 
too.
   
   ### How was this patch tested?
   
   - New and changed tests in `test_dropin_offline.py`, both of which fail on 
master:
     - `test_add_artifacts_reads_a_path_that_is_not_a_str_as_pyspark`, on the 
mock server, which now records the first request of each AddArtifacts;
     - `test_the_classes_of_the_client_are_of_its_core_module_as_pyspark`.
   - Probes of both clients against a Spark 4.3.0 server:
     - `p12_artifact_paths.py`: identical, 15 of 15 lines.
     - `p13_client_names.py`: the result classes, `import *`, core's names and 
`getLogLevel` are identical. The rest of the package's namespace and its 
`__all__` differ, as described above.
   - The official `test_client`, `test_artifact`, `test_parity_observation`, 
`test_connect_session` and `test_connect_clone_session` were run against the 
drop-in (`run_official_tests.py --dropin --only`). The results are the same on 
master and on this branch.
   - The 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` of the four crates 
`--features apache-spark-connect/wasm-udf`;
     - `cargo test -p pyspark-rs --lib`: 15 passed;
     - ruff 0.14.0, the stub and dispatch generators, the guards and 
`test_type_stubs_offline.py` (13 passed, 3 skipped);
     - the offline suite of `coverage.yml`: 6495 passed, 77 skipped;
     - the coverage step of `coverage.yml`, with its commands and its 
`.coveragerc`: 93.43% (floor 93.00%), with no new line of the change uncovered;
     - `test_dropin_e2e.py` against a Spark 4.3.0 server: 333 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