[SPARK-59398][ML][SQL] Add a SQL expression for ML vector affine transformations - #58692
Open
zhengruifeng wants to merge 10 commits into
Open
[SPARK-59398][ML][SQL] Add a SQL expression for ML vector affine transformations#58692zhengruifeng wants to merge 10 commits into
zhengruifeng wants to merge 10 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR adds an internal
VectorAffineTransformCatalyst expression, registered asml_vector_affine_transform, that computesvector(i) * scale(i) + shift(i)from the SQL structrepresentation of an MLlib vector and non-nullable-element
array<double>scale and shift inputs.The expression supports interpreted and code-generated evaluation for dense and sparse vectors
through a shared
MLExpressionUtils.affineTransformimplementation. Code-generated evaluationcaches non-null literal scale and shift arrays as primitive
double[]references.A null scale column value is treated as an identity scale, and a null shift column value is treated
as a zero shift. When both are null, the input vector is returned unchanged. It preserves sparse
output only when the input vector is sparse and the shift is null; any non-null shift produces a
dense vector. It also adds private ML helper functions for column and constant-array scale/shift
inputs. This PR does not use the expression in ML implementations.
Why are the changes needed?
Several ML feature transformations perform per-feature scaling and shifting through Scala UDFs.
This expression provides a reusable Catalyst building block for future optimizations without
deserializing vectors into MLlib objects.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
New tests cover interpreted and code-generated evaluation with dense and sparse vectors, null
scale and shift handling, non-null array element enforcement, sparse output preservation, nonzero
shifts, null and empty vectors, infinite and NaN values, and mismatched dimensions.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-5)