-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add plugable handler for CREATE FUNCTION
#9333
Conversation
CREATE FUNCTION
Drop function will be added as well |
Hi @milenkovicm -- I plan to review this PR shortly |
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 for this PR @milenkovicm -- I think the idea and the PR is really neat and the code was easy to follow. ❤️
I left some API suggestions, and comments in regards to your questions. Let me know what you think.
datafusion/core/tests/sql/sql_api.rs
Outdated
@@ -39,6 +52,99 @@ async fn unsupported_ddl_returns_error() { | |||
ctx.sql_with_options(sql, options).await.unwrap(); | |||
} | |||
|
|||
struct MockFunctionFactory; |
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.
This is very cool -- I think it would be great (as a follow on PR) if we turned this into an example (with docs, etc like the others in https://github.com/apache/arrow-datafusion/tree/main/datafusion-examples/examples)
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.
Right, this functionality looks important and definitely needs to be covered with docs, examples in following PR, looking forward for it
Comments totally make sense thanks @alamb, |
Items to follow up (new issues or discussion)
|
b9bf00e
to
acdb4b5
Compare
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.
Looking very 👨🍳 👌 nice @milenkovicm
datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
Outdated
Show resolved
Hide resolved
25206aa
to
45c7edb
Compare
0b93b6a
to
a1d75a5
Compare
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 @milenkovicm -- I think this PR is almost good to go from my perspective. I had a few minor comments, but nothing major.
I think we should have at least one other maintainer give it a look. Perhaps @comphead or @universalmind303 ?
One interesting implication of this feature is that once we migrate all functions to be "udfs" (e.g. #8045) it means we can now drop functions that weren't explicitly made with CREATE FUNCTION
For example, on this branch I can drop the abs
function:
DataFusion CLI v36.0.0
❯ DROP FUNCTION abs;
0 rows in set. Query took 0.009 seconds.
Although I do get an appropriate error when I try to drop a function that is still a BuiltInScalarFunction
like add
:
❯ DROP FUNCTION add;
Execution error: Function does not exist
People could
datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
Outdated
Show resolved
Hide resolved
datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
Outdated
Show resolved
Hide resolved
datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
Outdated
Show resolved
Hide resolved
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 @milenkovicm -- the only thing left from my perspective is to "error on multi-part identifiers" which I think we could do as a follow on PR if needed.
However, I do think we should leave this open for a few more days to let other people have a chance to comment on it before we merge.
Thanks again. This is a really neat feature that I think will let people build all sorts of cool things using DataFusion 🙏
@alamb multi-part identifiers fixed as well, please have a look. also, can you please let me know once new version of thanks a lot for all your help |
and please squash commit on merge, thanks |
Yes, this will be done (as on all commits) |
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 @milenkovicm
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 @milenkovicm
I would say it is nice to get also tests what will happen if the function is invalid/not compilable or something
another question if function can call another function?
Thanks for your comments @comphead , |
Its great to have a test with invalid function, the function which is not parseable or compilable. And the next question if the user created functions |
... `DROP FUNCTION` will look for function name in all available registries (udf, udaf, udwf). `remove` may be necessary if UDaF and UDwF do not get `simplify` method from apache#9304.
FunctionDefinition already exists, DefinitionStatement makes more sense.
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
…ns.rs Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
f17a50f
to
383602c
Compare
... as `create function` gets support in latest sqlparser.
I merged up from main to pick up a fix for the CI (I hope 🤞 ) |
Thanks @alamb |
Merged up from main again to resolve conflicts |
Thanks again @milenkovicm -- this is a pretty epic feature |
Which issue does this PR close?
Closes #9332.
Rationale for this change
explained in #9332
What changes are included in this PR?
this is minimum viable product, with some open question which i hope to resolve in the process of PR review (note TODOs)
Are these changes tested?
There is a test in place but would add more if community aggress to accept the change.
Usage example can be found at https://github.com/milenkovicm/torchfusion
Are there any user-facing changes?
There are using facing changes, but they are backward compatible. Would update docs if community aggress to accept the change.
A problem I see is from perspective of user experience, as generic parser does not support
CREATE FUNCTION
statement, user should change parser configuration toPostgreSQL
. Maybe it would make sense after this change is merged addingCREATE FUNCTION
to generic flavour