Skip to content

[SPARK-58546][ML] Avoid redundant StringIndexer label lookups - #57745

Closed
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:single-lookup-string-indexer
Closed

[SPARK-58546][ML] Avoid redundant StringIndexer label lookups#57745
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:single-lookup-string-indexer

Conversation

@zhengruifeng

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR passes keepInvalid into StringIndexerModel.getIndexer, computes it once during transformation, and uses one OpenHashMap.get lookup for non-null labels.

Why are the changes needed?

The previous UDF performed contains followed by map access for known labels, causing two lookups per value. This removes the redundant lookup while preserving invalid-label behavior.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Not run (not requested). Verified with git diff --check, ASCII scan, and changed-line length scan.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Codex (GPT-5)

zhengruifeng added a commit that referenced this pull request Aug 4, 2026
### What changes were proposed in this pull request?

This PR passes `keepInvalid` into `StringIndexerModel.getIndexer`, computes it once during transformation, and uses one `OpenHashMap.get` lookup for non-null labels.

### Why are the changes needed?

The previous UDF performed `contains` followed by map access for known labels, causing two lookups per value. This removes the redundant lookup while preserving invalid-label behavior.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Not run (not requested). Verified with `git diff --check`, ASCII scan, and changed-line length scan.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Codex (GPT-5)

Closes #57745 from zhengruifeng/single-lookup-string-indexer.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
(cherry picked from commit 1f2b47d)
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
@zhengruifeng

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

@zhengruifeng
zhengruifeng deleted the single-lookup-string-indexer branch August 4, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants