-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-43082][CONNECT][PYTHON] Arrow-optimized Python UDFs in Spark Connect #40725
Conversation
python/pyspark/sql/udf.py
Outdated
else: | ||
return regular_udf | ||
|
||
|
||
def _create_arrow_py_udf(f, regular_udf): # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring the type annotations of _create_arrow_py_udf
because it is shared between vanilla PySpark and Spark Connect Python Client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is only an extraction of original code L142 - L179 for code reuse.
else useArrow | ||
) | ||
|
||
regular_udf = _create_udf(f, returnType, evalType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is duplicated code in _create_py_udf
between Spark Connect Python Client and vanilla PySpark, except for fetching the active SparkSession.
However, for a clear code path separation and abstraction, I decided not to refactor it for now.
CI failed because of
|
95cad25
to
f6fc6e1
Compare
@HyukjinKwon @zhengruifeng Would you please take a look? Thank you! |
cc @ueshin FYI |
import pandas as pd | ||
from pyspark.sql.pandas.functions import _create_pandas_udf | ||
|
||
return_type = regular_udf.returnType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that the regular_udf
is only used to pass the returnType
and evalType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And regular_udf.func
based on the updated code.
python/pyspark/sql/tests/connect/test_parity_arrow_python_udf.py
Outdated
Show resolved
Hide resolved
Merged to master. |
What changes were proposed in this pull request?
Implement Arrow-optimized Python UDFs in Spark Connect.
Please see #39384 for motivation and performance improvements of Arrow-optimized Python UDFs.
Why are the changes needed?
Parity with vanilla PySpark.
Does this PR introduce any user-facing change?
Yes. In Spark Connect Python Client, users can:
useArrow
parameter True to enable Arrow optimization for a specific Python UDF.spark.sql.execution.pythonUDF.arrow.enabled
Spark Conf to make all Python UDFs Arrow-optimized.How was this patch tested?
Parity unit tests.
SPARK-40307