[SPARK-56648][PYTHON] Refactor SQL_SCALAR_PANDAS_UDF#55613
Open
Yicong-Huang wants to merge 2 commits intoapache:masterfrom
Open
[SPARK-56648][PYTHON] Refactor SQL_SCALAR_PANDAS_UDF#55613Yicong-Huang wants to merge 2 commits intoapache:masterfrom
Yicong-Huang wants to merge 2 commits intoapache:masterfrom
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?
Refactor
SQL_SCALAR_PANDAS_UDFto useArrowStreamSerializeras pure I/O, moving Arrow-to-Pandas and Pandas-to-Arrow conversion logic fromArrowStreamPandasUDFSerializerintoread_udfs()inworker.py.Specifically:
wrap_scalar_pandas_udfwrapper.SQL_SCALAR_PANDAS_UDFthroughArrowStreamSerializer(write_start_stream=True).read_udfs(), add a self-contained handler that:RecordBatchto pandas Series viaArrowBatchTransformer.to_pandas()(withstruct_in_pandas=\"dict\",df_for_struct=True,ndarray_as_list=False).pandas.DataFrame.RecordBatchviaPandasToArrowConversion.convert().Why are the changes needed?
Part of SPARK-55388. This consolidates UDF dispatch, verification, and conversion logic for
SQL_SCALAR_PANDAS_UDFinto a single inline handler inread_udfs(), mirroring the pattern already applied toSQL_SCALAR_ARROW_UDF(SPARK-55390) andSQL_ARROW_BATCHED_UDF(SPARK-55902). The dedicatedArrowStreamPandasUDFSerializeris no longer used by the scalar pandas path, reducing indirection and bringing the eval-type processing paths closer to a uniform structure.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing tests. No behavior change.
pyspark.sql.tests.pandas.test_pandas_udf_scalar(81 tests) plustest_pandas_udf,test_pandas_udf_typehints,test_pandas_udf_window, andtest_arrow_python_udfall pass.ASV benchmark comparison via
COLUMNS=120 asv run --python=same --bench \"ScalarPandasUDF\" --attribute \"repeat=(3,5,5.0)\":ScalarPandasUDFTimeBench - Before (master):
ScalarPandasUDFTimeBench - After (this PR):
ScalarPandasUDFPeakmemBench - Before (master):
ScalarPandasUDFPeakmemBench - After (this PR):
Summary: Latency and peak memory are essentially neutral (within run-to-run noise). The refactor reorganizes logic without changing data layout or buffering.
Was this patch authored or co-authored using generative AI tooling?
No