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

   ### What changes were proposed in this pull request?
   
   [SPARK-61320](https://issues.apache.org/jira/browse/SPARK-61320): Keep the 
type of pivot values as their Spark literals, reject a NULL pivot value, and 
reject a bad `how` in `DataFrame::dropna`, as PySpark does.
   
   - `GroupedData::pivot`: an explicit pivot value keeps its type. Date, 
timestamp, timestamp without time zone, time, binary and decimal values become 
the matching literals (a decimal without a precision or scale takes those of 
its text, as `BigDecimal` has them). Before, every such value other than a 
bool, number, string or interval was sent as the text of its Debug form 
("Date(18262)", "Null"). A NULL, list, map, struct or variant value is now 
`NOT_EXPECTED_TYPE` with the Python type name, as PySpark's `GroupedData.pivot` 
reports a value it does not take. The signature is unchanged.
   - `DataFrame::dropna` and `NaFunctions::drop` now return 
`Result<DataFrame>`. `how` must be `"any"` or `"all"` (or `None`, which is 
`"any"`), else `VALUE_NOT_ALLOWED` with `['any', 'all']`, as PySpark's `dropna` 
raises. Before, any other value silently meant `"any"`. The drop-in now takes 
the core's check instead of its own copy of it; its results and errors are the 
same (checked against official 4.3.0 with `how` values of several types and 
with `thresh` and `subset` set). Callers in `crates/spark-connect/tests` are 
updated.
   - The other string arguments of the core were checked against official 4.3.0 
and need no change: `corr` and `cov` take no method (only "pearson" exists), 
`explain_string` already checks its mode, and the join types, `nearestByJoin`, 
`asOfJoin`, `summary`, `outputMode` and the save mode are sent to the server as 
PySpark sends them.
   
   Official PySpark 4.3.0 rejects a date, timestamp or decimal pivot value on 
the client (`NOT_EXPECTED_TYPE`), so the Rust API can pivot on those values 
only through its own call; the server accepts them. The test compares that 
pivot with the one PySpark computes without values for the same data.
   
   ### Why are the changes needed?
   
   - A pivot on a date column with `Value::Date` values failed on the server 
with `CAST_INVALID_INPUT`, because the value was sent as the text 
`Date(18262)`. A NULL pivot value silently pivoted a string column on the text 
`Null`.
   - `dropna(Some("bogus"), None, None)` dropped every row with a NULL, as 
`"any"` does. PySpark raises `VALUE_NOT_ALLOWED` for it, and so does the 
drop-in.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, for the Rust API only. `DataFrame::dropna` and `NaFunctions::drop` 
return a `Result` (a call site needs `?` or `.unwrap()`). A pivot value of a 
date, timestamp, time, binary or decimal type pivots on that value, and a NULL 
pivot value is an error. The Python drop-in's results do not change.
   
   ### How was this patch tested?
   
   - Offline unit tests in `crates/spark-connect/src/group.rs` (`mod tests`, 
before `stat_crosstab_plan`): `pivot_values_keep_their_types_as_literals` 
checks the proto literal of each value type, including decimals with and 
without a precision and scale, and 
`a_null_or_a_nested_pivot_value_is_not_expected_type` checks the error of a 
NULL, list and map value.
   - Offline unit test in `crates/spark-connect/src/dataframe.rs` 
(`plan_construction_tests`, before `replace_literals_plan`): 
`dropna_takes_how_any_or_all_as_pyspark` checks that "any", "all" and no `how` 
are accepted and that `"ANY"`, `"all "`, `""` and `"some"` give 
`VALUE_NOT_ALLOWED` with and without `thresh`.
   - Live test in `crates/spark-connect/tests/e2e_dataframe.rs` (before 
`day_time_interval_input_roundtrips`): 
`pivot_values_of_dates_timestamps_and_decimals_match_discovered_pivots` checks 
that explicit date, timestamp and decimal pivot values give the same result as 
the discovered pivot of the same data, and that a NULL value and `how="bogus"` 
give the errors above. Official PySpark 4.3.0 on the same server and data: a 
NULL pivot value raises `NOT_EXPECTED_TYPE` with `arg_type` `NoneType`, a date, 
timestamp or decimal value raises it with `arg_type` `date`, `datetime` or 
`Decimal`, `dropna(how="bogus")` and `how="ANY"` raise `VALUE_NOT_ALLOWED` with 
`['any', 'all']`, and `dropna(how="all")` keeps both rows, as the test asserts.
   - The existing live tests that call `dropna` and `na().drop` 
(`agg_na_stat_reshape_surface`, `na_reshape_execute`) pass with the new 
`Result`.
   - The lib tests (531 passed), the build of all tests, the offline Python 
suites (2927 passed, 8 skipped) with the rebuilt extension, and the live Rust 
tests `e2e_dataframe` (8 passed), `e2e_coverage -k agg_na_stat_reshape_surface` 
and `e2e_ops_breadth -k na_reshape_execute` against a local Spark 4.3.0 server. 
Clippy reports no new 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]

Reply via email to