drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From par...@apache.org
Subject drill git commit: DRILL-2118: inform user with a user friendly error message if kvgen fails due to heterogenous types
Date Wed, 04 Mar 2015 01:43:32 GMT
Repository: drill
Updated Branches:
  refs/heads/master 767a97648 -> a66b6cc0d


DRILL-2118: inform user with a user friendly error message if kvgen fails due to heterogenous
types


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

Branch: refs/heads/master
Commit: a66b6cc0d7d3de0fbe8aa0715233235aee18f71b
Parents: 767a976
Author: Hanifi Gunes <hgunes@maprtech.com>
Authored: Tue Mar 3 16:37:24 2015 -0800
Committer: Parth Chandra <pchandra@maprtech.com>
Committed: Tue Mar 3 17:43:01 2015 -0800

----------------------------------------------------------------------
 .../src/main/codegen/templates/BaseReader.java  |   5 +-
 .../main/codegen/templates/ComplexReaders.java  |   6 +-
 .../drill/exec/vector/complex/MapUtility.java   | 369 ++++++++++---------
 .../vector/complex/impl/AbstractBaseReader.java |   7 +
 4 files changed, 203 insertions(+), 184 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/a66b6cc0/exec/java-exec/src/main/codegen/templates/BaseReader.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/BaseReader.java b/exec/java-exec/src/main/codegen/templates/BaseReader.java
