drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject drill git commit: DRILL-3373: Raise parsing error when CTAS has partition by clause yet partitioning column list is empty.
Date Thu, 25 Jun 2015 23:55:21 GMT
Repository: drill
Updated Branches:
  refs/heads/master 4f9ad493e -> 25977105f


DRILL-3373: Raise parsing error when CTAS has partition by clause yet partitioning column
list is empty.


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

Branch: refs/heads/master
Commit: 25977105ffb72b51b362fa592936aeac40906383
Parents: 4f9ad49
Author: Jinfeng Ni <jni@apache.org>
Authored: Wed Jun 24 16:10:55 2015 -0700
Committer: Jinfeng Ni <jni@apache.org>
Committed: Thu Jun 25 14:20:38 2015 -0700

----------------------------------------------------------------------
 .../src/main/codegen/includes/parserImpls.ftl   | 28 ++++++++++++++------
 .../org/apache/drill/exec/sql/TestCTAS.java     | 14 ++++++++++
 2 files changed, 34 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/25977105/exec/java-exec/src/main/codegen/includes/parserImpls.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/includes/parserImpls.ftl b/exec/java-exec/src/main/codegen/includes/parserImpls.ftl
index eedba99..b1c22f2 100644
--- a/exec/java-exec/src/main/codegen/includes/parserImpls.ftl
+++ b/exec/java-exec/src/main/codegen/includes/parserImpls.ftl
@@ -136,7 +136,23 @@ SqlNode SqlUseSchema():
 }
 
 /** Parses an optional field list and makes sure no field is a "*". */
-SqlNodeList ParseFieldList(String relType) :
+SqlNodeList ParseOptionalFieldList(String relType) :
+{
+    SqlNodeList fieldList;
+}
+{
+    fieldList = ParseRequiredFieldList(relType)
+    {
+        return fieldList;
+    }
+    |
+    {
+        return SqlNodeList.EMPTY;
+    }
+}
+
+/** Parses a required field list and makes sure no field is a "*". */
+SqlNodeList ParseRequiredFieldList(String relType) :
 {
     SqlNodeList fieldList;
 }
@@ -152,10 +168,6 @@ SqlNodeList ParseFieldList(String relType) :
         }
         return fieldList;
     }
-    |
-    {
-        return SqlNodeList.EMPTY;
-    }
 }
 
 /**
@@ -175,7 +187,7 @@ SqlNode SqlCreateOrReplaceView() :
     [ <OR> <REPLACE> { replaceView = true; } ]
     <VIEW>
     viewName = CompoundIdentifier()
-    fieldList = ParseFieldList("View")
+    fieldList = ParseOptionalFieldList("View")
     <AS>
     query = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY)
     {
@@ -218,9 +230,9 @@ SqlNode SqlCreateTable() :
     <CREATE> { pos = getPos(); }
     <TABLE>
     tblName = CompoundIdentifier()
-    fieldList = ParseFieldList("Table")
+    fieldList = ParseOptionalFieldList("Table")
     (   <PARTITION> <BY>
-        partitionFieldList = ParseFieldList("Partition")
+        partitionFieldList = ParseRequiredFieldList("Partition")
     )?
     <AS>
     query = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY)

http://git-wip-us.apache.org/repos/asf/drill/blob/25977105/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTAS.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTAS.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTAS.java
index c4cc37a..74bf0de 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTAS.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTAS.java
@@ -118,6 +118,20 @@ public class TestCTAS extends BaseTestQuery {
     }
   }
 
+  @Test
+  public void ctasPartitionWithEmptyList() throws Exception {
+    final String newTblName = "ctasPartitionWithEmptyList";
+
+    try {
+      final String ctasQuery = String.format("CREATE TABLE %s.%s PARTITION BY AS SELECT *
from cp.`region.json`", TEMP_SCHEMA, newTblName);
+
+      errorMsgTestHelper(ctasQuery,
+          String.format("PARSE ERROR: Encountered \"AS\""));
+    } finally {
+      FileUtils.deleteQuietly(new File(getDfsTestTmpSchemaLocation(), newTblName));
+    }
+  }
+
   private static void ctasErrorTestHelper(final String ctasSql, final String expErrorMsg)
throws Exception {
     final String createTableSql = String.format(ctasSql, TEMP_SCHEMA, "testTableName");
     errorMsgTestHelper(createTableSql, expErrorMsg);


Mime
View raw message