-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[CALCITE-1581] Support UDTF like Hive #2092
base: main
Are you sure you want to change the base?
Conversation
This PR comes from #2092 with some fixups. Besides, It is already reviewed by some members. I think it is good overall. |
core/src/main/java/org/apache/calcite/sql/validate/SqlConformance.java
Outdated
Show resolved
Hide resolved
LogicalProject(F0=[$2], F1=[$3]) | ||
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{0}]) | ||
LogicalTableScan(table=[[CATALOG, SALES, DEPT]]) | ||
LogicalTableFunctionScan(invocation=[TABLE_FUNC($cor0.DEPTNO)], rowType=[RecordType(BIGINT f0, VARCHAR f1)], elementType=[class [Ljava.lang.Object;]) |
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.
The plan is not correct, there is no need to translate as a LogicalCorrelate
, the LogicalTableFunctionScan
inputs need to be set correctly.
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 am not sure whether it should use LogicalCorrelate
or not. Some existed examples use LogicalCorrelate
[1]. Any suggestion, @julianhyde ?
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 LoggicalCorrelate
is the right thing. This is a function that RETURNS a table on each invocation but its arguments are scalars, and the scalars are correlating variables.
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.
If we just select from a function using select * from func
, i think there is no need to translate into a LoggicalCorrelate
, because usually a LoggicalCorrelate
would be decorrelated into a Join
, can we elaborate the LogicalTableFunctionScan
inputs to specify the input table and function's argument as an input ref
?
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.
When would we have select * from func
? We only have select func(a, b) as (a. b) from t
. If I am wrong, correct me please.
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.
For query select func(a, b) as (a. b) from t
, we can generate a LogicalTableFunctionScan
directly instead of a Correlate
plus a right project.
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.
OK. I would like to see if we can make it.
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
Show resolved
Hide resolved
62ee42f
to
da5fe76
Compare
8a5cf83
to
cf7f71b
Compare
hi @chunweilei , when time to merge this pull request. I think UDTF is useful feature for SQL . Thanks a lot |
The codebase has changed significantly in the last 4 years since this PR was submitted, so some work will be needed to rebase this. I agree it would be a useful feature to have. Note that Calcite does support table functions, but they are invoked with the TABLE syntax: https://calcite.apache.org/docs/reference.html#table-functions |
OK, I use |
Close #1138