-
Notifications
You must be signed in to change notification settings - Fork 78
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
docs: Example of calling Python UDF & UDAF in SQL #258
Conversation
@@ -190,7 +190,7 @@ def udaf(accum, input_type, return_type, state_type, volatility, name=None): | |||
"`accum` must implement the abstract base class Accumulator" | |||
) | |||
if name is None: | |||
name = accum.__qualname__ | |||
name = accum.__qualname__.lower() |
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.
Previously calling the UDAF in SQL would fail if name
is not specified (i.e. both MyAccumulator(b)
and myaccumulator(b)
would fail when running e.g. result_df = ctx.sql(f"select a, myaccumulator(b) as b_aggregated from {table_name}")
). With this change both the uppercase & lowercase variant will work.
# Query the DataFrame using SQL | ||
table_name = ctx.catalog().database().names().pop() | ||
result_df = ctx.sql( | ||
f"select a, my_accumulator(b) as b_aggregated from {table_name} group by a order by a" | ||
) |
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.
Here it would be nice if the table name can be set in the from...
context functions so table_name is known, have created ticket #259 as follow-up task
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.
Thank you @simicd 🙏
Which issue does this PR close?
Closes #138
Rationale for this change
Document how to utilize Python UDFs & UDAFs in SQL
What changes are included in this PR?
Document examples & link in README.md
Are there any user-facing changes?
Additional examples/documentation