Skip to content
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

Support user defined function #3655

Merged
merged 26 commits into from Dec 27, 2021
Merged

Conversation

lianghanzhen
Copy link
Contributor

@lianghanzhen lianghanzhen commented Dec 26, 2021

I hereby agree to the terms of the CLA available at: https://databend.rs/policies/cla/

Summary

Support user defined function

  • All UDFs will be stored in meta KV store like user stages.
  • UDFs will be verified before stored which they must be: a) Not builtin scalar or aggregate functions; b) Params must match format @\d+ and starts with @0; c) Params much be continuous, such as @0, @1, @2; d) The order of params doesn't matter; e) Params are repeatable;
  • UDFs will be transformed into the combination of builtin scalar and aggregate functions in analyze_expr phase;
  • CREATE/DROP/SHOW function is supported;

Examples are available in stateless tests.

Changelog

  • New Feature

Related Issues

Fixes #3440

Test Plan

Unit Tests

Stateless Tests

@databend-bot databend-bot added pr-feature this PR introduces a new feature to the codebase labels Dec 26, 2021
@databend-bot
Copy link
Member

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

1 similar comment
@databend-bot
Copy link
Member

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@vercel
Copy link

vercel bot commented Dec 26, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/databend/databend/GQjLtYjJZivc7tVCNCN6AYzjiFym
✅ Preview: Canceled

[Deployment for 25e29b8 canceled]

@lianghanzhen
Copy link
Contributor Author

@BohuTANG The stateless test of 05_0012_ddl_show_udf failed, but I couldn't figure out why.

Output diff:

@@ -1 +1 @@
-isnotempty     not(isnull(@0)) This is a description
+isnotempty     not(isnull(@0)) This is a description

@BohuTANG
Copy link
Member

BohuTANG commented Dec 27, 2021

@BohuTANG The stateless test of 05_0012_ddl_show_udf failed, but I couldn't figure out why.

Output diff:

@@ -1 +1 @@	
-isnotempty     not(isnull(@0)) This is a description
+isnotempty     not(isnull(@0)) This is a description

isnotempty not(isnull(@0)) This is a description -- The result should be a tab not 4 blanks :)

image

@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2021

Codecov Report

Merging #3655 (25e29b8) into main (4f30a6b) will increase coverage by 0%.
The diff coverage is 62%.

Impacted file tree graph

@@          Coverage Diff           @@
##            main   #3655    +/-   ##
======================================
  Coverage     60%     60%            
======================================
  Files        678     694    +16     
  Lines      36484   37116   +632     
======================================
+ Hits       21951   22393   +442     
- Misses     14533   14723   +190     
Impacted Files Coverage Δ
common/planners/src/plan_node.rs 41% <0%> (-3%) ⬇️
common/planners/src/plan_rewriter.rs 43% <0%> (-1%) ⬇️
query/src/interpreters/interpreter_factory.rs 32% <0%> (-3%) ⬇️
query/src/sql/sql_statement.rs 31% <0%> (-2%) ⬇️
common/functions/src/udfs/udf_transformer.rs 24% <24%> (ø)
common/planners/src/plan_user_udf_show.rs 33% <33%> (ø)
query/src/users/user_api.rs 44% <33%> (-6%) ⬇️
common/sql/src/expr/expr_visitor.rs 63% <63%> (ø)
query/src/sql/statements/analyzer_expr.rs 68% <64%> (+2%) ⬆️
query/src/sql/statements/statement_create_udf.rs 66% <66%> (ø)
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2be8994...25e29b8. Read the comment docs.

@sundy-li sundy-li requested a review from zhyass December 27, 2021 05:00
@sundy-li
Copy link
Member

Awesome, really surprised me that this pr can be landed in such a swift speed.

str_expr,
} => self.visit_position(substr_expr, str_expr),
Expr::Value(value) => {
self.rpn.push(ExprRPNItem::Value(value.clone()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's much better now, no extra function call.

@databend-bot
Copy link
Member

Wait for another reviewer approval

Comment on lines +1570 to +1577
[[package]]
name = "common-sql"
version = "0.1.0"
dependencies = [
"common-exception",
"sqlparser",
]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this crate only involves expr_visitor, what about rename it to common-ast? Since the name common-sql looks too common.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion about the naming, I will rename it in other MR.

@BohuTANG
Copy link
Member

Great job, let's merge!
Thank you @lianghanzhen !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-review pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support user defined functions
6 participants