index 327e618..9281d3c 100644
--- a/exec/java-exec/src/main/codegen/templates/BaseReader.java
+++ b/exec/java-exec/src/main/codegen/templates/BaseReader.java
@@ -30,8 +30,9 @@ package org.apache.drill.exec.vector.complex.reader;
 
 @SuppressWarnings("unused")
 public interface BaseReader extends Positionable{
-  public MajorType getType();
-  
+  MajorType getType();
+  MaterializedField getField();
+
   public interface MapReader extends BaseReader, Iterable<String>{
     FieldReader reader(String name);
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/a66b6cc0/exec/java-exec/src/main/codegen/templates/ComplexReaders.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/ComplexReaders.java b/exec/java-exec/src/main/codegen/templates/ComplexReaders.java
index 9d05934..cd69d0d 100644
--- a/exec/java-exec/src/main/codegen/templates/ComplexReaders.java
+++ b/exec/java-exec/src/main/codegen/templates/ComplexReaders.java
@@ -56,10 +56,14 @@ public class ${nullMode}${name}ReaderImpl extends AbstractFieldReader
{
     super();
     this.vector = vector;
   }
-  
+
   public MajorType getType(){
     return vector.getField().getType();
   }
+
+  public MaterializedField getField(){
+    return vector.getField();
+  }
   
   public boolean isSet(){
     <#if nullMode == "Nullable">

http://git-wip-us.apache.org/repos/asf/drill/blob/a66b6cc0/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapUtility.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapUtility.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapUtility.java
index 93f0de9..7a5863a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapUtility.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapUtility.java
@@ -23,199 +23,206 @@ import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.apache.drill.common.types.TypeProtos.MajorType;
 
 import org.apache.drill.exec.expr.fn.impl.MappifyUtility;
+import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.vector.complex.reader.FieldReader;
 import org.apache.drill.exec.vector.complex.writer.BaseWriter;
 
 public class MapUtility {
+  private final static String TYPE_MISMATCH_ERROR = "Mappify/kvgen does not support heterogeneous
value types. All values in the input map must be of the same type. The field [%s] has a differing
type [%s].";
+
   /*
    * Function to read a value from the field reader, detect the type, construct the appropriate
value holder
    * and use the value holder to write to the Map.
    */
   // TODO : This should be templatized and generated using freemarker
   public static void writeToMapFromReader(FieldReader fieldReader, BaseWriter.MapWriter mapWriter)
{
+    try {
+      MajorType valueMajorType = fieldReader.getType();
+      MinorType valueMinorType = valueMajorType.getMinorType();
+      boolean repeated = false;
 
-    MajorType valueMajorType = fieldReader.getType();
-    MinorType valueMinorType = valueMajorType.getMinorType();
-    boolean repeated = false;
-
-    if (valueMajorType.getMode() == TypeProtos.DataMode.REPEATED) {
-      repeated = true;
-    }
+      if (valueMajorType.getMode() == TypeProtos.DataMode.REPEATED) {
+        repeated = true;
+      }
 
-    switch (valueMinorType) {
-      case TINYINT:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).tinyInt());
-        } else {
-          fieldReader.copyAsValue(mapWriter.tinyInt(MappifyUtility.fieldValue));
-        }
-        break;
-      case SMALLINT:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).smallInt());
-        } else {
-          fieldReader.copyAsValue(mapWriter.smallInt(MappifyUtility.fieldValue));
-        }
-        break;
-      case BIGINT:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).bigInt());
-        } else {
-          fieldReader.copyAsValue(mapWriter.bigInt(MappifyUtility.fieldValue));
-        }
-        break;
-      case INT:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).integer());
-        } else {
-          fieldReader.copyAsValue(mapWriter.integer(MappifyUtility.fieldValue));
-        }
-        break;
-      case UINT1:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt1());
-        } else {
-          fieldReader.copyAsValue(mapWriter.uInt1(MappifyUtility.fieldValue));
-        }
-        break;
-      case UINT2:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt2());
-        } else {
-          fieldReader.copyAsValue(mapWriter.uInt2(MappifyUtility.fieldValue));
-        }
-        break;
-      case UINT4:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt4());
-        } else {
-          fieldReader.copyAsValue(mapWriter.uInt4(MappifyUtility.fieldValue));
-        }
-        break;
-      case UINT8:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt8());
-        } else {
-          fieldReader.copyAsValue(mapWriter.uInt8(MappifyUtility.fieldValue));
-        }
-        break;
-      case DECIMAL9:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal9());
-        } else {
-          fieldReader.copyAsValue(mapWriter.decimal9(MappifyUtility.fieldValue));
-        }
-        break;
-      case DECIMAL18:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal18());
-        } else {
-          fieldReader.copyAsValue(mapWriter.decimal18(MappifyUtility.fieldValue));
-        }
-        break;
-      case DECIMAL28SPARSE:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal28Sparse());
-        } else {
-          fieldReader.copyAsValue(mapWriter.decimal28Sparse(MappifyUtility.fieldValue));
-        }
-        break;
-      case DECIMAL38SPARSE:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal38Sparse());
-        } else {
-          fieldReader.copyAsValue(mapWriter.decimal38Sparse(MappifyUtility.fieldValue));
-        }
-       break;
-      case DATE:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).date());
-        } else {
-          fieldReader.copyAsValue(mapWriter.date(MappifyUtility.fieldValue));
-        }
-        break;
-      case TIME:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).time());
-        } else {
-          fieldReader.copyAsValue(mapWriter.time(MappifyUtility.fieldValue));
-        }
-        break;
-      case TIMESTAMP:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).timeStamp());
-        } else {
-          fieldReader.copyAsValue(mapWriter.timeStamp(MappifyUtility.fieldValue));
-        }
-        break;
-      case INTERVAL:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).interval());
-        } else {
-          fieldReader.copyAsValue(mapWriter.interval(MappifyUtility.fieldValue));
-        }
-        break;
-      case INTERVALDAY:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).intervalDay());
-        } else {
-          fieldReader.copyAsValue(mapWriter.intervalDay(MappifyUtility.fieldValue));
-        }
-        break;
-      case INTERVALYEAR:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).intervalYear());
-        } else {
-          fieldReader.copyAsValue(mapWriter.intervalYear(MappifyUtility.fieldValue));
-        }
-        break;
-      case FLOAT4:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).float4());
-        } else {
-          fieldReader.copyAsValue(mapWriter.float4(MappifyUtility.fieldValue));
-        }
-        break;
-      case FLOAT8:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).float8());
-        } else {
-          fieldReader.copyAsValue(mapWriter.float8(MappifyUtility.fieldValue));
-        }
-        break;
-      case BIT:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).bit());
-        } else {
-          fieldReader.copyAsValue(mapWriter.bit(MappifyUtility.fieldValue));
-        }
-        break;
-      case VARCHAR:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).varChar());
-        } else {
-          fieldReader.copyAsValue(mapWriter.varChar(MappifyUtility.fieldValue));
-        }
-        break;
-      case VARBINARY:
-        if (repeated) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).varBinary());
-        } else {
-          fieldReader.copyAsValue(mapWriter.varBinary(MappifyUtility.fieldValue));
-        }
-        break;
-      case MAP:
-        if (valueMajorType.getMode() == TypeProtos.DataMode.REPEATED) {
-          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).map());
-        } else {
-          fieldReader.copyAsValue(mapWriter.map(MappifyUtility.fieldValue));
-        }
-        break;
-      case LIST:
-        fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).list());
-        break;
-      default:
-        throw new DrillRuntimeException(String.format("kvgen does not support input of type:
%s", valueMinorType));
+      switch (valueMinorType) {
+        case TINYINT:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).tinyInt());
+          } else {
+            fieldReader.copyAsValue(mapWriter.tinyInt(MappifyUtility.fieldValue));
+          }
+          break;
+        case SMALLINT:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).smallInt());
+          } else {
+            fieldReader.copyAsValue(mapWriter.smallInt(MappifyUtility.fieldValue));
+          }
+          break;
+        case BIGINT:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).bigInt());
+          } else {
+            fieldReader.copyAsValue(mapWriter.bigInt(MappifyUtility.fieldValue));
+          }
+          break;
+        case INT:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).integer());
+          } else {
+            fieldReader.copyAsValue(mapWriter.integer(MappifyUtility.fieldValue));
+          }
+          break;
+        case UINT1:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt1());
+          } else {
+            fieldReader.copyAsValue(mapWriter.uInt1(MappifyUtility.fieldValue));
+          }
+          break;
+        case UINT2:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt2());
+          } else {
+            fieldReader.copyAsValue(mapWriter.uInt2(MappifyUtility.fieldValue));
+          }
+          break;
+        case UINT4:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt4());
+          } else {
+            fieldReader.copyAsValue(mapWriter.uInt4(MappifyUtility.fieldValue));
+          }
+          break;
+        case UINT8:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt8());
+          } else {
+            fieldReader.copyAsValue(mapWriter.uInt8(MappifyUtility.fieldValue));
+          }
+          break;
+        case DECIMAL9:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal9());
+          } else {
+            fieldReader.copyAsValue(mapWriter.decimal9(MappifyUtility.fieldValue));
+          }
+          break;
+        case DECIMAL18:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal18());
+          } else {
+            fieldReader.copyAsValue(mapWriter.decimal18(MappifyUtility.fieldValue));
+          }
+          break;
+        case DECIMAL28SPARSE:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal28Sparse());
+          } else {
+            fieldReader.copyAsValue(mapWriter.decimal28Sparse(MappifyUtility.fieldValue));
+          }
+          break;
+        case DECIMAL38SPARSE:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal38Sparse());
+          } else {
+            fieldReader.copyAsValue(mapWriter.decimal38Sparse(MappifyUtility.fieldValue));
+          }
+          break;
+        case DATE:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).date());
+          } else {
+            fieldReader.copyAsValue(mapWriter.date(MappifyUtility.fieldValue));
+          }
+          break;
+        case TIME:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).time());
+          } else {
+            fieldReader.copyAsValue(mapWriter.time(MappifyUtility.fieldValue));
+          }
+          break;
+        case TIMESTAMP:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).timeStamp());
+          } else {
+            fieldReader.copyAsValue(mapWriter.timeStamp(MappifyUtility.fieldValue));
+          }
+          break;
+        case INTERVAL:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).interval());
+          } else {
+            fieldReader.copyAsValue(mapWriter.interval(MappifyUtility.fieldValue));
+          }
+          break;
+        case INTERVALDAY:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).intervalDay());
+          } else {
+            fieldReader.copyAsValue(mapWriter.intervalDay(MappifyUtility.fieldValue));
+          }
+          break;
+        case INTERVALYEAR:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).intervalYear());
+          } else {
+            fieldReader.copyAsValue(mapWriter.intervalYear(MappifyUtility.fieldValue));
+          }
+          break;
+        case FLOAT4:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).float4());
+          } else {
+            fieldReader.copyAsValue(mapWriter.float4(MappifyUtility.fieldValue));
+          }
+          break;
+        case FLOAT8:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).float8());
+          } else {
+            fieldReader.copyAsValue(mapWriter.float8(MappifyUtility.fieldValue));
+          }
+          break;
+        case BIT:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).bit());
+          } else {
+            fieldReader.copyAsValue(mapWriter.bit(MappifyUtility.fieldValue));
+          }
+          break;
+        case VARCHAR:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).varChar());
+          } else {
+            fieldReader.copyAsValue(mapWriter.varChar(MappifyUtility.fieldValue));
+          }
+          break;
+        case VARBINARY:
+          if (repeated) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).varBinary());
+          } else {
+            fieldReader.copyAsValue(mapWriter.varBinary(MappifyUtility.fieldValue));
+          }
+          break;
+        case MAP:
+          if (valueMajorType.getMode() == TypeProtos.DataMode.REPEATED) {
+            fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).map());
+          } else {
+            fieldReader.copyAsValue(mapWriter.map(MappifyUtility.fieldValue));
+          }
+          break;
+        case LIST:
+          fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).list());
+          break;
+        default:
+          throw new DrillRuntimeException(String.format("kvgen does not support input of
type: %s", valueMinorType));
+      }
+    } catch (ClassCastException e) {
+      final MaterializedField field = fieldReader.getField();
+      throw new DrillRuntimeException(String.format(TYPE_MISMATCH_ERROR, field.getPath(),
field.getType()));
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/a66b6cc0/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/AbstractBaseReader.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/AbstractBaseReader.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/AbstractBaseReader.java
index 468ea0f..04235fa 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/AbstractBaseReader.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/AbstractBaseReader.java
@@ -20,6 +20,8 @@ package org.apache.drill.exec.vector.complex.impl;
 import java.util.Iterator;
 
 import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.vector.complex.reader.FieldReader;
 
 
@@ -51,6 +53,11 @@ abstract class AbstractBaseReader implements FieldReader{
   }
 
   @Override
+  public MaterializedField getField() {
+    return MaterializedField.create("unknown", Types.LATE_BIND_TYPE);
+  }
+
+  @Override
   public boolean next() {
     throw new IllegalStateException("The current reader doesn't support getting next information.");
   }


Mime
View raw message