HyukjinKwon opened a new pull request, #459: URL: https://github.com/apache/spark-connect-rust/pull/459
### What changes were proposed in this pull request? [SPARK-61329](https://issues.apache.org/jira/browse/SPARK-61329): the random functions of the Rust API draw a new seed for each call, as PySpark does. - `rand`, `randn`, `uuid`, `shuffle`, `uniform`, `randstr` and `count_min_sketch` (`crates/spark-connect/src/functions.rs`) send a new non-negative seed for each call, the core's `random_seed()` (as PySpark's `random.randint(0, sys.maxsize)`), instead of a fixed literal. - `_with_seed` variants take an explicit seed, as the Scala client's overloads: `rand_with_seed(i64)` and `randn_with_seed(i64)`, and `uuid_with_seed`, `shuffle_with_seed`, `uniform_with_seed`, `randstr_with_seed` and `count_min_sketch_with_seed` with a `Column`. - `random` and `random_with_seed` are added, PySpark's alias of `rand`. - `docs/compatibility.md` notes the change in the Rust migration section. ### Why are the changes needed? Each of these functions sent the same constant seed in every call, query, session and process. So `uuid()` returned the same UUIDs in every run, so surrogate keys collided across appends. `select(rand(), rand())` gave two equal columns, and `orderBy(rand())`, `filter(rand() < p)` and `shuffle` picked the same rows every time. PySpark 4.3.0 (`pyspark.sql.connect.functions.builtin`) and the Scala client draw a new seed per call. The Python drop-in was not affected: its functions draw from Python's `random`. ### Does this PR introduce _any_ user-facing change? Yes, in the Rust API. A random function without a seed now gives different values in each call and run, as PySpark does; an expression keeps its seed, so every execution of a DataFrame gives the same values. The `_with_seed` variants, `random` and `random_with_seed` are new. ### How was this patch tested? - Unit tests in `functions.rs`: - `random_functions_draw_a_new_seed_for_each_call_as_pyspark`: the eight functions, four calls each, give distinct non-negative seeds. It fails without the change. - `random_functions_with_a_seed_send_it_as_pyspark`: the seed of each `_with_seed` variant is sent as given, and `random_with_seed` is `rand_with_seed`. - Live (`crates/spark-connect/tests/e2e_functions.rs`, in both CI e2e lists): `random_functions_draw_a_seed_for_each_call_as_pyspark`. - Two `uuid()` columns and two `rand()` columns differ, and the `uuid()` of two queries differ. - A DataFrame gives the same values in two executions, and `rand_with_seed`/`shuffle_with_seed` repeat for a seed. - It fails without the change. - The golden plan test (`functions_golden.rs`, which zeroes these seeds) and `functions_coverage.rs` pass. - Checks: - lib tests of both crates; - the build of all tests, also with `wasm-udf` and `datafusion,polars`, with no warnings; - `cargo fmt --all --check`; - clippy, no diagnostics on 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]
