-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25601][PYTHON] Register Grouped aggregate UDF Vectorized UDFs for SQL Statement #22620
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,6 +298,15 @@ def register(self, name, f, returnType=None): | |
| >>> spark.sql("SELECT add_one(id) FROM range(3)").collect() # doctest: +SKIP | ||
| [Row(add_one(id)=1), Row(add_one(id)=2), Row(add_one(id)=3)] | ||
|
|
||
| >>> @pandas_udf("integer", PandasUDFType.GROUPED_AGG) # doctest: +SKIP | ||
| ... def sum_udf(v): | ||
| ... return v.sum() | ||
| ... | ||
| >>> _ = spark.udf.register("sum_udf", sum_udf) # doctest: +SKIP | ||
| >>> q = "SELECT sum_udf(v1) FROM VALUES (3, 0), (2, 0), (1, 1) tbl(v1, v2) GROUP BY v2" | ||
| >>> spark.sql(q).collect() # doctest: +SKIP | ||
| [Row(sum_udf(v1)=1), Row(sum_udf(v1)=5)] | ||
|
|
||
| .. note:: Registration for a user-defined function (case 2.) was added from | ||
| Spark 2.3.0. | ||
| """ | ||
|
|
@@ -310,9 +319,11 @@ def register(self, name, f, returnType=None): | |
| "Invalid returnType: data type can not be specified when f is" | ||
| "a user-defined function, but got %s." % returnType) | ||
| if f.evalType not in [PythonEvalType.SQL_BATCHED_UDF, | ||
| PythonEvalType.SQL_SCALAR_PANDAS_UDF]: | ||
| PythonEvalType.SQL_SCALAR_PANDAS_UDF, | ||
| PythonEvalType.SQL_GROUPED_AGG_PANDAS_UDF]: | ||
|
||
| raise ValueError( | ||
| "Invalid f: f must be either SQL_BATCHED_UDF or SQL_SCALAR_PANDAS_UDF") | ||
| "Invalid f: f must be SQL_BATCHED_UDF, SQL_SCALAR_PANDAS_UDF or " | ||
| "SQL_GROUPED_AGG_PANDAS_UDF") | ||
| register_udf = UserDefinedFunction(f.func, returnType=f.returnType, name=name, | ||
| evalType=f.evalType, | ||
| deterministic=f.deterministic) | ||
|
|
||
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.
what is the "_ =" thing here?
Uh oh!
There was an error while loading. Please reload this page.
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.
Hides the output like ...
in the doctest.
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.
Ha. I see..