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

jhyde pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit fc792668047014beb39a012746bb94acde0d98e5
Author: Niels Pardon <[email protected]>
AuthorDate: Wed Sep 11 08:19:07 2024 +0200

    [CALCITE-6576] In SET clause of UPDATE statement, allow column identifiers 
to be prefixed with table alias
    
    For example, in the following query 'e' is a table alias and
    'e.deptno' is the column name prefixed with the table alias.
    Previously only 'deptno' was allowed.
    
      UPDATE emp AS e
        SET e.deptno = 20;
    
    A follow-up case, [CALCITE-6584], will implement this in the
    validator.
    
    Signed-off-by: Niels Pardon <[email protected]>
    Close apache/calcite#3959
---
 core/src/main/codegen/templates/Parser.jj                 |  4 ++--
 .../java/org/apache/calcite/sql/parser/SqlParserTest.java | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/core/src/main/codegen/templates/Parser.jj 
b/core/src/main/codegen/templates/Parser.jj
index 216c3e0b02..8e854ce3fa 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -1820,14 +1820,14 @@ SqlNode SqlUpdate() :
     ( tableRef = TableHints(tableName) | { tableRef = tableName; } )
     [ tableRef = ExtendTable(tableRef) ]
     ( [ <AS> ] alias = SimpleIdentifier() | { alias = null; } )
-    <SET> id = SimpleIdentifier() {
+    <SET> id = CompoundIdentifier() {
         targetColumnList.add(id);
     }
     // TODO:  support DEFAULT also
     <EQ> AddExpression(sourceExpressionList, ExprContext.ACCEPT_SUB_QUERY)
     (
         <COMMA>
-        id = SimpleIdentifier() { targetColumnList.add(id); }
+        id = CompoundIdentifier() { targetColumnList.add(id); }
         <EQ> AddExpression(sourceExpressionList, ExprContext.ACCEPT_SUB_QUERY)
     )*
     ( where = Where() | { where = null; } )
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 cfab89aa68..f2eb0175bb 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
@@ -5102,6 +5102,21 @@ public class SqlParserTest {
             + "WHERE (`EMPNO` = 12)");
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6576";>[CALCITE-6576]
+   * In SET clause of UPDATE statement, allow column identifiers to be prefixed
+   * with table alias</a>. */
+  @Test void testUpdateTableAlias() {
+    final String sql = "UPDATE mytable AS t SET t.ID=1";
+    final String expected = "UPDATE `MYTABLE` AS `T` SET `T`.`ID` = 1";
+    sql(sql).ok(expected);
+
+    final String sql2 = "UPDATE scott.mytable SET scott.mytable.ID=1";
+    final String expected2 =
+        "UPDATE `SCOTT`.`MYTABLE` SET `SCOTT`.`MYTABLE`.`ID` = 1";
+    sql(sql2).ok(expected2);
+  }
+
   @Test void testMergeSelectSource() {
     final String sql = "merge into emps e "
         + "using (select * from tempemps where deptno is null) t "

Reply via email to