HyukjinKwon opened a new pull request, #242: URL: https://github.com/apache/spark-connect-rust/pull/242
### What changes were proposed in this pull request? [SPARK-61013](https://issues.apache.org/jira/browse/SPARK-61013): the `Observation`s of `df.observe` now receive their metrics, as in PySpark. After `df.observe(o, count(lit(1)).alias("c")).collect()`, `o.get` is `{'c': 3}`, as in PySpark. The same holds for `count()`, `toPandas()`, `show()`, `toArrow()`, `toLocalIterator()` and writes, of the DataFrame or of a DataFrame of it. The server reports the metrics of each `CollectMetrics` relation by its plan ID. So two Observations of the same name on two DataFrames each receive their own. `get` raises the error of collecting the metrics, which the server reports in its `ObservedMetrics`, as PySpark's `convert_observation_errors` makes it. The client also checks the arguments as PySpark does: - An `Observation` is used once (`REUSE_OBSERVATION`). - `get` raises `NO_OBSERVE_BEFORE_GET` before it is used, and returns `{}` until an action runs. - Its name, a random UUID by default, is a non-empty string (`NOT_EXPECTED_TYPE`, `VALUE_NOT_NON_EMPTY_STR`). - A streaming DataFrame is not observed (`UNSUPPORTED_OPERATION`); `observe` asks the server whether the DataFrame is streaming, as `df.isStreaming` does. - `DataFrame.observe` raises `CANNOT_BE_EMPTY` without exprs, and `NOT_EXPECTED_TYPE` for exprs that are not Columns and for an observation that is neither an `Observation` nor a string. The core `Observation` keeps the shared state of the observation, which `DataFrame::observe_with` observes with, and its `get` returns the metrics. ### Why are the changes needed? `Observation.get` was always `{}`: it never received the observed metrics, and none of these errors were raised. ### Does this PR introduce _any_ user-facing change? Yes. Observations receive their metrics, and raise the errors of PySpark 4.3.0. ### How was this patch tested? - A new live test observes metrics through `collect`, a write and `count`, of two Observations of one name, and an observation error. It passes with official PySpark 4.3.0, and fails without this change. - A new offline test checks the arguments and the errors of `Observation` and `DataFrame.observe` against a mock Connect server. - New lib tests check the observations that observed metrics set, by the plan IDs of their relations, the single use of an observation, and the errors of observations. - The lib tests of both crates (574 passed), the build of all tests, also with `wasm-udf`, the offline Python suites (1810 passed, 8 skipped), and the live drop-in and Arrow suites (109 passed) and live cases (10 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]
