You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by am...@apache.org on 2015/03/17 19:29:33 UTC

[3/3] drill git commit: DRILL-2311: In ProjectRecordBatch, even if a column from incoming recordbatch does not need to be classified, the output name for this column is still ensured to be unique

DRILL-2311: In ProjectRecordBatch, even if a column from incoming recordbatch does not need to be classified, the output name for this column is still ensured to be unique


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

Branch: refs/heads/master
Commit: ae2053d2a078a40033a140f2dfaeef802a5e8254
Parents: 63bd48e
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Sun Mar 15 11:43:42 2015 -0700
Committer: Aman Sinha <as...@maprtech.com>
Committed: Tue Mar 17 11:08:50 2015 -0700

----------------------------------------------------------------------
 .../impl/project/ProjectRecordBatch.java        | 18 +++++++-
 .../org/apache/drill/TestExampleQueries.java    | 45 ++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/ae2053d2/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java
index 8f7812f..0c7a71a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/project/ProjectRecordBatch.java
@@ -319,7 +319,7 @@ public class ProjectRecordBatch extends AbstractSingleRecordBatch<Project> {
         classifyExpr(namedExpression, incoming, result);
 
         if (result.isStar) {
-          // The parameter value indicates which wildcard we are processing now
+          // The value indicates which wildcard we are processing now
           Integer value = result.prefixMap.get(result.prefix);
           if (value != null && value.intValue() == 1) {
             int k = 0;
@@ -366,6 +366,12 @@ public class ProjectRecordBatch extends AbstractSingleRecordBatch<Project> {
           }
           continue;
         }
+      } else {
+        // For the columns which do not needed to be classified,
+        // it is still necessary to ensure the output column name is unique
+        result.outputNames = Lists.newArrayList();
+        String outputName = getRef(namedExpression).getRootSegment().getPath();
+        addToResultMaps(outputName, result, true);
       }
 
       String outputName = getRef(namedExpression).getRootSegment().getPath();
@@ -510,6 +516,16 @@ public class ProjectRecordBatch extends AbstractSingleRecordBatch<Project> {
     return newName;
   }
 
+  /**
+  * Helper method to ensure unique output column names. If allowDupsWithRename is set to true, the original name
+  * will be appended with a suffix number to ensure uniqueness. Otherwise, the original column would not be renamed even
+  * even if it has been used
+  *
+  * @param origName            the original input name of the column
+  * @param result              the data structure to keep track of the used names and decide what output name should be
+  *                            to ensure uniqueness
+  * @Param allowDupsWithRename if the original name has been used, is renaming allowed to ensure output name unique
+  */
   private void addToResultMaps(String origName, ClassifierResult result, boolean allowDupsWithRename) {
     String name = origName;
     if (allowDupsWithRename) {

http://git-wip-us.apache.org/repos/asf/drill/blob/ae2053d2/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
index 8ae0ae4..d2d97f8 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
@@ -27,6 +27,8 @@ import org.apache.drill.exec.planner.physical.PlannerSettings;
 import org.junit.Ignore;
 import org.junit.Test;
 
+import java.math.BigDecimal;
+
 public class TestExampleQueries extends BaseTestQuery{
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestExampleQueries.class);
 
@@ -691,4 +693,47 @@ public class TestExampleQueries extends BaseTestQuery{
 
     test("alter session set `planner.slice_target` = " + ExecConstants.SLICE_TARGET_DEFAULT);
   }
+
+  @Test // DRILL-2311
+  public void testCreateTableSameColumnNames() throws Exception {
+    String creatTable = "CREATE TABLE CaseInsensitiveColumnNames as " +
+        "select cast(r_regionkey as BIGINT) BIGINT_col, cast(r_regionkey as DECIMAL) bigint_col \n" +
+        "FROM cp.`tpch/region.parquet`;\n";
+
+    test("USE dfs.tmp");
+    test(creatTable);
+
+    testBuilder()
+        .sqlQuery("select * from `CaseInsensitiveColumnNames`")
+        .unOrdered()
+        .baselineColumns("BIGINT_col", "bigint_col0\n")
+        .baselineValues((long) 0, new BigDecimal(0))
+        .baselineValues((long) 1, new BigDecimal(1))
+        .baselineValues((long) 2, new BigDecimal(2))
+        .baselineValues((long) 3, new BigDecimal(3))
+        .baselineValues((long) 4, new BigDecimal(4))
+        .build().run();
+  }
+
+  @Test // DRILL-1943, DRILL-1911
+  public void testColumnNamesDifferInCaseOnly() throws Exception {
+    testBuilder()
+        .sqlQuery("select r_regionkey a, r_regionkey A FROM cp.`tpch/region.parquet`")
+        .unOrdered()
+        .baselineColumns("a", "A0")
+        .baselineValues(0, 0)
+        .baselineValues(1, 1)
+        .baselineValues(2, 2)
+        .baselineValues(3, 3)
+        .baselineValues(4, 4)
+        .build().run();
+
+    testBuilder()
+        .sqlQuery("select employee_id, Employee_id from cp.`employee.json` limit 2")
+        .unOrdered()
+        .baselineColumns("employee_id", "Employee_id0")
+        .baselineValues((long) 1, (long) 1)
+        .baselineValues((long) 2, (long) 2)
+        .build().run();
+  }
 }