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

   ### What changes were proposed in this pull request?
   
   `DataFrame._plan.plan(session)` gives a shallow placeholder of the 
DataFrame's relation, which the core replaces by the relation when it sends a 
plan. It replaced it only:
   - as the root relation of a plan or an analysis;
   - in the plans of `pyspark.ml`;
   - under a `WithRelations` or (SPARK-61926) a `SubqueryAlias`;
   - in the messages of extensions (#785).
   
   Since #779 (SPARK-61856), `SparkSession.client` takes PySpark's plans and 
commands, which code builds with `pyspark.sql.connect.proto` over 
`df._plan.plan(client)`. Anywhere else, the server refused the placeholder with 
`CONNECT_INVALID_PLAN.NO_HANDLER_FOR_EXTENSION`, where PySpark sends the 
relation. Checked on both clients against a Spark 4.3.0 server:
   
   | sent by `spark.client` | pyspark-client 4.3.0 | drop-in before |
   |---|---|---|
   | `to_table` of a `Limit` over `df._plan.plan(client)` | `{'id': [0, 1]}` | 
`NO_HANDLER_FOR_EXTENSION` |
   | `to_table` of a cross `Join` of two DataFrames' plans | 15 rows | 
`NO_HANDLER_FOR_EXTENSION` |
   | `execute_command` of a `CreateDataFrameView` over it | a view of 5 rows | 
`NO_HANDLER_FOR_EXTENSION` |
   | `execute_command` of a local, eager `CheckpointCommand` | a DataFrame of 5 
rows | `NO_HANDLER_FOR_EXTENSION` |
   | `execute_command` of a `WriteOperation` (noop) | runs | 
`NO_HANDLER_FOR_EXTENSION` |
   
   The same held for `DataFrame(plan, session)` of a `LogicalPlan` that builds 
such a relation.
   
   **The relations.** `plan::resolve_relation_at` now descends into every input 
of every relation of Spark Connect, a level below it. `relation_inputs_of` 
lists them, in the order of their fields:
   - the input of each relation of one input;
   - both sides of a join (`Join`, `AsOfJoin`, `LateralJoin`, `NearestByJoin`), 
a `SetOperation` and a `Zip`;
   - the initial input of a `GroupMap` and the other input of a `CoGroupMap`;
   - the root and the references of a `WithRelations`.
   
   **The commands.** `resolve_command` replaces the relation of each command 
that holds one:
   - `WriteOperation`, `WriteOperationV2`, `CreateDataFrameView`, 
`WriteStreamOperationStart`;
   - `SqlCommand.input`, `CheckpointCommand`, `MergeIntoTableCommand`;
   - the flows of a `PipelineCommand`;
   - as before, the ML commands and the extensions.
   
   **The Observations.** `child_observations` takes the Observations of the 
child of every relation, as PySpark's `LogicalPlan.observations` collects them. 
For a `Join`, `AsOfJoin`, `LateralJoin`, `NearestByJoin`, `Zip` and 
`SetOperation`, it takes both sides, the right side's over the left side's of a 
name (`{**left, **right}`). For a `GroupMap` and a `CoGroupMap`, it takes the 
input only, as PySpark's do.
   
   **What stays.** The core does not look into expressions, which hold no 
relation (a subquery refers to its plan by its ID in a `WithRelations`). So a 
placeholder in the extension of an expression is still sent as it is, and so is 
one that the message of an extension changes (`plan.common.plan_id = ...`). 
Delta Lake's plans hold neither.
   
   **The docs** say this in the one list of "SparkSession.client" in 
`docs/compatibility.md` and of "Plans of a DataFrame's relation" in 
`dev/parity/known-differences.md`. The Delta Lake paragraph, the plugin entry 
and `AGENTS.md` refer to them.
   
   ### Why are the changes needed?
   
   So that the plans and commands that `SparkSession.client` is given, and the 
plans of `DataFrame(plan, session)`, send the relations of their DataFrames 
wherever PySpark's do, as #779's parity claims.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A DataFrame's plan under any relation, and as the relation of any 
command, now works as on PySpark. The Observations of a `DataFrame(plan, 
session)` over a join are those of both sides.
   
   ### How was this patch tested?
   
   - **New Rust tests** in `plan.rs`:
     - 
`placeholders_resolve_under_every_input_of_the_relations_of_spark_connect` 
covers 14 shapes of input, each a level below its relation, and a chain of 
`Limit`s of its levels;
     - `placeholders_resolve_in_the_relations_of_commands` covers 9 commands;
     - the `SubqueryAlias` test of SPARK-61926 now expects its `Limit` to be 
replaced.
   
     `the_observations_of_a_plan_are_those_that_pyspark_collects` in 
`dataframe.rs` checks a `Join` (both sides, the right's of a name) and a 
`CoGroupMap` (its input only).
   - **New Python tests:**
     - 
`test_plans_and_commands_built_in_python_send_the_relations_of_their_dataframes`
 in `test_dropin_offline.py`, on the mock server. It fails on SPARK-61926 alone 
and passes with this change.
     - 
`test_client_sends_the_relations_of_dataframes_under_the_plans_it_is_given_as_pyspark`
 in `test_dropin_e2e.py`, which also passes on pyspark-client 4.3.0.
   - **Probes:** a session hook sees each request as it is sent. On SPARK-61926 
alone, the placeholder was sent under a `Limit`, also in a `WithRelations`, 
under a `Join` and in a `WriteOperation`, `CreateDataFrameView` and 
`CheckpointCommand`. It was not sent as the root, under a `SubqueryAlias` or a 
`WithRelations`, or in the extensions of relations and commands. With this 
change only an expression's extension sends it, and the server returns 
PySpark's results for the rest.
   - `cargo test -p apache-spark-connect --release --lib`: 775 passed.
   - The offline suite of `coverage.yml`: 6200 passed, 77 skipped.
   - `test_dropin_e2e.py` against a Spark 4.3.0 server: 306 passed.
   - **Lint:**
     - `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`;
     - 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