[SPARK-58189][PYTHON] Refactor SQL_GROUPED_MAP_PANDAS_UDF_WITH_STATE#57339
Open
Yicong-Huang wants to merge 2 commits into
Open
[SPARK-58189][PYTHON] Refactor SQL_GROUPED_MAP_PANDAS_UDF_WITH_STATE#57339Yicong-Huang wants to merge 2 commits into
Yicong-Huang wants to merge 2 commits into
Conversation
HyukjinKwon
approved these changes
Jul 19, 2026
uros-b
approved these changes
Jul 20, 2026
uros-b
left a comment
Member
There was a problem hiding this comment.
Thank you @Yicong-Huang and @HyukjinKwon!
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 refactors
SQL_GROUPED_MAP_PANDAS_UDF_WITH_STATE(applyInPandasWithState) so that the worker uses the plainArrowStreamSerializerfor pure Arrow stream I/O, moving the per-eval-type logic fromApplyInPandasWithStateSerializerintoread_udfs()inworker.py: reconstructing eachGroupStatefrom the trailing state-info column, slicing the data columns by each chunk's(startOffset, numRows), regrouping chunks by grouping key (via the reused state object), invoking the UDF once per key with a lazy iterator of pandas DataFrames and its state, validating the returned DataFrames, and serializing the output plus updated state back into count/data/state Arrow RecordBatches bounded byarrow_max_records_per_batch. This mirrors the earlier refactor ofSQL_TRANSFORM_WITH_STATE_PANDAS_UDFin SPARK-57400. TheApplyInPandasWithStateSerializerclass is kept for now and deleted in a follow-up cleanup.Why are the changes needed?
Part of SPARK-55388. Keeping serializers as pure Arrow stream I/O and concentrating eval-type-specific logic in
worker.pymakes the per-eval-type data flow explicit.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing tests. No behavior change.
ASV comparison (
bench_eval_type.ApplyInPandasWithStateUDFTimeBench/ApplyInPandasWithStateUDFPeakmemBench,-a repeat=3): before =upstream/master, after = this PR. Values are from one representative run per side; the conclusion is consistent across runs. All deltas are within run-to-run noise (the larger swings track high before-side variance, e.g.few_groups_sm/countbefore131ms+-228ms), showing no regression. Peak memory is unchanged.Was this patch authored or co-authored using generative AI tooling?
No.