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

   ### What changes were proposed in this pull request?
   
   The Rust API's `spark_connect::functions` had no typed form for the optional 
arguments of about 106 of PySpark 4.3.0's functions. A Rust caller could send 
their requests only through `call_function` or `expr`. This was found by a 
review of the Rust API against PySpark's surface.
   
   This PR adds 131 functions. Each sends exactly the request that PySpark's 
function sends for its optional arguments: the function name, and the argument 
expressions in order.
   
   **Naming:**
   - `<name>_with_<param>`, with PySpark's parameter in snake_case; a chain of 
trailing parameters gets one form per arity 
(`aes_encrypt_with_mode_padding_and_iv`).
   - Groups are uniform:
     - `_with_format` for every date and time format;
     - `_with_ignore_nulls` for first, last, any_value, first_value, last_value 
and nth_value;
     - `_with_options` for the csv, json and xml functions;
     - `_with_parts` for the interval constructors.
   - The existing family names are kept: `ceiling_scale` (as `ceil_scale`), 
`btrim_with` and `replace_with` (as `trim_with`), `try_to_binary_format` (as 
`to_binary_format`).
   
   **Arguments:**
   - Every argument is a `Column`, as in the rest of the module. PySpark takes 
a Column for most of these too, so scalar types could not send all of its 
requests.
   - Options are name and value pairs, sent as `map(lit(k), lit(v), ...)` in 
their order, as PySpark's `_options_to_col` builds them.
   - The parts of the interval constructors are an `Option` each, sending 
`lit(0)` for `None`, as PySpark does.
   
   **Gap list corrections:**
   - `approxCountDistinct` needs no form: PySpark sends 
`approx_count_distinct(col, rsd)`, which `approx_count_distinct_rsd` sends.
   - `window_with_slide` covers `window(t, w, slideDuration)`, which the list 
missed.
   - PySpark's explicit `nth_value(col, n, ignoreNulls=None)` sends two 
arguments, where the base sends `false`. The server gives the same column name 
and result for both, which `nth_value_with_ignore_nulls` documents.
   
   **Generated dispatch:**
   - `scripts/gen_fn_dispatch.py` lists 107 forms in `OPTIONAL_ARG_VARIANTS`, 
whose arm picks a form by the number of arguments. The other 24 go in 
`NOT_DISPATCHED`, with a reason each: options, `Option` parts, date and time 
forms, `&str` arguments and the comparator closure.
   - `crates/pyspark-rs/src/dispatch_generated.rs` is regenerated. It has the 
same 532 arms; only the 87 base arms change.
   - `python/pyspark/sql/functions_generated.py` is byte-identical. The 
drop-in's functions call `_invoke_function` by name, so its requests do not 
change.
   
   **A gate:**
   - The tooling tests (`scripts/tests/test_gen_fn_dispatch.py`) fail on an 
optional parameter of a function of PySpark's checked-in stub 
`connect/functions/builtin.pyi` that no Rust function of its name or of its 
forms takes, unless `OPTIONAL_ARGS_OTHERWISE` gives the reason.
   - That list covers approxCountDistinct, lag, lead, log, udf, udtf and 
arrow_udtf.
   - Against master's functions, the gate reports 106 functions. 
`docs/contributing.md` describes it.
   
   `make_interval()`, `make_dt_interval()`, `make_ym_interval()` and 
`try_make_interval()` now call their `_with_parts` forms; their requests are 
unchanged. The closure parameters of `aggregate_with_finish` and 
`reduce_with_finish` are renamed to PySpark's `merge` and `finish`.
   
   ### Why are the changes needed?
   
   So that the Rust API can send every request that PySpark's functions send, 
as the docs say it mirrors PySpark's surface, and so that the gap does not 
reopen.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes: new functions in the Rust API, which the Rust migration notes list. No 
existing function changes its request, and the drop-in does not change.
   
   ### How was this patch tested?
   
   - **Golden tests of the requests.**
     - 130 new cases in `functions_golden.rs`, and one HOF case (`array_sort` 
of a comparator) in `hof_golden.rs`. All 671 cases pass.
     - The goldens were captured with the official client 
(`scripts/capture_functions_golden.py`, `capture_hof_golden.py`). A rerun 
reproduces them, apart from the random seeds, which the test zeroes.
   - **Live:** `e2e_functions` against a Spark 4.3.0 server, with a new test of 
the forms' results, whose expected values come from the official client.
   - **Rust.**
     - `cargo test -p apache-spark-connect -p apache-spark-connect-core 
--release`, and `--features wasm-udf`.
     - The drift checks of `gen_fn_dispatch.py`, both against PySpark's source 
and the Rust-only check, and of `gen_type_stubs`.
   - **Python.**
     - The tooling tests (`python3.11 -m unittest discover -s scripts/tests`), 
with the gate's unit tests.
     - The offline suite of `coverage.yml`.
   - **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -p 
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`, ruff 0.14.0, 
`audit_no_stubs.sh` and `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps`.
   
   ### 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