[WIP][PYTHON] Zero Copy Pandas UDF #53435
Draft
+80
−3
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?
Add a config
spark.sql.execution.pandas.backend, when setpyarrow, provide pyarrow-backed Pandas Series to UDF execution.1, pre-execution arrow->pandas conversion: convert to pyarrow-backed pandas data, will be zero copy;
2, UDF execution: if the operation is compatible with pyarrow (e.g. ser -> ser + 1), then the computation result will also be pyarrow-backed; otherwise, it will fallback to a numpy-backed one (e.g. ser -> ser.apply always generate a numpy-backed ser);
3, post-execution pandas->arrow conversion: if the computation result is a pyarrow-backed instance, then the conversion will be zero copy;
Why are the changes needed?
Pandas is moving forward to pyarrow-backend, in the coming 3.0 release, it starts to use arrow-backed string type. see https://pandas.pydata.org/docs/dev/whatsnew/v3.0.0.html#dedicated-string-data-type-by-default
Does this PR introduce any user-facing change?
the config is disabled by default, but the behavior change is unknown right now
How was this patch tested?
ci
Was this patch authored or co-authored using generative AI tooling?
no