HyukjinKwon opened a new pull request, #421: URL: https://github.com/apache/spark-connect-rust/pull/421
### What changes were proposed in this pull request? [SPARK-61243](https://issues.apache.org/jira/browse/SPARK-61243): Route the Rust `GroupedData::sum`, `avg`, `min`, `max` and `mean` through the same numeric aggregation as the Python drop-in, so they behave as PySpark 4.3.0 for no columns, numeric columns and non-numeric columns. - `sum`, `avg`, `min`, `max` now call `numeric_agg`. Without columns they aggregate every numeric column of the DataFrame, in schema order, named as PySpark names them (`sum(i)`, `avg(d)`, ...). A given column must be numeric, otherwise the call fails with `NOT_NUMERIC_COLUMNS` (`PySparkTypeError` in Python) and `invalid_columns` lists the bad names in the given order, as `_numeric_agg` does. A missing column is also invalid. - `mean` still delegates to `avg`. `count` is unchanged. - Public API change: these five methods now return `Result<DataFrame>` instead of `DataFrame`, because `numeric_agg` reads the schema (an analysis RPC). Callers in the workspace are updated: `crates/spark-connect/tests/e2e_coverage.rs` and `e2e_ops_breadth.rs`. No doc snippet or example used them. - The offline unit test `group_sum_plan` is removed: it built the plan without a server, and `sum` now needs the schema. The new e2e test checks the same plan shape through the results. The results were checked against PySpark 4.3.0 (Connect) on a DataFrame with a string grouping column `k`, `i int`, `l long`, `d double` (NULL for one group), a string `s` and a pivot column `p`: `groupBy("k").sum()` gives `['k', 'sum(i)', 'sum(l)', 'sum(d)']` with rows `(a, 3, 30, 4.0)`, `(b, 3, 30, None)`; `rollup` and `cube` give the same plus a NULL key row `(None, 6, 60, 4.0)`; a pivot on `p` with values `p`, `q` gives `p_sum(i)`, ..., `q_sum(d)`; `sum("s")`, `min("i", "nope", "s")` and a pivot `sum("s")` raise `NOT_NUMERIC_COLUMNS` with `['s']`, `['nope', 's']` and `['s']`. ### Why are the changes needed? `GroupedData::sum(vec![])` built an aggregate with no expressions, so the result held only the grouping columns, where PySpark returns the sum of every numeric column. A non-numeric column was sent to the server as a raw `sum(s)` with no check, so the error was the server's and not PySpark's `NOT_NUMERIC_COLUMNS`. The Python drop-in already used `numeric_agg` and behaved as PySpark, so the two clients differed. Example: `df.group_by(vec![col("k")]).sum(vec![])` returned only `k` on a frame with `i`, `l`, `d`; PySpark returns `k, sum(i), sum(l), sum(d)`. ### Does this PR introduce _any_ user-facing change? Yes. The Rust `GroupedData::sum`, `avg`, `min`, `max` and `mean` return `Result<DataFrame>` (was `DataFrame`). Without columns they aggregate every numeric column (was: grouping columns only). A non-numeric or missing column is `NOT_NUMERIC_COLUMNS` (was: passed to the server). The Python drop-in is unchanged. ### How was this patch tested? - `group_numeric_aggregates_follow_pyspark` (new, `crates/spark-connect/tests/e2e_dataframe.rs`, before `dataframe_metadata_json_semantics`): `sum`, `avg`, `mean`, `min`, `max` with no columns and with a given numeric column on groupBy, rollup and pivot; grouping sets checked against rollup; a cube checked against rollup; and the `NOT_NUMERIC_COLUMNS` errors (kind, condition, `invalid_columns`) for a string column, a missing column, a pivot and a rollup. The expected names and values are the PySpark 4.3.0 results listed above. It fails without the fix (the no-column result is `['k']`). - `aggregates_execute` (`e2e_ops_breadth.rs`) and `agg_na_stat_reshape_surface` (`e2e_coverage.rs`) now unwrap the `Result` and pass. - The lib tests (521 passed), the build of all tests, the offline Python suites (2819 passed, 8 skipped) with the rebuilt extension, the live Rust tests `e2e_dataframe` (5 passed), `e2e_ops_breadth` (5 passed) and `e2e_coverage` (25 passed), and the live drop-in tests `-k group` (6 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]
