HyukjinKwon opened a new pull request, #419: URL: https://github.com/apache/spark-connect-rust/pull/419
### What changes were proposed in this pull request? [SPARK-61237](https://issues.apache.org/jira/browse/SPARK-61237): Release the relation of a checkpointed DataFrame on the server when its last DataFrame is dropped, as PySpark does. - `checkpoint()` and `localCheckpoint()` (and their `_with` variants) now attach a reference to the checkpoint's `CachedRemoteRelation` plan. The plans derived from it (`select`, `filter`, `join`, ...) keep the reference alive through their inputs. When the last such plan is dropped, the reference sends `RemoveCachedRemoteRelationCommand` for the relation id, without waiting for the server. Its errors are ignored, and nothing is sent when the session is stopped or its client is closed. - `LogicalPlan::CachedRemoteRelation` gets an `owner: Option<RelationOwner>` field, as `LogicalPlan::Raw` and the ML plans have. `plan::cached_remote_relation(id)` keeps its signature and has no owner. This is a change to a public enum variant: the workspace callers (`plan.rs`, `dataframe.rs`) are updated, and no examples or other crates match on it. - Official PySpark 4.3.0 does the same in `CachedRemoteRelation.__del__` (`sql/connect/plan.py`). Checked on the same server: after `del` of a `localCheckpoint()` DataFrame and of its derived DataFrame, and `gc.collect()`, reading the relation id gives `CONNECT_INVALID_PLAN.DATAFRAME_NOT_FOUND`, and the derived DataFrame counts 7 rows while the checkpoint is gone. The drop-in now gives the same results. - The other places that build a CachedRemoteRelation (`cached_remote_relation(id)`, and the `foreachBatch` worker's `_create_remote_dataframe` in PySpark) do not create a checkpoint, so they keep no owner. The Rust client has no foreachBatch worker path. ### Why are the changes needed? A checkpointed relation stayed on the server, with its data, until the session ended, whatever happened to its DataFrames. A loop such as `for i in range(n): df = df.localCheckpoint()` grew the server's state by one relation per iteration. Official PySpark releases the relation when the DataFrame is garbage-collected, so the behavior differed from PySpark. ### Does this PR introduce _any_ user-facing change? Yes. A checkpointed relation is removed on the server when its last DataFrame is dropped, as in PySpark. Derived DataFrames keep working while the checkpoint is alive. The Rust `LogicalPlan::CachedRemoteRelation` variant has a new `owner` field (see above). ### How was this patch tested? - Rust e2e, `crates/spark-connect/tests/e2e_dataframe.rs`, before `subqueries_return_the_rows_of_pyspark`: - `a_dropped_checkpoint_releases_its_relation_on_the_server`: after the `local_checkpoint()` DataFrame is dropped, its relation (taken with `to_relation()`) is polled until reading it fails with `CONNECT_INVALID_PLAN.DATAFRAME_NOT_FOUND` (60 s bound). Without the fix the relation stays readable and the test fails. Official PySpark 4.3.0 gives the same result for the same case. - `a_checkpoint_stays_while_a_dataframe_derived_from_it_is_alive`: a `filter` over the checkpoint still counts 3 after the checkpoint is dropped, the relation is still readable, and it is released once the derived DataFrame is dropped too. Official PySpark 4.3.0 gives the same results. - `checkpoint()` (reliable) is not covered: the test server has no checkpoint directory, and the server rejects it with "Checkpoint directory has not been set in the SparkContext". - Python e2e, `python/tests/test_dropin_e2e.py`, before `test_to_pandas_converts_the_columns_as_pyspark`: `test_a_derived_dataframe_of_a_local_checkpoint_outlives_the_checkpoint_as_pyspark` checks that a derived DataFrame of `localCheckpoint()` still counts and collects after `del` of the checkpoint and `gc.collect()`. This is a guard against releasing too early, so it passes without the fix too; the release itself is checked by the Rust tests above and by a manual probe of the drop-in (derived count 7, then `DATAFRAME_NOT_FOUND` after both are dropped, the same as official). - The offline test `test_checkpoints_send_their_eager_and_storage_level_as_pyspark` (`python/tests/test_dropin_offline.py`) now reads the last `CheckpointCommand` among the requests, since a dropped checkpoint sends its removal in the background too, and checks that its six dropped checkpoints each send `RemoveCachedRemoteRelationCommand` for their relation (deterministic, against the mock server). - The live Rust tests `e2e_dataframe` (6 passed), `e2e_new_methods` (7 passed) and `e2e_coverage` (25 passed) against a local Spark 4.3.0 server. - The lib tests of both crates (664 passed), the build of all tests, also with `wasm-udf`, the offline Python suites (2819 passed, 8 skipped), and the live drop-in and Arrow suites (234 passed) and live cases (13 passed) against a local Spark 4.3.0 server. Clippy reports no diagnostics in the changed lines. ### 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]
