HyukjinKwon opened a new pull request, #610: URL: https://github.com/apache/spark-connect-rust/pull/610
### What changes were proposed in this pull request? A follow-up of SPARK-61537 (43158969, the Observations of a deep copy), from a post-merge review. In PySpark 4.3.0, `copy.copy`, `copy.deepcopy` and pickling of a Connect DataFrame all go through `DataFrame.__reduce__`. `copy._reconstruct` deep-copies the plan and the session with the memo of the whole `deepcopy` call, and restores the state (`_support_repr_html`, `_cached_schema`). The drop-in's `__copy__`/`__deepcopy__` from SPARK-61537 differed from that in several ways: - `copy.deepcopy` ignored the memo. A deep copy of a DataFrame and its Observation in one call, such as `copy.deepcopy((df, o))`, a list or an object holding both, gave the copied DataFrame a hidden copy of the Observation, so the user's copied Observation never got the metrics; PySpark's does. The plan's Observations are now copied with `copy.deepcopy(py_obs, memo)`, through a weak handle from each Observation's state to its Python object. Memo identity then holds: either order, several DataFrames in one call, a caller's or pre-seeded memo, deep copies of deep copies, and cycles. - The session is deep-copied with the memo too, as `_reconstruct` does, so a deep copy on a thread without an active session raises `NO_ACTIVE_SESSION`, as PySpark's. Before, it copied. - `copy.copy` shared the original's `executionInfo`, which was a regression: the copy showed the original's last execution and overwrote it. A copy now starts with its own, as PySpark's starts at `None`. - A deep copy, and an unpickle, dropped `_support_repr_html`, so with eager evaluation on, `repr` of a copy printed the table where PySpark prints `DataFrame[id: bigint]`. - An unpickled DataFrame shared the Observations of the live plan with its plan ID. Unpickling a deep copy therefore set the original's Observation, the bug that SPARK-61537 fixed, reached by another route. It now gets copies, as PySpark's unpickled plan has. `docs/compatibility.md` also notes a PyO3 limit: an Observation that PySpark pickled at protocol 0 or 1 does not load in this client, since its class has a native base. Protocols 2 to 5 are byte-identical both ways. ### Why are the changes needed? To match PySpark 4.3.0. The review's probes (`df_deep.py`, `df_ei.py`, `unpickle_obs.py`, `df_copy2.py`) and new probes of threads, memos and sessions now give the same results on official pyspark-client 4.3.0 and on this client, in every case. The one exception, pickling a `(DataFrame, Observation)` tuple, needs a redesign of the Observation pickle and is left as a known difference. ### Does this PR introduce _any_ user-facing change? Yes, in the Python client. The copies, deep copies and unpickles of a DataFrame keep, share or copy its Observations, its execution info and its HTML repr state as PySpark's do. A deep copy without an active session raises `NO_ACTIVE_SESSION`. ### How was this patch tested? - 5 new offline tests and 1 e2e test. They fail without the change, each on its own finding. - New and updated Rust tests. - The whole `test_dropin_offline.py` (1967 passed, 8 skipped), and the related e2e tests against a Spark 4.3.0 server. - `cargo test -p apache-spark-connect --release --lib` (676 passed), the build of all tests, `cargo fmt --all --check` and ruff. ### 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]
