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

   ### What changes were proposed in this pull request?
   
   A follow-up of #776 (SPARK-61853), which found that `readwriter_golden.rs` 
claimed protobuf parity with PySpark but read no golden. Three more golden 
tests did the same:
   - `catalog_golden.rs` said its goldens were in `tests/golden/catalog.jsonl` 
and that "a required case that is missing or mismatches FAILS the test". The 
file did not exist, the loader was dead code under `#![allow(dead_code)]`, and 
the tests only asserted that the bytes were not empty.
   - `ml_golden.rs` and `ml_extra_golden.rs` read `tests/golden/ml.jsonl` and 
`ml_extra.jsonl`. Neither existed, so both printed a warning and skipped their 
comparisons.
   
   Their capture scripts, and `capture_golden.py` and 
`capture_window_golden.py`, read `FieldDescriptor.label`, which protobuf 7 no 
longer has. With this PR, as #776 did for the readwriter:
   
   **The goldens.**
   - `tests/golden/catalog.jsonl` (59 calls), `ml.jsonl` 
(`standard_scaler_transform`) and `ml_extra.jsonl` 
(`vector_assembler_transform`, `string_indexer_transform`, 
`max_abs_scaler_transform`, `logistic_regression_transform`, 
`pipeline_transform`) are captured on PySpark 4.3.0. Each capture gave 
byte-identical results three times.
   - `capture_catalog_golden.py` captured no case, as PySpark's list methods 
return lists, not DataFrames. It now records each plan that a Catalog call 
sends, for each method that the Rust API mirrors, with their optional arguments.
   - The ML scripts now capture `pyspark.ml`, which the Rust API mirrors, 
rather than `pyspark.ml.connect`, whose StandardScaler runs pandas UDFs and 
whose LogisticRegression needs torch. They record the fit's ML commands, and 
the transform's relation over a dataset that the client builds without a server.
   - The scripts that `-I` could not import from 
(`capture_functions_golden.py`, `capture_hof_golden.py`) add their own 
directory to `sys.path`, as the ML scripts do. All 47 `capture_*.py` import 
with the official client under `-I`.
   
   **The tests.**
   - `catalog_golden.rs` compares each of the 59 cases. Lazy calls are compared 
through `to_relation()`, and eager ones through a loopback service that records 
their plans.
   - `ml_golden.rs` and `ml_extra_golden.rs` fit each model through the replay 
server on its golden fit, check the fit's commands, and compare the transform's 
relation with the golden.
   - A missing golden or case fails each test. The dead code, the loaders that 
skipped a missing file and the vacuous tests are removed.
   - `functions_golden.rs` gets a case for each of its goldens, which it now 
requires: the 23 functions that 4.3.0's capture adds, `random`, and the six 
`tuple_union_*`.
   
   **The recaptured goldens.**
   - `plans.jsonl` changes in 6 lines:
     - `group_count`, `cube`, `rollup` and `pivot` get an empty `common` of the 
grouping expression's origin, which the test clears;
     - `sample` is captured as `sample(fraction=0.5, seed=42)`, as PySpark 
4.3.0's `sample(0.5, seed=42)` ignores the keyword seed 
(dataframe.py:2187-2192);
     - `replace` changes in its text only.
   - `functions.jsonl` is refreshed: its 518 cases match 4.3.0 apart from 8 
random seeds, which the test zeroes, and it gains 23 functions.
   - `exprs.jsonl`, `window.jsonl`, `functions_hof.jsonl` and 
`readwriter.jsonl` are recaptured identical.
   
   **The Rust API, where the goldens show a gap.**
   
   | | PySpark 4.3.0 (now here too) | before |
   |---|---|---|
   | `Catalog::create_external_table(_with)` | `createExternalTable` calls 
`createTable` (connect/catalog.py:227-239), so it sends a `CreateTable`, whose 
`description` option is the table's description | a `CreateExternalTable` |
   | `variant_set(v, path, value)`, `try_variant_set` | sends 
`lit(create_if_missing)`, `True` by default (builtin.py:2247-2271) | no fourth 
argument |
   | `tuple_union_agg_double`, `tuple_union_agg_integer`, `tuple_union_double`, 
`tuple_union_integer`, `tuple_union_theta_double`, `tuple_union_theta_integer` 
| send `lit(12)` and `lit("sum")`, the defaults of `lgNomEntries` and `mode` | 
the columns only |
   
   The drop-in already sent these, through PySpark's own Python functions. 
`tuple_sketch_agg_double` and `tuple_sketch_agg_integer` already sent their 
defaults.
   
   The docs of the Rust ML traits named `pyspark.ml.connect.base`. They now 
name the `pyspark.ml` classes that they mirror: `pyspark.ml.base`'s 
`Estimator`, `Transformer` and `Model`, and `pyspark.ml.evaluation.Evaluator`, 
through `pyspark.ml.util`'s `try_remote_*`. `docs/contributing.md` describes 
which builders the goldens cover and how to capture them.
   
   ### Why are the changes needed?
   
   So that these golden tests check what they claim, and the Rust API sends 
what PySpark sends.
   
   ### Does this PR introduce _any_ user-facing change?
   
   In the Rust API, yes:
   - `Catalog::create_external_table` sends a `CreateTable`;
   - the three-argument `variant_set` and `try_variant_set` send 
`create_if_missing` of `true`;
   - the `tuple_union_*` functions send `lgNomEntries` of 12 and `mode` of 
`"sum"`, as PySpark does.
   
   No change in the drop-in.
   
   A remaining difference, already documented: PySpark's LogisticRegression fit 
also fetches `numClasses` right after the fit (ml/util.py:197-205), which the 
Rust model fetches only when asked. The ml_extra test asks for it after the 
fit, so both commands of the golden are compared.
   
   ### How was this patch tested?
   
   - `cargo test -p apache-spark-connect -p apache-spark-connect-core 
--release`: 1591 passed.
   - Live, against a Spark 4.3.0 server: `e2e_coverage` (25 passed) and 
`e2e_session_catalog` (13 passed), including the external table of a path, read 
back as 3 rows.
   - Mutation checks: each of these fails its test:
     - a missing `ml.jsonl` or `catalog.jsonl`;
     - a case dropped from `ml_extra.jsonl` or `catalog.jsonl`;
     - a changed param of the transform, the fit command or the pipeline's 
inner transform;
     - a changed `create_table`;
     - a removed `num_classes()` read;
     - a function golden without its case.
   - The drop-in: `test_dropin_offline.py -k "tuple or variant or catalog or 
create_table or external"` on pandas 3, and `scripts/gen_fn_dispatch.py 
--check`.
   - Lint: `cargo fmt --all --check`, `cargo +1.100.0 clippy -p 
apache-spark-connect --all-targets -- -D warnings`, ruff 0.14.0, 
`audit_no_stubs.sh` and `scripts/tests`.
   
   CI already runs these tests offline: rust.yml's `cargo test -p 
apache-spark-connect -p apache-spark-connect-core --release` and coverage.yml's 
llvm-cov pass.
   
   ### 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