-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: add support for executing simple UDFs #85674
Conversation
2b1e650
to
4759880
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.
Nice work! No comments :)
Reviewed 1 of 1 files at r1, 3 of 3 files at r2, 19 of 19 files at r3, 6 of 6 files at r4, 9 of 9 files at r5, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @msirek, and @rytaft)
pkg/sql/sem/tree/routine.go
line 45 at r3 (raw file):
} // NewTypedRoutineExpr returns a new RoutineExpr the is well-typed.
nit: probably s/the is/that is/
.
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @mgartner, @msirek, and @rytaft)
pkg/sql/logictest/testdata/logic_test/udf
line 293 at r5 (raw file):
query III colnames SELECT *, one() FROM ab WHERE a = one()
[nit] Is it possible to use a udf as a table source right now? If so, that case could use a test.
Release note: None
Release note: None
This commit adds basic support for executing single-statement, zero-argument, scalar user-defined functions. It sets up some basic components that are needed. There's quite a few TODOs scattered throughout the commit that will be addressed in future commits. Evaluation of a UDF is performed similarly to the execution of apply-joins. During the execbuilder phase, a `tree.RoutineExpr` is created to represent the invocation of a UDF. This expression contains a closure that can generate an optimized plan for each statement in the UDF body. During evaluation, a plan is generated and executed for each statement sequentially (however, only a single-statement is currently supported). The results of the last statement are returned as the result. Release note: None
The optimizer now creates required properties that are used when optimizing each statement in a body UDF during evaluation of the UDF. These props must be used to ensure that properties such as ordering and presentation are maintained during optimization. Release note: None
All statements in a UDF body are now executed when a UDF is evaluated. Release note: None
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball, @msirek, and @rytaft)
pkg/sql/logictest/testdata/logic_test/udf
line 293 at r5 (raw file):
Previously, DrewKimball (Drew Kimball) wrote…
[nit] Is it possible to use a udf as a table source right now? If so, that case could use a test.
Good catch! Done.
pkg/sql/sem/tree/routine.go
line 45 at r3 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit: probably
s/the is/that is/
.
Done.
4759880
to
1665a0d
Compare
TFTRs! bors r+ |
Build failed (retrying...): |
Build succeeded: |
opt: fix outdated comment in execbuilder
Release note: None
sql: add helpful eval_gen instructions
Release note: None
sql: add support for executing simple UDFs
This commit adds basic support for executing single-statement,
zero-argument, scalar user-defined functions. It sets up some basic
components that are needed. There's quite a few TODOs scattered
throughout the commit that will be addressed in future commits.
Evaluation of a UDF is performed similarly to the execution of
apply-joins. During the execbuilder phase, a
tree.RoutineExpr
iscreated to represent the invocation of a UDF. This expression contains a
closure that can generate an optimized plan for each statement in the
UDF body. During evaluation, a plan is generated and executed for each
statement sequentially (however, only a single-statement is currently
supported). The results of the last statement are returned as the
result.
Release note: None
opt: fully optimize statements in UDFs
The optimizer now creates required properties that are used when
optimizing each statement in a body UDF during evaluation of the UDF.
These props must be used to ensure that properties such as ordering and
presentation are maintained during optimization.
Release note: None
sql: execute all statements in a UDF during evaluation
All statements in a UDF body are now executed when a UDF is evaluated.
Release note: None