This is an automated email from the ASF dual-hosted git repository.
mihaibudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new a05b05e7e9 [CALCITE-7732] Make the TABLE keyword optional for table
function calls in LATERAL context
a05b05e7e9 is described below
commit a05b05e7e9be77c7ed8c2e869975718a0b43765c
Author: darpan-14 <[email protected]>
AuthorDate: Wed Aug 26 11:27:49 2026 +0530
[CALCITE-7732] Make the TABLE keyword optional for table function calls in
LATERAL context
---
core/src/main/codegen/templates/Parser.jj | 6 ++++++
core/src/test/resources/sql/lateral.iq | 9 +--------
site/_docs/reference.md | 1 +
.../org/apache/calcite/sql/parser/SqlParserTest.java | 16 ++++++++++++++--
4 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/core/src/main/codegen/templates/Parser.jj
b/core/src/main/codegen/templates/Parser.jj
index 16bf6b5e95..968c386f6c 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -2468,6 +2468,12 @@ SqlNode TableRef3(ExprContext exprContext, boolean
lateral) :
tableRef = MatchRecognize(tableRef)
]
)
+ |
+ LOOKAHEAD(<LATERAL> CompoundTableIdentifier() <LPAREN>)
+ <LATERAL> { lateral = true; }
+ tableName = CompoundTableIdentifier()
+ tableRef = ImplicitTableFunctionCallArgs(tableName)
+ tableRef = addLateral(tableRef, lateral)
|
LOOKAHEAD(2)
[ <LATERAL> { lateral = true; } ]
diff --git a/core/src/test/resources/sql/lateral.iq
b/core/src/test/resources/sql/lateral.iq
index 4c4ffbe170..12fe348741 100644
--- a/core/src/test/resources/sql/lateral.iq
+++ b/core/src/test/resources/sql/lateral.iq
@@ -20,14 +20,7 @@
# Bad: LATERAL tableName
select * from "scott".emp join lateral "scott".dept using (deptno);
-parse failed: Encountered "join lateral \"scott\"" at line 1, column 27.
-Was expecting one of:
- "AS" ...
- "CROSS" ...
- "EXTEND" ...
- "FOR" ...
- "OUTER" ...
- "TABLESAMPLE" ...
+parse failed: Encountered "\"scott\" . dept using" at line 1, column 40.
!error
# Bad: LATERAL TABLE
diff --git a/site/_docs/reference.md b/site/_docs/reference.md
index dd385a4c87..54e47d58c0 100644
--- a/site/_docs/reference.md
+++ b/site/_docs/reference.md
@@ -307,6 +307,7 @@ ## Grammar
| tablePrimary [ hintComment ] [ EXTEND ] '(' columnDecl [, columnDecl ]*
')'
| [ LATERAL ] '(' query ')'
| UNNEST '(' expression ')' [ WITH ORDINALITY ]
+ | [ LATERAL ] functionName '(' expression [, expression ]* ')'
| [ LATERAL ] TABLE '(' [ SPECIFIC ] functionName '(' expression [,
expression ]* ')' ')'
columnDecl:
diff --git
a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
index a64edcd6fb..68c14a73b7 100644
--- a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -4881,7 +4881,7 @@ void checkPeriodPredicate(Checker checker) {
@Test void testLateral() {
// Bad: LATERAL table
sql("select * from lateral ^emp^")
- .fails("(?s)Encountered \"emp\" at .*");
+ .fails("(?s)Encountered \"emp <EOF>\" at .*");
sql("select * from lateral table ^emp^ as e")
.fails("(?s)Encountered \"emp\" at .*");
@@ -4925,7 +4925,8 @@ void checkPeriodPredicate(Checker checker) {
// Can not use explicit LATERAL keyword.
final String sql1 = "select stream * from orders, LATERAL
^products_temporal^\n"
+ "for system_time as of TIMESTAMP '2011-01-02 00:00:00'";
- final String error = "(?s)Encountered \"products_temporal\" at line .*";
+ final String error =
+ "(?s)Encountered \"products_temporal for\" at line .*";
sql(sql1).fails(error);
// Inner join with a specific timestamp
@@ -5032,6 +5033,17 @@ void checkPeriodPredicate(Checker checker) {
sql(sql).ok(expected);
}
+ @Test void testLateralTableFunctionWithoutTableWrapper() {
+ sql("select * from dept, lateral ramp(dept.deptno) as r(v)")
+ .ok("SELECT *\n"
+ + "FROM `DEPT`,\n"
+ + "LATERAL TABLE(`RAMP`(`DEPT`.`DEPTNO`)) AS `R` (`V`)");
+ sql("select * from dept, lateral s.ramp(dept.deptno) as r(v)")
+ .ok("SELECT *\n"
+ + "FROM `DEPT`,\n"
+ + "LATERAL TABLE(`S`.`RAMP`(`DEPT`.`DEPTNO`)) AS `R` (`V`)");
+ }
+
@Test void testTableFunctionWithPartitionKey() {
// test one partition key for input table
final String sql = "select * from table(topn(table orders partition by
productid, 3))";