HyukjinKwon opened a new pull request, #596:
URL: https://github.com/apache/spark-connect-rust/pull/596
### What changes were proposed in this pull request?
A follow-up of #578 (SPARK-61576), from a review of it. The Python client's
`Observation` (`crates/pyspark-rs/src/observation.rs`) did not pickle at
protocols 0 and 1. It had `__getstate__`, `__setstate__`, `__copy__` and
`__deepcopy__`, but no `__reduce__`. Below protocol 2, the default reduce of a
class with a native base fails, so `pickle.dumps(Observation("x"), protocol=0)`
raised `TypeError: cannot pickle 'Observation' object`.
It now has a `__reduce__` that returns `(copyreg.__newobj__, (type(self),),
self.__getstate__())`. That is the tuple that `object.__reduce_ex__` gives at
protocols 2 and up, so the pickles at those protocols do not change, and it
pickles at 0 and 1 too.
- The class reference stays `pyspark.sql.connect.observation.Observation`,
so a worker running plain PySpark unpickles its own class.
- `copy.copy` and `copy.deepcopy` still go through `__copy__` and
`__deepcopy__`.
### Why are the changes needed?
To match PySpark 4.3.0, whose `Observation` is a plain class that pickles at
every protocol.
### Does this PR introduce _any_ user-facing change?
Yes, on unreleased changes: an `Observation` pickles at protocols 0 and 1.
### How was this patch tested?
- `test_an_observation_pickles_at_every_protocol_as_pyspark` in
`python/tests/test_dropin_offline.py`, new. It round-trips an Observation at
protocols 0 to 5, before the observed DataFrame runs (it then observes the
unpickled copy) and after it (`get` is `{"c": 3}`). It pickles an unpickled one
again at each protocol, and checks REUSE_OBSERVATION on the unpickled copy. It
fails at protocol 0 without the change and passes with it. The existing pickle
tests pass: cloudpickle and a worker's unpickle, and the protocol 4
`__reduce_ex__`.
- The state matches official PySpark 4.3.0: `{_error: None, _name: 'o',
_result: None}` for an unused one.
- The offline drop-in and ML suites (1957 and 128 passed), the observation
and pickle tests of `test_dropin_e2e.py` against a Spark 4.3.0 server, `ruff
check`, and `scripts/audit_no_stubs.sh`.
### 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]