-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Document] Adding UDF by impl ScalarUDFImpl #9172
Conversation
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.
create_udf
will use SimpleScalarUDF::new
, which is not deprecated. The deprecated one is ScalarUDF::new
, sorry for my previous wrong understanding.
https://github.com/apache/arrow-datafusion/blob/c9e4b7b7c5c2c2e7b3ea01040a6edeafd151410c/datafusion/expr/src/expr_fn.rs#L982-L996
|
||
To register a Scalar UDF, you need to wrap the function implementation in a [`ScalarUDF`] struct and then register it with the `SessionContext`. | ||
DataFusion provides the [`create_udf`] and helper functions to make this easier. | ||
There is a lower level API with more functionality but is more complex, that is documented in [`advanced_udf.rs`]. |
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.
I doubt a little that whether my PR is necessary, it seems that there's already a updated link that helps user create scalarUDF by impl trait
. 🤔 What do you think ? @alamb
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.
I think the value of this library guide is the surrounding text, so it seems ok to me to have the code replicated in two places
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.
|
||
To register a Scalar UDF, you need to wrap the function implementation in a [`ScalarUDF`] struct and then register it with the `SessionContext`. | ||
DataFusion provides the [`create_udf`] and helper functions to make this easier. | ||
There is a lower level API with more functionality but is more complex, that is documented in [`advanced_udf.rs`]. |
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.
I think the value of this library guide is the surrounding text, so it seems ok to me to have the code replicated in two places
Ok(Arc::new(new_array)) | ||
} | ||
} | ||
|
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.
I suggest ending the first code block here and then adding a sentence:
We now need to register the function with DataFusion so that it can be used in the context of a query.
(then rest of the example)
Co-authored-by: Andrew Lamb <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
Thanks for your review! @alamb and have applied the suggestions. |
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.
Thanks again @yyy1000
Which issue does this PR close?
Closes #9136.
Rationale for this change
See #9136
What changes are included in this PR?
Document update including adding a scalar udf by
impl ScalarUDFImpl