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

   ### What changes were proposed in this pull request?
   
   [SPARK-61286](https://issues.apache.org/jira/browse/SPARK-61286): 
`GroupedData::pivot` now sends typed pivot-value literals for binary, date, 
timestamp, timestamp without time zone, time and decimal values.
   
   - `value_to_lit_expr` in `crates/spark-connect/src/group.rs` maps each of 
those `Value` variants to its `LiteralExpression`. A time gets precision 6, as 
PySpark's literal of a `datetime.time`.
   - A decimal needs both `precision` and `scale`, which the 
`LiteralExpression` requires, so a decimal without them is an error.
   - A null, a list, a map, a struct, a variant, or a decimal without precision 
or scale now makes `pivot` return an `UNSUPPORTED_OPERATION` error. Before, 
each was sent as the string of its Debug format.
   - The Python client is unchanged. It accepts only bool, float, int and str 
pivot values, as before, so its `NOT_EXPECTED_TYPE` rejection of date, 
timestamp and decimal values is unchanged.
   
   ### Why are the changes needed?
   
   The Rust API's `pivot` built each value that did not fall in the boolean, 
number, string or day-time-interval arms from its Debug format. A pivot on a 
date column with `Value::Date(19723)` therefore sent the string 
`"Date(19723)"`. The server casts that string to the column's type, so the 
query failed with `CAST_INVALID_INPUT` under ANSI mode, and without ANSI it 
silently produced a null column named `Date(19723)`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, for the Rust API only. A pivot on a date, timestamp or decimal column 
with explicit values now matches the rows of those values. Before, it failed or 
returned a null column. `GroupedData::pivot` now returns an 
`UNSUPPORTED_OPERATION` error for a null, a nested value, or a decimal without 
precision or scale, where it used to send a string.
   
   ### How was this patch tested?
   
   - Offline unit tests in `crates/spark-connect/src/group.rs`:
     - `pivot_values_are_typed_literals` checks that each of the six variants 
is serialized as its typed literal in the `Aggregate` proto.
     - `pivot_values_without_a_literal_are_unsupported` checks the error and 
its `operation` parameter for a null, an array, a map, a variant and a decimal 
without precision or scale.
   - Server-gated e2e test `pivot_on_typed_values_matches_pyspark` in 
`crates/spark-connect/tests/e2e_dataframe.rs`, for a date, a timestamp and a 
decimal column. Its expected column names and counts were checked against 
PySpark 4.3.0 on the same server: pivoting each column on the same value 
written as a string gives `k=1 -> 1, k=2 -> 1` under the column named after 
that string (`2024-01-01`, `2024-01-01 00:00:00`, `1.50`).
   - With the old fall-through restored temporarily, all three new tests fail: 
the unit tests on the serialized literal type and on the missing error, and the 
e2e test with the server's `CAST_INVALID_INPUT`.
   - `cargo test -p apache-spark-connect --release --lib` (530 passed), 
`--no-run` and `--features wasm-udf --no-run`, `cargo fmt --all --check`. 
Clippy reports nothing on the changed lines.
   - Live: `e2e_dataframe`, `e2e_ops_breadth`, `e2e_coverage`, 
`plan_arg_regression_golden` and `coverage_plan_extra` pass against a Spark 
4.3.0 Connect server.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5 and Claude Haiku 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