Skip to content

[SPARK-59152][ML] Create CountVectorizer broadcast per transform - #58452

Closed
zhengruifeng wants to merge 3 commits into
apache:masterfrom
zhengruifeng:ml-countvectorizer-transform-broadcast-dev-5
Closed

[SPARK-59152][ML] Create CountVectorizer broadcast per transform#58452
zhengruifeng wants to merge 3 commits into
apache:masterfrom
zhengruifeng:ml-countvectorizer-transform-broadcast-dev-5

Conversation

@zhengruifeng

@zhengruifeng zhengruifeng commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR creates the CountVectorizerModel dictionary and its broadcast for each transform call
instead of caching the broadcast on the model.

Why are the changes needed?

The dictionary broadcast is transformation-only execution state. Retaining it on the model keeps the
broadcast alive for the model's lifetime and ties later transformations to the SparkContext used by
the first transformation. A transform-scoped broadcast follows the lifecycle of the returned lazy
DataFrame. This is consistent with the other explicit inference broadcasts in
org.apache.spark.ml: Word2VecModel broadcasts its word-vector model per transform, while
RandomForestRegressionModel and GBTRegressionModel broadcast their models per transform and
share each broadcast between the output UDFs created by that transform.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

No tests were added because this is an internal broadcast lifecycle change and the transformation
logic is unchanged. The patch was checked with git diff --check and source line-length and
non-ASCII scans.

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

Generated-by: OpenAI Codex (GPT-5)

@zhengruifeng

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

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

This PR creates the `CountVectorizerModel` dictionary and its broadcast for each `transform` call
instead of caching the broadcast on the model.

### Why are the changes needed?

The dictionary broadcast is transformation-only execution state. Retaining it on the model keeps the
broadcast alive for the model's lifetime and ties later transformations to the `SparkContext` used by
the first transformation. A transform-scoped broadcast follows the lifecycle of the returned lazy
DataFrame. This is consistent with the other explicit inference broadcasts in
`org.apache.spark.ml`: `Word2VecModel` broadcasts its word-vector model per transform, while
`RandomForestRegressionModel` and `GBTRegressionModel` broadcast their models per transform and
share each broadcast between the output UDFs created by that transform.

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

No.

### How was this patch tested?

No tests were added because this is an internal broadcast lifecycle change and the transformation
logic is unchanged. The patch was checked with `git diff --check` and source line-length and
non-ASCII scans.

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

Generated-by: OpenAI Codex (GPT-5)

Closes #58452 from zhengruifeng/ml-countvectorizer-transform-broadcast-dev-5.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
(cherry picked from commit 0653977)
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 ml-countvectorizer-transform-broadcast-dev-5 branch September 2, 2026 00:43
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