This is an automated email from the ASF dual-hosted git repository.

snuyanzin 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 e7472d454f [CALCITE-7312] Alias is not auto generated for LATERAL TABLE
e7472d454f is described below

commit e7472d454f81bf3d86ef25709fbadd0d4892acc4
Author: Sergey Nuyanzin <[email protected]>
AuthorDate: Wed Dec 3 00:50:55 2025 +0100

    [CALCITE-7312] Alias is not auto generated for LATERAL TABLE
---
 .../apache/calcite/sql/validate/SqlValidatorImpl.java  |  5 +++--
 .../java/org/apache/calcite/test/SqlValidatorTest.java | 18 +++++++++++++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java 
b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 03e8978efb..00a02a3cc4 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -2623,8 +2623,8 @@ private SqlNode registerFrom(
 
     case LATERAL:
       SqlBasicCall sbc = (SqlBasicCall) node;
-      registerFrom(parentScope,
-          usingScope,
+      newOperand =
+          registerFrom(parentScope, usingScope,
           register,
           ((SqlCall) node).operand(0),
           enclosingNode,
@@ -2635,6 +2635,7 @@ private SqlNode registerFrom(
       // Put the usingScope which is a JoinScope,
       // in order to make visible the left items
       // of the JOIN tree.
+      sbc.setOperand(0, newOperand);
       scopes.put(node, usingScope);
       return sbc;
 
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 129261c9e9..105e428efe 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -9127,13 +9127,23 @@ void testGroupExpressionEquivalenceParams() {
 
   /** Test case for
    * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7217";>[CALCITE-7217]
-   * LATERAL is lost after validation</a>. */
+   * LATERAL is lost after validation</a> and
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7312";>[CALCITE-7312]
+   * Alias is not auto generated for LATERAL TABLE</a>.
+   * */
   @Test void testCollectionTableWithLateralRewrite() {
     sql("select * from emp, lateral table(ramp(emp.deptno)), dept")
         .rewritesTo("SELECT *\n"
             + "FROM `EMP`,\n"
             + "LATERAL TABLE(RAMP(`EMP`.`DEPTNO`)),\n"
             + "`DEPT`");
+    // SELECT 1 to save space since test is verifying alias for the case of 
LATERAL TABLE
+    sql("select 1 from emp, lateral table(ramp(emp.deptno)), dept")
+        .withValidatorIdentifierExpansion(true)
+        .rewritesTo("SELECT 1\n"
+            + "FROM `CATALOG`.`SALES`.`EMP` AS `EMP`,\n"
+            + "LATERAL TABLE(RAMP(`EMP`.`DEPTNO`)) AS `EXPR$0`,\n"
+            + "`CATALOG`.`SALES`.`DEPT` AS `DEPT`");
     // As above, with alias
     sql("select * from emp, lateral table(ramp(emp.deptno)) as t(a), dept")
         .rewritesTo("SELECT *\n"
@@ -9174,6 +9184,12 @@ void testGroupExpressionEquivalenceParams() {
         .rewritesTo("SELECT *\n"
             +  "FROM LATERAL TABLE(RAMP(1234)),\n"
             +  "`EMP`");
+    // SELECT 1 to save space since test is verifying alias for the case of 
LATERAL TABLE
+    sql("select 1 from lateral table(ramp(1234)), emp")
+        .withValidatorIdentifierExpansion(true)
+        .rewritesTo("SELECT 1\n"
+            + "FROM LATERAL TABLE(RAMP(1234)) AS `EXPR$0`,\n"
+            + "`CATALOG`.`SALES`.`EMP` AS `EMP`");
   }
 
   @Test void testCollectionTableWithCursorParam() {

Reply via email to