You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by ma...@apache.org on 2016/12/13 00:43:47 UTC

calcite git commit: [CALCITE-1534] Allow compound identifiers in INSERT target column list

Repository: calcite
Updated Branches:
  refs/heads/master 584432cac -> 9535efb6c


[CALCITE-1534] Allow compound identifiers in INSERT target column list


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/9535efb6
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/9535efb6
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/9535efb6

Branch: refs/heads/master
Commit: 9535efb6ce35f02ce8de7034c90def37a130fac6
Parents: 584432c
Author: maryannxue <ma...@gmail.com>
Authored: Mon Dec 12 16:43:35 2016 -0800
Committer: maryannxue <ma...@gmail.com>
Committed: Mon Dec 12 16:43:35 2016 -0800

----------------------------------------------------------------------
 core/src/main/codegen/templates/Parser.jj       | 44 ++++++++++++++++----
 .../calcite/test/SqlToRelConverterTest.java     |  4 +-
 .../apache/calcite/test/SqlValidatorTest.java   | 10 +++++
 3 files changed, 47 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/9535efb6/core/src/main/codegen/templates/Parser.jj
----------------------------------------------------------------------
diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index 26d40f4..bf03c10 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -1283,7 +1283,7 @@ SqlNode SqlInsert() :
     }
     [
         LOOKAHEAD(2)
-        columnList = ParenthesizedSimpleIdentifierList()
+        columnList = ParenthesizedCompoundIdentifierList()
     ]
     source = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY)
     {
@@ -3762,17 +3762,13 @@ SqlIdentifier SimpleIdentifier() :
 /**
  * Parses a comma-separated list of simple identifiers.
  */
-SqlNodeList SimpleIdentifierCommaList() :
+void SimpleIdentifierCommaList(List<SqlNode> list) :
 {
-    List<SqlIdentifier> list = new ArrayList<SqlIdentifier>();
     SqlIdentifier id;
 }
 {
     id = SimpleIdentifier() {list.add(id);}
     (<COMMA> id = SimpleIdentifier() {list.add(id);}) *
-    {
-        return new SqlNodeList(list, getPos());
-    }
 }
 
 /**
@@ -3782,14 +3778,14 @@ SqlNodeList SimpleIdentifierCommaList() :
 SqlNodeList ParenthesizedSimpleIdentifierList() :
 {
     SqlParserPos pos;
-    SqlNodeList list;
+    List<SqlNode> list = new ArrayList<SqlNode>();
 }
 {
     <LPAREN> { pos = getPos(); }
-    list = SimpleIdentifierCommaList()
+    SimpleIdentifierCommaList(list)
     <RPAREN>
     {
-        return list.clone(pos.plus(getPos()));
+        return new SqlNodeList(list, pos.plus(getPos()));
     }
 }
 
@@ -3833,6 +3829,36 @@ SqlIdentifier CompoundIdentifier() :
         return new SqlIdentifier(list, null, pos, posList);
     }
 }
+
+/**
+ * Parses a comma-separated list of compound identifiers.
+ */
+void CompoundIdentifierCommaList(List<SqlNode> list) :
+{
+    SqlIdentifier id;
+}
+{
+    id = CompoundIdentifier() {list.add(id);}
+    (<COMMA> id = CompoundIdentifier() {list.add(id);}) *
+}
+
+/**
+  * List of compound identifiers in parentheses. The position extends from the
+  * open parenthesis to the close parenthesis.
+  */
+SqlNodeList ParenthesizedCompoundIdentifierList() :
+{
+    SqlParserPos pos;
+    List<SqlNode> list = new ArrayList<SqlNode>();
+}
+{
+    <LPAREN> { pos = getPos(); }
+    CompoundIdentifierCommaList(list)
+    <RPAREN>
+    {
+        return new SqlNodeList(list, pos.plus(getPos()));
+    }
+}
 <#else>
   <#include "/@includes/compoundIdentifier.ftl" />
 </#if>

http://git-wip-us.apache.org/repos/asf/calcite/blob/9535efb6/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index 24f3294..4317b7d 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1521,12 +1521,12 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
   }
 
   @Test public void testInsertWithCustomColumnResolving2() {
-    final String sql = "insert into struct.t (c0, c2, c1) values (?, ?, ?)";
+    final String sql = "insert into struct.t (f0.c0, f1.c2, c1) values (?, ?, ?)";
     sql(sql).ok();
   }
 
   @Test public void testInsertViewWithCustomColumnResolving() {
-    final String sql = "insert into struct.t_10 (c0, c2, c1) values (?, ?, ?)";
+    final String sql = "insert into struct.t_10 (f0.c0, f1.c2, c1) values (?, ?, ?)";
     sql(sql).ok();
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/9535efb6/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
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 881da12..78377f8 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -7986,10 +7986,20 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
         "RecordType(INTEGER ?0, INTEGER ?1, VARCHAR(20) ?2)";
     sql(sql2).ok().bindType(expected2);
 
+    final String sql3 =
+        "insert into struct.t (f1.c0, f1.c2, f0.c1) values (?, ?, ?)";
+    final String expected3 =
+        "RecordType(INTEGER ?0, INTEGER ?1, INTEGER ?2)";
+    sql(sql3).ok().bindType(expected3);
+
     sql("insert into struct.t (c0, ^c4^, c1) values (?, ?, ?)")
         .fails("Unknown target column 'C4'");
     sql("insert into struct.t (^a0^, c2, c1) values (?, ?, ?)")
         .fails("Unknown target column 'A0'");
+    sql("insert into struct.t (f1.c0, ^f0.a0^, f0.c1) values (?, ?, ?)")
+        .fails("Unknown target column 'F0.A0'");
+    sql("insert into struct.t (f1.c0, f1.c2, ^f1.c0^) values (?, ?, ?)")
+        .fails("Target column '\"F1\".\"C0\"' is assigned more than once");
   }
 
   @Test public void testUpdateBind() {