drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amansi...@apache.org
Subject drill git commit: DRILL-2639: At planning for Union-All, block only the cases where implicit casting cannot resolve an output type
Date Fri, 10 Apr 2015 23:19:04 GMT
Repository: drill
Updated Branches:
  refs/heads/master 434099659 -> 38eb383a9


DRILL-2639: At planning for Union-All, block only the cases where implicit casting cannot
resolve an output type


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

Branch: refs/heads/master
Commit: 38eb383a9589891dbd37033545145cca25d1a253
Parents: 4340996
Author: Hsuan-Yi Chu <hsuanyi@usc.edu>
Authored: Wed Apr 1 15:16:52 2015 -0700
Committer: Aman Sinha <asinha@maprtech.com>
Committed: Fri Apr 10 14:28:34 2015 -0700

----------------------------------------------------------------------
 .../org/apache/drill/common/types/Types.java    | 56 +++++++++++++-------
 .../exec/planner/common/DrillRelOptUtil.java    | 16 +++++-
 .../exec/planner/common/DrillUnionRelBase.java  |  2 +-
 .../drill/exec/planner/logical/DrillOptiq.java  |  1 +
 .../java/org/apache/drill/TestUnionAll.java     | 19 +++++++
 5 files changed, 73 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/38eb383a/common/src/main/java/org/apache/drill/common/types/Types.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/types/Types.java b/common/src/main/java/org/apache/drill/common/types/Types.java
index 015ee90..c41727d 100644
--- a/common/src/main/java/org/apache/drill/common/types/Types.java
+++ b/common/src/main/java/org/apache/drill/common/types/Types.java
@@ -324,53 +324,71 @@ public class Types {
     return getMajorTypeFromName(typeName, DataMode.REQUIRED);
   }
 
