HyukjinKwon opened a new pull request, #813:
URL: https://github.com/apache/spark-connect-rust/pull/813
### What changes were proposed in this pull request?
`DataFrame._plan.plan(session)` gives a shallow placeholder of the
DataFrame's relation. The core
replaced it as the root relation of a plan, where the plans of `pyspark.ml`
take their inputs,
under a `WithRelations`, and, since #785, in the message of the extension of
a plugin's relation or
command. It did not look under a `SubqueryAlias`. So the plans that the
drop-in's own
`pyspark.sql.connect.plan` builds over a DataFrame sent the placeholder,
which the server refuses,
where PySpark sends the relation. Checked on the repo's mock server with
both clients:
| plan | pyspark-client 4.3.0 | drop-in before |
|---|---|---|
| `DataFrame(SubqueryAlias(df._plan, "s"), spark)` | sends df's relation |
sends the placeholder |
| `DataFrame(SQL("SELECT * FROM v", views=[SubqueryAlias(df._plan, "v")]),
spark)` | sends df's relation | sends the placeholder |
| `SubqueryAlias(PluginPlan(df._plan), "p")`, whose extension holds
`df._plan.plan(session)` | sends df's relation | sends the placeholder |
The same holds for such plans that `SparkSession.client`'s `to_table`,
`schema` and the other
methods of #779 are given. Delta Lake's `DeltaTable.alias` builds a
`SubqueryAlias` over its own
plans. Those hold no DataFrame, so Delta 4.0's operations were not affected;
a plugin's plan over a
DataFrame was.
`plan::resolve_relation_at` now descends into the input of a
`SubqueryAlias`, a level below it,
on a grown stack, as an alias over an alias is as deep as the Python plan
that builds it.
`child_observations` takes the Observations of the alias's input, as
PySpark's
`SubqueryAlias.observations` are those of its child.
**The docs** now say where the core replaces the placeholder in one list.
#779 had added a list
to the "SparkSession.client" section of `docs/compatibility.md` and to the
"Plans of a DataFrame's
relation" entry of `dev/parity/known-differences.md`, which said that the
placeholder was not
replaced under a `SubqueryAlias`; this PR adds the `SubqueryAlias` and the
views of `SQL` there. The
Delta Lake paragraph of `docs/compatibility.md`, the plugin entry of
`known-differences.md` and
`AGENTS.md` refer to that list rather than keep their own. A placeholder
under a relation of
another type, such as a `Limit`, a `Join` or a plugin's own `Project`, and
one that a plugin
changes in the message of an extension (`plan.common.plan_id = ...`), are
still sent as they are,
which the server refuses.
### Why are the changes needed?
So that the plans that `pyspark.sql.connect.plan` builds over a DataFrame,
and a plugin's plans
under them, send the DataFrame's relation, as PySpark's do, and so that the
docs say where the
placeholder is replaced, in one place.
### Does this PR introduce _any_ user-facing change?
Yes. `SubqueryAlias(df._plan, ...)`, `SQL(...,
views=[SubqueryAlias(df._plan, ...)])` and
plugin plans under an alias now work as on PySpark: the server receives the
relation, and the
DataFrame's Observations receive their metrics.
### How was this patch tested?
- **New Rust test**
`placeholders_resolve_under_the_subquery_aliases_of_python_plans` in
`plan.rs`. It covers an alias over an alias over a placeholder, with its
levels; a `SQL` view in
the references of a `WithRelations`; an alias over a plugin's extension;
and a placeholder under
a `Limit`, which is left as it is.
- `the_observations_of_a_plan_are_those_that_pyspark_collects` in
`dataframe.rs` now also checks
an alias over the placeholder of an observed DataFrame.
- **New Python test**
`test_subquery_aliases_of_python_plans_send_the_relations_of_their_dataframes`
in `test_dropin_offline.py`, against the mock server. It checks the three
plans above, and that
the Observation of an observed DataFrame under an alias receives its
metrics. It fails without
the change and passes with it.
- After the rebase onto dc3aa4f0:
- `cargo test -p apache-spark-connect --release --lib`: 773 passed;
- the offline suite of `coverage.yml`: 6199 passed, 77 skipped;
`test_dropin_e2e.py` against a
Spark 4.3.0 server: 305 passed;
- `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`, and 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]