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

   ### What changes were proposed in this pull request?
   
   [SPARK-61493](https://issues.apache.org/jira/browse/SPARK-61493): follow-ups 
of a post-hoc review of SPARK-61413 (#519) and SPARK-61410 (#517), checked 
against PySpark 4.3.0.
   
   - **`prefetchPartitions` of `DataFrame.toLocalIterator`** 
(`crates/pyspark-rs/src/dataframe.rs`): any value is taken, by position or by 
name, and ignored, as PySpark Connect's `toLocalIterator(self, 
prefetchPartitions: bool = False)` ignores it. The signature still shows the 
default `False`.
   - **The code name of the generator** 
(`python/pyspark/sql/connect/dataframe.py`): the generator that 
`toLocalIterator` returns has the code name `toLocalIterator`, and the 
qualified name `DataFrame.toLocalIterator` on Python 3.11 and later, as 
PySpark's. Only `__name__` and `__qualname__` were set before.
   - **The session IDs of artifact responses** 
(`crates/spark-connect-core/src/client.rs`): `cache_artifacts`, 
`upload_artifact` and `artifact_status` no longer check the session IDs of the 
`ArtifactStatus` and `AddArtifacts` responses. PySpark's `ArtifactManager` does 
not check them, and its requests, like ours, carry no observed server-side 
session ID.
   
   ### Why are the changes needed?
   
   - **`toLocalIterator` raised for a non-bool value.** 
`df.toLocalIterator(1)`, `toLocalIterator(None)` and 
`toLocalIterator(prefetchPartitions="x")` raised a PyO3 `TypeError` at the 
call. PySpark returns the rows.
   - **The generator had another code name.** Its code name was `_local_rows`, 
which `gi_code`, tracebacks and `inspect` show. A traceback through the 
generator now shows `toLocalIterator`, as PySpark's does.
   - **Artifact calls closed the client after a server restart.** When 
`spark.addArtifacts(...)`, or a cache of artifacts, was the first call after a 
server restart, ours raised an assertion error and closed the client. PySpark's 
call returns, and the next call of the client raises. With this change, ours 
does the same: the next call raises and closes the client, as SPARK-61410 made 
it do.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as above: `toLocalIterator` takes any `prefetchPartitions`, its 
generator has PySpark's code name, and artifact calls after a server restart 
return as PySpark's do.
   
   ### How was this patch tested?
   
   - Offline (`python/tests/test_dropin_offline.py`):
     - `test_local_iterators_take_any_prefetch_partitions_as_pyspark`, placed 
before 
`test_is_streaming_is_empty_and_input_files_are_asked_once_per_dataframe_as_pyspark`.
 With `True`, `False`, `1`, `0`, `None`, `"x"` and `[1]`, by position and by 
name, it checks the rows and that the plan is the default's. It also checks the 
signature's default `False`, and that two arguments raise a `TypeError`.
     - `test_to_local_iterator_is_a_generator_as_pyspark` also checks 
`gi_code.co_name`, `co_qualname`, and the name of the traceback frame of a 
`throw()` into the started generator.
   - Rust (`crates/spark-connect-core/tests/server_session.rs`): 
`artifact_responses_of_a_restarted_server_are_not_checked_as_pyspark`. After 
the fake server's session changes, `artifact_status` and `cache_artifacts` 
return, the client stays open, and the next `config` call raises the assertion 
error and closes it.
   - Live, against a local Spark 4.3.0 server, with the server-side session ID 
that the client observed changed under it: `spark.addArtifacts(path, 
pyfile=True)` returns, then the next call raises `NO_ACTIVE_SESSION` and 
`is_stopped` is True, as with PySpark 4.3.0. Before, `addArtifacts` raised 
`PySparkAssertionError` and closed the session. `collect` and `toLocalIterator` 
raise `NO_ACTIVE_SESSION` at once, as before and as PySpark does.
   - Each new check fails without its change:
     - the prefetch test with `TypeError: argument 'prefetchPartitions': 'int' 
object is not an instance of 'bool'`;
     - the generator test with `'_local_rows' == 'toLocalIterator'`;
     - the Rust test at `artifact_status`, which raised.
   - Checks:
     - the lib tests of both crates: 808 passed, and 1 failed, 
`test_interrupt_all_request_structure`, unrelated to this change. That test 
raced another one over `SPARK_CONNECT_AUTHENTICATE_TOKEN`, which a separate PR 
fixes;
     - the build of all tests, also with `wasm-udf` and `datafusion,polars`, 
without warnings;
     - `cargo fmt --all --check`, and clippy with no diagnostics on the changed 
lines;
     - `ruff check` and `ruff format --check`;
     - a full trial on master before the merge.
   
   ### 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