Skip to content

[CALCITE-7688] Support scalar subqueries in table function arguments - #5144

Merged
mihaibudiu merged 1 commit into
apache:mainfrom
tkalkirill:calcite-7688
Aug 7, 2026
Merged

[CALCITE-7688] Support scalar subqueries in table function arguments#5144
mihaibudiu merged 1 commit into
apache:mainfrom
tkalkirill:calcite-7688

Conversation

@tkalkirill

Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7688

Changes Proposed

This PR introduces support for scalar subqueries and expressions containing scalar subqueries in table function arguments:

SELECT * FROM TABLE(my_function((SELECT value FROM t), 1));

SELECT * FROM TABLE(my_function((SELECT 4) + (SELECT 6), 1));

SELECT *
FROM person p
CROSS JOIN LATERAL TABLE(
  my_function((SELECT p.id + 1), p.id)
);

@mihaibudiu

Copy link
Copy Markdown
Contributor

the commit message is not ideal.
Is this work in progress, or is it ready for review?

@tkalkirill

Copy link
Copy Markdown
Contributor Author

@mihaibudiu It's a habit from the IGNITE project, where they don't pay as much attention to commit messages. It's ready for review, could you take a look?

@mihaibudiu

Copy link
Copy Markdown
Contributor

I will review, but to merge this you will have to use the same commit message as the JIRA issue title.

@mihaibudiu mihaibudiu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure that the interpreter module is being actively maintained or complete. Some of the changes in this PR seem not directly related to the actual JIRA issue 7688. The SubQueryRemoveRule is what should be the focus of this PR.

If you want to bring the interpreter up-to-date, please check for JIRA issues related to that or file new ones and submit that part of the work as separate PRs.

Comment thread core/src/main/java/org/apache/calcite/interpreter/Nodes.java Outdated
Comment thread core/src/main/java/org/apache/calcite/interpreter/AggregateNode.java Outdated
@tkalkirill
tkalkirill requested a review from mihaibudiu August 5, 2026 13:48

@mihaibudiu mihaibudiu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This generally looks fine

"row_name=row 2; c1=103; c2=106");
}

@Test void testTableFunctionWithScalarQueryLiteralAndColumnArguments() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I hope that you have validated these results in some way.
Maybe you can say how.
Ideally you wrote a test oracle (a separate program) which verified these results.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I validated the expected results independently against Oracle using a standalone PL/SQL test oracle https://onecompiler.com/plsql/44xe3ubj8. The program defines a pipelined table function and invokes it with the same scalar subquery, literal, and correlated outer-column arguments. Oracle produced (100, 10, 20, 100) and (200, 10, 20, 200), which matches the test expectations.
Or did you mean something else?

public static final Method MULTIPLICATION_TABLE_METHOD =
Types.lookupMethod(Smalls.class, "multiplicationTable", int.class,
int.class, Integer.class);
public static final Method SCALAR_QUERY_ARGUMENTS_TABLE_METHOD =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder why this file is named Smalls.java.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Smalls like teen spirit.

Comment thread core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java Outdated
@tkalkirill
tkalkirill requested a review from mihaibudiu August 6, 2026 14:49
@mihaibudiu mihaibudiu added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Aug 7, 2026
@mihaibudiu

Copy link
Copy Markdown
Contributor

Please squash the commits for merging

@tkalkirill

Copy link
Copy Markdown
Contributor Author

@mihaibudiu Done.

@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@mihaibudiu
mihaibudiu merged commit a2a973e into apache:main Aug 7, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants