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

   ### What changes were proposed in this pull request?
   
   PySpark's `DataFrame._plan.observations` is `LogicalPlan.observations` of 
the DataFrame's plan: the Observations of `observe` on the DataFrame and on its 
inputs, by their names (`plan.py:152-157`, `CollectMetrics` at `:1829-1837`, 
both sides of a `Join` at `:1155-1157`). PySpark's DataFrame gives them to the 
executions of its client (`client.to_table(query, self._plan.observations)`, 
`connect/dataframe.py:1982`, `2002`, `2228`), and a plan of 
`pyspark.sql.connect.plan` over it, such as a `SubqueryAlias`, has them too. 
The drop-in's `DataFrame._plan`, a `_DataFramePlan`, had none.
   
   Checked on both clients against a Spark 4.3.0 server, with `o = 
Observation("o1")` and `df = spark.range(3).observe(o, 
F.count(F.lit(1)).alias("n"))`:
   
   | | pyspark-client 4.3.0 | drop-in before |
   |---|---|---|
   | `df._plan.observations` | `{'o1': o}` | `{}` |
   | `SubqueryAlias(df._plan, "s").observations` | `{'o1': o}` | `{}` |
   | `o.get` after `client.to_table(plan_of_df, df._plan.observations)` | 
`{'n': 3}` | `{}` |
   | `o.get` after `DataFrame(SubqueryAlias(df._plan, "s"), spark).collect()` | 
`{'n': 3}` | `{'n': 3}` |
   
   The change:
   - `_DataFramePlan.observations` (`python/pyspark/sql/connect/plan.py`) gives 
the Observations of the core's plan, `DataFrame::observations`, through the 
binding's new `DataFrame._observations` (`crates/pyspark-rs/src/dataframe.rs`):
     - in the order of PySpark's dict, which merges the Observations of a plan 
after those of its inputs: the core gives them in the reverse order;
     - by PySpark's keys, `str(observation._name)`;
     - a DataFrame observed by a name has none, as in PySpark.
   - Each is the Python Observation that holds the state. Once only the plan 
holds it, it is a new Observation of the state, which the executions of the 
plan set, and which later reads give back while it is alive 
(`python_observation_of`, `crates/pyspark-rs/src/observation.rs`).
   - So the plans over it (`SubqueryAlias(df._plan, "s")`) and a DataFrame of 
such a plan have them, through the core's Observations of its relation.
   
   `docs/compatibility.md` says so in the "SparkSession.client" section.
   
   ### Why are the changes needed?
   
   So that code that runs the plan of a DataFrame through 
`SparkSession.client`, as PySpark's DataFrame does, sets the DataFrame's 
Observations, and so that `DataFrame._plan.observations` is PySpark's.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `DataFrame._plan.observations`, and the `observations` of the plans of 
`pyspark.sql.connect.plan` over it, are the DataFrame's Observations by their 
names, as in PySpark, where they were empty.
   
   ### How was this patch tested?
   
   - **Probes of both clients against a Spark 4.3.0 server:** 
`df._plan.observations`, a `SubqueryAlias` over it, the views of `SQL` (none, 
in both), `client.to_table` with and without them, and 
`DataFrame(SubqueryAlias(...)).collect()` give identical output.
   - **New tests:**
     - `test_the_plans_of_dataframes_have_their_observations_as_pyspark` in 
`test_dropin_offline.py`, on the mock server, checks:
       - the order of PySpark's dict, of an `observe` chain, a join, a union 
and a filter;
       - the identity of the Observations, and that a DataFrame observed by a 
name has none;
       - a `SubqueryAlias`, a DataFrame of one, and `SQL`'s views;
       - an Observation that only the plan holds any more;
       - that `client.to_table` sets the Observations that it is given, and 
only those.
     - 
`test_the_plans_of_dataframes_give_the_client_their_observations_as_pyspark` in 
`test_dropin_e2e.py`, which also passes on pyspark-client 4.3.0.
   - `cargo test -p pyspark-rs --lib`: 13 passed.
   - The offline suite of `coverage.yml`: 6259 passed, 77 skipped.
   - `test_dropin_e2e.py` against a Spark 4.3.0 server: 311 passed.
   - **Lint and guards:**
     - `cargo fmt --all --check`;
     - `cargo +1.100.0 clippy -p apache-spark-connect-core -p 
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`;
     - `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p apache-spark-connect 
-p apache-spark-connect-core`;
     - ruff 0.14.0, `test_ruff_excludes.py`, `scripts/audit_no_stubs.sh`;
     - `scripts/gen_type_stubs.py --check` and `scripts/gen_fn_dispatch.py 
--check` against the v4.3.0 source, and `test_type_stubs_offline.py` with mypy 
2.4.1: OK, and 7 passed;
     - the guards of `coverage.yml` and `build_python_connect.yml`.
   
   ### 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