HyukjinKwon opened a new pull request, #742:
URL: https://github.com/apache/spark-connect-rust/pull/742
### What changes were proposed in this pull request?
This is a follow-up of #686 (SPARK-61698), found while reviewing the last 50
commits. The Rust API's `OneVsRestModel` transform and `OneVsRest` fit did not
compose their classes as PySpark's `OneVsRestModel._transform` and
`OneVsRest._fit` do. #738 makes the Python binding run PySpark's own
`_transform`, and this PR ports it to the Rust API.
- **The transform** is now an exact port of `OneVsRestModel._transform`
(`classification.py:3851-3897`):
- the `mbc$acc<uuid>` accumulator of `F.array().cast("array<double>")`;
- each submodel's transform with its OWN params, then the select of the
input columns, the model's `rawPredictionCol` and the accumulator;
- `array_append` of `vector_get(raw, 1)`, and the rename of the
`mbc$tmp<uuid>` column;
- `array_to_vector` and `array_argmax(...).cast("double")` at the end, and
the drop of the accumulator.
`vector_get` and `array_argmax` are ported from PySpark's
`pyspark.sql.internal.InternalFunction`. The input is persisted with
`MEMORY_AND_DISK` when it isn't persisted already, and unpersisted when the
composition is built, as PySpark's `_cache_spark_dataset` does, including its
`SPARKML_TEMP_DFS_PATH` branch. The validators' cache helper is generalized to
a storage level and an enable flag for this.
- **Before**, the Rust transform overrode each submodel's `featuresCol` with
the model's, wrote the raw scores to a temporary column, used other functions,
and didn't persist. So a model `featuresCol` that the submodels don't use
failed, and a `rawPredictionCol` that the submodels don't produce succeeded.
PySpark does the opposite of both. The results agreed otherwise.
- **The fit's binary labels.** PySpark fits each class on its binary label
`mc2b$<index>`; the Rust fit named it `<uid>_label_<index>`. It now uses
PySpark's name, in the core and in the binding's training sets of the
submodels' summaries.
`docs/compatibility.md`'s OneVsRest section describes the transform.
### Why are the changes needed?
To match PySpark 4.3.0, in the edge cases and in the requests. Through a
recording proxy, the transform's requests now equal PySpark's: the AnalyzePlans
of the schema, storage level, persist and unpersist, and the ExecutePlan. They
differ only in uids, uuids, python_origin blocks and the counter-based names of
lambda variables. Before, they were 3 requests against PySpark's 6, with
different expression trees.
### Does this PR introduce _any_ user-facing change?
Yes, in the Rust API: the transform's behavior in the two edge cases above,
its persist and unpersist, and the names of the fit's binary labels.
### How was this patch tested?
- New live tests in
`crates/spark-connect/tests/e2e_classification_misc_api.rs`, against official's
values:
- the transform on the golden's evaluation rows;
- a model `featuresCol` that the submodels don't use, which fails without
the change;
- a `rawPredictionCol` that they don't produce, failing with
`UNRESOLVED_COLUMN`, which also fails without the change.
- The wire comparison above, by hand.
- The crate's offline tests pass (1279), and so does
`e2e_classification_misc_api` live (14).
- After the label rename, the binding's offline and live OneVsRest suites
pass.
- `cargo fmt --check`, `cargo +1.100.0 clippy --workspace --all-targets --
-D warnings` and `scripts/audit_no_stubs.sh` are clean.
### 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]