You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by za...@apache.org on 2019/04/30 12:47:14 UTC

[calcite] branch master updated: [CALCITE-3030] SqlParseException when using component identifier for setting in merge statements (Danny Chan)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new e3a6970  [CALCITE-3030] SqlParseException when using component identifier for setting in merge statements (Danny Chan)
e3a6970 is described below

commit e3a69708df55cf05bbe38f8f1d5bd472cf8de81f
Author: yuzhao.cyz <yu...@alibaba-inc.com>
AuthorDate: Mon Apr 29 17:31:47 2019 +0800

    [CALCITE-3030] SqlParseException when using component identifier for setting in merge statements (Danny Chan)
    
    Close apache/calcite#1190
---
 core/src/main/codegen/templates/Parser.jj          |  4 +-
 .../apache/calcite/sql/parser/SqlParserTest.java   | 44 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index 6499e4b..37e5bc5 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -1500,7 +1500,7 @@ SqlUpdate WhenMatchedClause(SqlNode table, SqlIdentifier alias) :
 }
 {
     <WHEN> { s = span(); } <MATCHED> <THEN>
-    <UPDATE> <SET> id = SimpleIdentifier() {
+    <UPDATE> <SET> id = CompoundIdentifier() {
         updateColumnList.add(id);
     }
     <EQ> exp = Expression(ExprContext.ACCEPT_SUB_QUERY) {
@@ -1508,7 +1508,7 @@ SqlUpdate WhenMatchedClause(SqlNode table, SqlIdentifier alias) :
     }
     (
         <COMMA>
-        id = SimpleIdentifier() {
+        id = CompoundIdentifier() {
             updateColumnList.add(id);
         }
         <EQ> exp = Expression(ExprContext.ACCEPT_SUB_QUERY) {
diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
index 88046f4..63b8926 100644
--- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -3791,6 +3791,29 @@ public class SqlParserTest {
         .node(not(isDdl()));
   }
 
+  /** Same as testMergeSelectSource but set with compound identifier. */
+  @Test public void testMergeSelectSource2() {
+    final String sql = "merge into emps e "
+        + "using (select * from tempemps where deptno is null) t "
+        + "on e.empno = t.empno "
+        + "when matched then update "
+        + "set e.name = t.name, e.deptno = t.deptno, e.salary = t.salary * .1 "
+        + "when not matched then insert (name, dept, salary) "
+        + "values(t.name, 10, t.salary * .15)";
+    final String expected = "MERGE INTO `EMPS` AS `E`\n"
+        + "USING (SELECT *\n"
+        + "FROM `TEMPEMPS`\n"
+        + "WHERE (`DEPTNO` IS NULL)) AS `T`\n"
+        + "ON (`E`.`EMPNO` = `T`.`EMPNO`)\n"
+        + "WHEN MATCHED THEN UPDATE SET `E`.`NAME` = `T`.`NAME`\n"
+        + ", `E`.`DEPTNO` = `T`.`DEPTNO`\n"
+        + ", `E`.`SALARY` = (`T`.`SALARY` * 0.1)\n"
+        + "WHEN NOT MATCHED THEN INSERT (`NAME`, `DEPT`, `SALARY`) "
+        + "(VALUES (ROW(`T`.`NAME`, 10, (`T`.`SALARY` * 0.15))))";
+    sql(sql).ok(expected)
+        .node(not(isDdl()));
+  }
+
   @Test public void testMergeTableRefSource() {
     check(
         "merge into emps e "
@@ -3811,6 +3834,27 @@ public class SqlParserTest {
             + "(VALUES (ROW(`T`.`NAME`, 10, (`T`.`SALARY` * 0.15))))");
   }
 
+  /** Same with testMergeTableRefSource but set with compound identifier. */
+  @Test public void testMergeTableRefSource2() {
+    check(
+        "merge into emps e "
+            + "using tempemps as t "
+            + "on e.empno = t.empno "
+            + "when matched then update "
+            + "set e.name = t.name, e.deptno = t.deptno, e.salary = t.salary * .1 "
+            + "when not matched then insert (name, dept, salary) "
+            + "values(t.name, 10, t.salary * .15)",
+
+        "MERGE INTO `EMPS` AS `E`\n"
+            + "USING `TEMPEMPS` AS `T`\n"
+            + "ON (`E`.`EMPNO` = `T`.`EMPNO`)\n"
+            + "WHEN MATCHED THEN UPDATE SET `E`.`NAME` = `T`.`NAME`\n"
+            + ", `E`.`DEPTNO` = `T`.`DEPTNO`\n"
+            + ", `E`.`SALARY` = (`T`.`SALARY` * 0.1)\n"
+            + "WHEN NOT MATCHED THEN INSERT (`NAME`, `DEPT`, `SALARY`) "
+            + "(VALUES (ROW(`T`.`NAME`, 10, (`T`.`SALARY` * 0.15))))");
+  }
+
   @Test public void testBitStringNotImplemented() {
     // Bit-string is longer part of the SQL standard. We do not support it.
     checkFails(