HyukjinKwon opened a new pull request, #590:
URL: https://github.com/apache/spark-connect-rust/pull/590
### What changes were proposed in this pull request?
In the Rust API, `DataFrame::select` and `group_by` take any columns (`impl
IntoIterator<Item = C>`, `C: Into<Column>`). The other column-list methods took
a `Vec<Expression>`, so the docs and examples wrote `.expression().clone()` for
each column:
```rust
df.group_by([f::col("category")]).agg(vec![
f::sum(f::col("id")).alias("total").expression().clone(),
f::avg(f::col("id")).alias("average").expression().clone(),
])
```
These now take columns, as `select` and `group_by` do:
- `DataFrame`: `sort`, `order_by`, `sort_within_partitions`, `agg`,
`observe`, `observe_with`, `hint_expressions`, `repartition_by_range`,
`repartition_by_range_opt` and `repartition_by_expressions`;
- `GroupedData::agg`;
- `WindowSpec::partition_by` and `Window::partition_by`;
- `WindowSpec::order_by` and `Window::order_by`, which took a
`Vec<SortOrder>`. A column that is a sort order keeps its order, and any other
column is ascending with nulls first, as PySpark's `Window.orderBy` sorts it.
`From<Expression> for Column` and `From<SortOrder> for Column` are added, so
callers that pass a `Vec<Expression>` or a `Vec<SortOrder>` compile as they
are. That includes the Python client, the examples crate and the existing
tests. An empty `vec![]` has no item type to infer and needs
`Vec::<Column>::new()`; `docs/compatibility.md` notes this.
The docs (`dataframes.md`, `examples.md`, `quickstart.md`, `sql.md`) and the
examples drop the `.expression().clone()`, e.g.
`.agg([f::sum(f::col("id")).alias("total"),
f::avg(f::col("id")).alias("average")])` and
`.order_by([f::col("count").desc()])`.
Left as they are:
- the plan-node and expression constructors (`Expression::function`, ...);
- the SQL parameter methods, where a `&str` must not become a column;
- `sample_by`, whose strata are values;
- the `Vec<Column>`/`Vec<&str>` methods (`with_columns`, `drop_columns`,
`grouping_sets`, ...), for a follow-up.
### Why are the changes needed?
The column-list methods were inconsistent, and their docs read badly.
### Does this PR introduce _any_ user-facing change?
Yes, in the Rust API. These methods take any columns: arrays of `Column`, as
well as the `Vec<Expression>` and `Vec<SortOrder>` that they took.
### How was this patch tested?
- New unit tests: each changed method takes `[Column; N]` and a
`Vec<Expression>`, and builds the plan that it built before. A new e2e test
checks `observe_with` of columns and of expressions.
- The lib tests (867 passed), the build of all tests (also with `wasm-udf`),
and the builds of `pyspark-rs` and `examples`.
- The e2e tests of dataframes, columns, functions and the ML estimators
against a Spark 4.3.0 server.
- `check_doc_snippets.py` (56 snippets, 0 failures) and `cargo fmt --all
--check`.
### 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]