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

[CALCITE-1581] Support UDTF like Hive #2092

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chunweilei
Copy link
Contributor

Close #1138

@chunweilei
Copy link
Contributor Author

This PR comes from #2092 with some fixups. Besides, It is already reviewed by some members. I think it is good overall.

@chunweilei chunweilei added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Aug 3, 2020
@danny0405 danny0405 added needs-a-final-review This patch looks good from at least one PMC or committer, but still needs a specialist final review and removed LGTM-will-merge-soon Overall PR looks OK. Only minor things left. labels Aug 4, 2020
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;])
Copy link
Contributor

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.

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 am not sure whether it should use LogicalCorrelate or not. Some existed examples use LogicalCorrelate [1]. Any suggestion, @julianhyde ?

[1] https://github.com/apache/calcite/blob/master/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml#L320

Copy link
Contributor

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.

Copy link
Contributor

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 ?

Copy link
Contributor Author

@chunweilei chunweilei Aug 17, 2020

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@MagnetoWang
Copy link

hi @chunweilei , when time to merge this pull request. I think UDTF is useful feature for SQL . Thanks a lot

@mihaibudiu
Copy link
Contributor

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

@MagnetoWang
Copy link

OK, I use lateral table (udtf(column)) as table(output1, output2) to replace select udtf(column) from table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-a-final-review This patch looks good from at least one PMC or committer, but still needs a specialist final review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants