drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From par...@apache.org
Subject [03/10] drill git commit: DRILL-1838: MapVector should late bind/replace vector if current vector is null valued
Date Fri, 12 Dec 2014 16:24:09 GMT
DRILL-1838: MapVector should late bind/replace vector if current vector is null valued


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

Branch: refs/heads/master
Commit: a0b16ce756bc3a030ef2ab62ead4536602a01151
Parents: cc33579
Author: Hanifi Gunes <hgunes@maprtech.com>
Authored: Wed Dec 10 19:31:15 2014 -0800
Committer: Parth Chandra <pchandra@maprtech.com>
Committed: Thu Dec 11 11:49:08 2014 -0800

----------------------------------------------------------------------
 .../drill/exec/vector/complex/MapVector.java    | 35 +++++++++++++++-----
 1 file changed, 26 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/a0b16ce7/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
index 513bfcb..cc3d24c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
@@ -119,17 +119,34 @@ public class MapVector extends AbstractContainerVector {
 
   @Override
   public <T extends ValueVector> T addOrGet(String name, MajorType type, Class<T>
clazz) {
-    ValueVector v = vectors.get(name);
-    if (v == null) {
-      v = TypeHelper.getNewVector(field.getPath(), name, allocator, type);
-      Preconditions.checkNotNull(v, String.format("Failure to create vector of type %s.",
type));
-      put(name, v);
-      if (callBack != null) {
-        callBack.doWork();
+    while (true) {
+      ValueVector vector = vectors.get(name);
+      if (vector == null) {
+        vector = TypeHelper.getNewVector(field.getPath(), name, allocator, type);
+        Preconditions.checkNotNull(vector, String.format("Failure to create vector of type
%s.", type));
+        put(name, vector);
+        if (callBack != null) {
+          callBack.doWork();
+        }
+      }
+      if (clazz.isAssignableFrom(vector.getClass())) {
+        return (T)vector;
+      } else {
+        boolean allNulls = true;
+        for (int i=0; i<vector.getAccessor().getValueCount(); i++) {
+          if (!vector.getAccessor().isNull(i)) {
+            allNulls = false;
+            break;
+          }
+        }
+        if (allNulls) {
+          vector.clear();
+          vectors.remove(name);
+        } else {
+          throw new IllegalStateException(String.format("Vector requested [%s] was different
than type stored [%s].  Drill doesn't yet support hetergenous types.", clazz.getSimpleName(),
vector.getClass().getSimpleName()));
+        }
       }
     }
-    return typeify(v, clazz);
-
   }
 
   protected void put(String name, ValueVector vv) {


Mime
View raw message