-  public static MajorType getMajorTypeFromName(String typeName, DataMode mode) {
+  public static MinorType getMinorTypeFromName(String typeName) {
+    typeName = typeName.toLowerCase();
+
     switch (typeName) {
     case "bool":
     case "boolean":
-      return withMode(MinorType.BIT, mode);
+      return MinorType.BIT;
     case "tinyint":
-      return withMode(MinorType.TINYINT, mode);
+      return MinorType.TINYINT;
     case "uint1":
-      return withMode(MinorType.UINT1, mode);
+      return MinorType.UINT1;
     case "smallint":
-      return withMode(MinorType.SMALLINT, mode);
+      return MinorType.SMALLINT;
     case "uint2":
-      return withMode(MinorType.UINT2, mode);
+      return MinorType.UINT2;
+    case "integer":
     case "int":
-      return withMode(MinorType.INT, mode);
+      return MinorType.INT;
     case "uint4":
-      return withMode(MinorType.UINT4, mode);
+      return MinorType.UINT4;
     case "bigint":
-      return withMode(MinorType.BIGINT, mode);
+      return MinorType.BIGINT;
     case "uint8":
-      return withMode(MinorType.UINT8, mode);
+      return MinorType.UINT8;
     case "float":
-      return withMode(MinorType.FLOAT4, mode);
+      return MinorType.FLOAT4;
     case "double":
-      return withMode(MinorType.FLOAT8, mode);
+      return MinorType.FLOAT8;
     case "decimal":
-      return withMode(MinorType.DECIMAL38SPARSE, mode);
+      return MinorType.DECIMAL38SPARSE;
+    case "symbol":
+    case "char":
     case "utf8":
     case "varchar":
-      return withMode(MinorType.VARCHAR, mode);
+      return MinorType.VARCHAR;
     case "utf16":
     case "string":
     case "var16char":
-      return withMode(MinorType.VAR16CHAR, mode);
+      return MinorType.VAR16CHAR;
+    case "timestamp":
+      return MinorType.TIMESTAMP;
+    case "interval_year_month":
+      return MinorType.INTERVALYEAR;
+    case "interval_day_time":
+      return MinorType.INTERVALDAY;
     case "date":
-      return withMode(MinorType.DATE, mode);
+      return MinorType.DATE;
     case "time":
-      return withMode(MinorType.TIME, mode);
+      return MinorType.TIME;
     case "binary":
-      return withMode(MinorType.VARBINARY, mode);
+      return MinorType.VARBINARY;
     case "json":
-      return withMode(MinorType.LATE, mode);
+      return MinorType.LATE;
+    case "null":
+    case "any":
+      return MinorType.NULL;
     default:
       throw new UnsupportedOperationException("Could not determine type: " + typeName);
     }
   }
 
+  public static MajorType getMajorTypeFromName(String typeName, DataMode mode) {
+    return withMode(getMinorTypeFromName(typeName), mode);
+  }
+
   public static String getNameOfMinorType(MinorType type) {
     switch (type) {
       case BIT:

http://git-wip-us.apache.org/repos/asf/drill/blob/38eb383a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
index aba6022..cacf26b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
@@ -19,6 +19,11 @@ package org.apache.drill.exec.planner.common;
 
 import java.util.List;
 
+import com.google.common.collect.Lists;
+import org.apache.drill.common.types.TypeProtos;
+import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.planner.logical.DrillOptiq;
+import org.apache.drill.exec.resolver.TypeCastRules;
 import org.eigenbase.reltype.RelDataType;
 import org.eigenbase.reltype.RelDataTypeField;
 import org.eigenbase.sql.type.SqlTypeName;
@@ -31,7 +36,7 @@ import org.eigenbase.util.Pair;
 public abstract class DrillRelOptUtil {
 
   // Similar to RelOptUtil.areRowTypesEqual() with the additional check for allowSubstring
-  public static boolean areRowTypesEqual(
+  public static boolean areRowTypesCompatible(
       RelDataType rowType1,
       RelDataType rowType2,
       boolean compareNames,
@@ -63,6 +68,15 @@ public abstract class DrillRelOptUtil {
             && (type1.getPrecision() <= type2.getPrecision())) {
           return true;
         }
+
+        // Check if Drill implicit casting can resolve the incompatibility
+        List<TypeProtos.MinorType> types = Lists.newArrayListWithCapacity(2);
+        types.add(Types.getMinorTypeFromName(type1.getSqlTypeName().getName()));
+        types.add(Types.getMinorTypeFromName(type2.getSqlTypeName().getName()));
+        if(TypeCastRules.getLeastRestrictiveType(types) != null) {
+          return true;
+        }
+
         return false;
       }
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/38eb383a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillUnionRelBase.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillUnionRelBase.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillUnionRelBase.java
index 932aa76..11ed8ba 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillUnionRelBase.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillUnionRelBase.java
@@ -43,7 +43,7 @@ public abstract class DrillUnionRelBase extends UnionRelBase implements
DrillRel
   public boolean isCompatible(boolean compareNames, boolean allowSubstring) {
     RelDataType unionType = getRowType();
     for (RelNode input : getInputs()) {
-      if (! DrillRelOptUtil.areRowTypesEqual(
+      if (! DrillRelOptUtil.areRowTypesCompatible(
           input.getRowType(), unionType, compareNames, allowSubstring)) {
         return false;
       }

http://git-wip-us.apache.org/repos/asf/drill/blob/38eb383a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
index 796f0f7..5dd6ed5 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
@@ -52,6 +52,7 @@ import org.eigenbase.rex.RexRangeRef;
 import org.eigenbase.rex.RexVisitorImpl;
 import org.eigenbase.sql.SqlSyntax;
 import org.eigenbase.sql.fun.SqlStdOperatorTable;
+import org.eigenbase.sql.type.SqlTypeName;
 import org.eigenbase.util.NlsString;
 
 import com.google.common.collect.Lists;

http://git-wip-us.apache.org/repos/asf/drill/blob/38eb383a/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java b/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
index 3843b32..d31cd19 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
@@ -459,4 +459,23 @@ public class TestUnionAll extends BaseTestQuery{
         .baselineValues("99")
         .build().run();
   }
+
+  @Test // see DRILL-2639
+  public void testUnionAllDiffTypesAtPlanning() throws Exception {
+    String query = "select count(c1) as ct from (select cast(r_regionkey as int) c1 from
cp.`tpch/region.parquet`) " +
+        "union all " +
+        "(select cast(r_regionkey as int) c2 from cp.`tpch/region.parquet`)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .ordered()
+        .baselineColumns("ct")
+        .baselineValues((long) 5)
+        .baselineValues((long) 0)
+        .baselineValues((long) 1)
+        .baselineValues((long) 2)
+        .baselineValues((long) 3)
+        .baselineValues((long) 4)
+        .build().run();
+  }
 }
\ No newline at end of file


Mime
View raw message