drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [1/2] drill git commit: DRILL-3377: Fix naming resolution error for partitioning columns when columns are explicitly specified in CTAS column list.
Date Fri, 26 Jun 2015 18:45:58 GMT
Repository: drill
Updated Branches:
  refs/heads/master 6503cfbff -> da17f2867


DRILL-3377:  Fix naming resolution error for partitioning columns when columns are explicitly
specified in CTAS column list.


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

Branch: refs/heads/master
Commit: 80270d1b687ec4cbff69fd13f1364ec77473588f
Parents: 6503cfb
Author: Jinfeng Ni <jni@apache.org>
Authored: Thu Jun 25 17:25:22 2015 -0700
Committer: Jinfeng Ni <jni@apache.org>
Committed: Thu Jun 25 22:58:05 2015 -0700

----------------------------------------------------------------------
 .../sql/handlers/CreateTableHandler.java        | 10 ++--
 .../planner/sql/handlers/DefaultSqlHandler.java |  2 +-
 .../org/apache/drill/exec/sql/TestCTAS.java     | 56 ++++++++++++++++++++
 3 files changed, 64 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/80270d1b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/CreateTableHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/CreateTableHandler.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/CreateTableHandler.java
index 6910785..5a0e40e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/CreateTableHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/CreateTableHandler.java
@@ -107,11 +107,15 @@ public class CreateTableHandler extends DefaultSqlHandler {
 
   private DrillRel convertToDrel(RelNode relNode, AbstractSchema schema, String tableName,
List<String> partitionColumns, RelDataType queryRowType)
       throws RelConversionException, SqlUnsupportedException {
-
     final DrillRel convertedRelNode = convertToDrel(relNode);
 
-    DrillWriterRel writerRel = new DrillWriterRel(convertedRelNode.getCluster(), convertedRelNode.getTraitSet(),
-        convertedRelNode, schema.createNewTable(tableName, partitionColumns));
+    // Put a non-trivial topProject to ensure the final output field name is preserved, when
necessary.
+    // Only insert project when the field count from the child is same as that of the queryRowType.
+    final DrillRel topPreservedNameProj = queryRowType.getFieldCount() == convertedRelNode.getRowType().getFieldCount()
?
+        addRenamedProject(convertedRelNode, queryRowType) : convertedRelNode;
+
+    final DrillWriterRel writerRel = new DrillWriterRel(convertedRelNode.getCluster(), convertedRelNode.getTraitSet(),
+        topPreservedNameProj, schema.createNewTable(tableName, partitionColumns));
     return new DrillScreenRel(writerRel.getCluster(), writerRel.getTraitSet(), writerRel);
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/80270d1b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
index 376fed1..e4b6643 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
@@ -473,7 +473,7 @@ public class DefaultSqlHandler extends AbstractSqlHandler {
     return rel;
   }
 
-  private DrillRel addRenamedProject(DrillRel rel, RelDataType validatedRowType) {
+  protected DrillRel addRenamedProject(DrillRel rel, RelDataType validatedRowType) {
     RelDataType t = rel.getRowType();
 
     RexBuilder b = rel.getCluster().getRexBuilder();

http://git-wip-us.apache.org/repos/asf/drill/blob/80270d1b/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 74bf0de..aec2237 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
@@ -132,6 +132,62 @@ public class TestCTAS extends BaseTestQuery {
     }
   }
 
+  @Test // DRILL-3377
+  public void partitionByCtasColList() throws Exception {
+    final String newTblName = "partitionByCtasColList";
+
+    try {
+      final String ctasQuery = String.format("CREATE TABLE %s.%s (cnt, rkey) PARTITION BY
(cnt) " +
+          "AS SELECT count(*), n_regionkey from cp.`tpch/nation.parquet` group by n_regionkey",
+          TEMP_SCHEMA, newTblName);
+
+      test(ctasQuery);
+
+      final String selectFromCreatedTable = String.format(" select cnt, rkey from %s.%s",
TEMP_SCHEMA, newTblName);
+      final String baselineQuery = "select count(*) as cnt, n_regionkey as rkey from cp.`tpch/nation.parquet`
group by n_regionkey";
+      testBuilder()
+          .sqlQuery(selectFromCreatedTable)
+          .unOrdered()
+          .sqlBaselineQuery(baselineQuery)
+          .build()
+          .run();
+    } finally {
+      FileUtils.deleteQuietly(new File(getDfsTestTmpSchemaLocation(), newTblName));
+    }
+  }
+
+  @Test // DRILL-3374
+  public void partitionByCtasFromView() throws Exception {
+    final String newTblName = "partitionByCtasColList";
+    final String newView = "partitionByCtasColListView";
+    try {
+      final String viewCreate = String.format("create or replace view %s.%s (col_int, col_varchar)
 " +
+          "AS select cast(n_nationkey as int), cast(n_name as varchar(30)) from cp.`tpch/nation.parquet`",
+          TEMP_SCHEMA, newView);
+
+      final String ctasQuery = String.format("CREATE TABLE %s.%s PARTITION BY (col_int) AS
SELECT * from %s.%s",
+          TEMP_SCHEMA, newTblName, TEMP_SCHEMA, newView);
+
+      test(viewCreate);
+      test(ctasQuery);
+
+      final String baselineQuery = "select cast(n_nationkey as int) as col_int, cast(n_name
as varchar(30)) as col_varchar " +
+        "from cp.`tpch/nation.parquet`";
+      final String selectFromCreatedTable = String.format("select col_int, col_varchar from
%s.%s", TEMP_SCHEMA, newTblName);
+      testBuilder()
+          .sqlQuery(selectFromCreatedTable)
+          .unOrdered()
+          .sqlBaselineQuery(baselineQuery)
+          .build()
+          .run();
+
+      final String viewDrop = String.format("DROP VIEW %s.%s", TEMP_SCHEMA, newView);
+      test(viewDrop);
+    } 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