You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by pr...@apache.org on 2017/12/21 05:19:32 UTC

[05/15] drill git commit: DRILL-5657: Size-aware vector writer structure

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/codegen/templates/RepeatedValueVectors.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/RepeatedValueVectors.java b/exec/vector/src/main/codegen/templates/RepeatedValueVectors.java
index 4da3d9e..c20ee89 100644
--- a/exec/vector/src/main/codegen/templates/RepeatedValueVectors.java
+++ b/exec/vector/src/main/codegen/templates/RepeatedValueVectors.java
@@ -18,6 +18,9 @@
 
 import java.lang.Override;
 
+import org.apache.drill.common.types.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.record.TransferPair;
 import org.apache.drill.exec.vector.complex.BaseRepeatedValueVector;
 import org.mortbay.jetty.servlet.Holder;
@@ -55,7 +58,10 @@ public final class Repeated${minor.class}Vector extends BaseRepeatedValueVector
 
   public Repeated${minor.class}Vector(MaterializedField field, BufferAllocator allocator) {
     super(field, allocator);
-    addOrGetVector(VectorDescriptor.create(Types.required(field.getType().getMinorType())));
+    MajorType majorType = field.getType();
+    addOrGetVector(VectorDescriptor.create(Types.withScaleAndPrecision(
+        majorType.getMinorType(), DataMode.REQUIRED,
+        majorType.getScale(), majorType.getPrecision())));
   }
 
   @Override
@@ -341,25 +347,12 @@ public final class Repeated${minor.class}Vector extends BaseRepeatedValueVector
       addSafe(index, bytes, 0, bytes.length);
     }
 
-    public void addEntry(int index, byte[] bytes) throws VectorOverflowException {
-      addEntry(index, bytes, 0, bytes.length);
-    }
-
     public void addSafe(int index, byte[] bytes, int start, int length) {
       final int nextOffset = offsets.getAccessor().get(index+1);
       values.getMutator().setSafe(nextOffset, bytes, start, length);
       offsets.getMutator().setSafe(index+1, nextOffset+1);
     }
 
-    public void addEntry(int index, byte[] bytes, int start, int length) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      final int nextOffset = offsets.getAccessor().get(index+1);
-      values.getMutator().setArrayItem(nextOffset, bytes, start, length);
-      offsets.getMutator().setSafe(index+1, nextOffset+1);
-    }
-
     <#else>
     public void addSafe(int index, ${minor.javaType!type.javaType} srcValue) {
       final int nextOffset = offsets.getAccessor().get(index+1);
@@ -367,15 +360,6 @@ public final class Repeated${minor.class}Vector extends BaseRepeatedValueVector
       offsets.getMutator().setSafe(index+1, nextOffset+1);
     }
 
-    public void addEntry(int index, ${minor.javaType!type.javaType} srcValue) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      final int nextOffset = offsets.getAccessor().get(index+1);
-      values.getMutator().setArrayItem(nextOffset, srcValue);
-      offsets.getMutator().setSafe(index+1, nextOffset+1);
-    }
-
     </#if>
     public void setSafe(int index, Repeated${minor.class}Holder h) {
       final ${minor.class}Holder ih = new ${minor.class}Holder();
@@ -393,14 +377,6 @@ public final class Repeated${minor.class}Vector extends BaseRepeatedValueVector
       offsets.getMutator().setSafe(index+1, nextOffset+1);
     }
 
-    public void addEntry(int index, ${minor.class}Holder holder) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      final int nextOffset = offsets.getAccessor().get(index+1);
-      values.getMutator().setArrayItem(nextOffset, holder);
-      offsets.getMutator().setSafe(index+1, nextOffset+1);
-    }
 
     public void addSafe(int index, Nullable${minor.class}Holder holder) {
       final int nextOffset = offsets.getAccessor().get(index+1);
@@ -408,15 +384,6 @@ public final class Repeated${minor.class}Vector extends BaseRepeatedValueVector
       offsets.getMutator().setSafe(index+1, nextOffset+1);
     }
 
-    public void addEntry(int index, Nullable${minor.class}Holder holder) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      final int nextOffset = offsets.getAccessor().get(index+1);
-      values.getMutator().setArrayItem(nextOffset, holder);
-      offsets.getMutator().setSafe(index+1, nextOffset+1);
-    }
-
     /**
      * Backfill missing offsets from the given last written position to the
      * given current write position. Used by the "new" size-safe column
@@ -427,11 +394,7 @@ public final class Repeated${minor.class}Vector extends BaseRepeatedValueVector
      * @param index the current write position to be initialized
      */
 
-    public void fillEmptiesBounded(int lastWrite, int index)
-            throws VectorOverflowException {
-      if (index >= UInt4Vector.MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
+    public void fillEmpties(int lastWrite, int index) {
       // If last write was 2, offsets are [0, 3, 6]
       // If next write is 4, offsets must be: [0, 3, 6, 6, 6]
       // Remember the offsets are one more than row count.
@@ -449,15 +412,6 @@ public final class Repeated${minor.class}Vector extends BaseRepeatedValueVector
       offsets.getMutator().setSafe(rowIndex+1, nextOffset+1);
     }
 
-    public void addEntry(int rowIndex, <#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) throws VectorOverflowException {
-      if (rowIndex >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      final int nextOffset = offsets.getAccessor().get(rowIndex+1);
-      values.getMutator().setArrayItem(nextOffset, <#list fields as field>${field.name}<#if field_has_next>, </#if></#list>);
-      offsets.getMutator().setSafe(rowIndex+1, nextOffset+1);
-    }
-
     </#if>
     <#if minor.class == "Decimal28Sparse" || minor.class == "Decimal38Sparse">
     public void addSafe(int index, BigDecimal value) {
@@ -466,15 +420,6 @@ public final class Repeated${minor.class}Vector extends BaseRepeatedValueVector
       offsets.getMutator().setSafe(index+1, nextOffset+1);
     }
 
-    public void addEntry(int index, BigDecimal value) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      final int nextOffset = offsets.getAccessor().get(index+1);
-      values.getMutator().setArrayItem(nextOffset, value);
-      offsets.getMutator().setSafe(index+1, nextOffset+1);
-    }
-
     </#if>
     protected void add(int index, ${minor.class}Holder holder) {
       final int nextOffset = offsets.getAccessor().get(index+1);

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/codegen/templates/UnionVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/UnionVector.java b/exec/vector/src/main/codegen/templates/UnionVector.java
index c198544..a46779d 100644
--- a/exec/vector/src/main/codegen/templates/UnionVector.java
+++ b/exec/vector/src/main/codegen/templates/UnionVector.java
@@ -116,7 +116,6 @@ public class UnionVector implements ValueVector {
     }
     return mapVector;
   }
-
   <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
   <#assign fields = minor.fields!type.fields />
   <#assign uncappedName = name?uncap_first/>
@@ -136,9 +135,7 @@ public class UnionVector implements ValueVector {
     }
     return ${uncappedName}Vector;
   }
-
   </#if>
-
   </#list></#list>
 
   private static final MajorType LIST_TYPE = Types.optional(MinorType.LIST);
@@ -183,8 +180,7 @@ public class UnionVector implements ValueVector {
   }
 
   @Override
-  public void setInitialCapacity(int numRecords) {
-  }
+  public void setInitialCapacity(int numRecords) { }
 
   @Override
   public int getValueCapacity() {
@@ -192,8 +188,7 @@ public class UnionVector implements ValueVector {
   }
 
   @Override
-  public void close() {
-  }
+  public void close() { }
 
   @Override
   public void clear() {
@@ -201,9 +196,7 @@ public class UnionVector implements ValueVector {
   }
 
   @Override
-  public MaterializedField getField() {
-    return field;
-  }
+  public MaterializedField getField() { return field; }
 
   @Override
   public void collectLedgers(Set<BufferLedger> ledgers) {
@@ -290,9 +283,7 @@ public class UnionVector implements ValueVector {
     }
 
     @Override
-    public void splitAndTransfer(int startIndex, int length) {
-
-    }
+    public void splitAndTransfer(int startIndex, int length) { }
 
     @Override
     public ValueVector getTo() {
@@ -306,14 +297,10 @@ public class UnionVector implements ValueVector {
   }
 
   @Override
-  public Accessor getAccessor() {
-    return accessor;
-  }
+  public Accessor getAccessor() { return accessor; }
 
   @Override
-  public Mutator getMutator() {
-    return mutator;
-  }
+  public Mutator getMutator() { return mutator; }
 
   @Override
   public FieldReader getReader() {
@@ -347,6 +334,11 @@ public class UnionVector implements ValueVector {
   }
 
   @Override
+  public int getAllocatedSize() {
+    return internalMap.getAllocatedSize();
+  }
+
+  @Override
   public int getBufferSizeFor(final int valueCount) {
     if (valueCount == 0) {
       return 0;
@@ -381,7 +373,6 @@ public class UnionVector implements ValueVector {
 
   public class Accessor extends BaseValueVector.BaseAccessor {
 
-
     @Override
     public Object getObject(int index) {
       int type = typeVector.getAccessor().get(index);
@@ -406,12 +397,9 @@ public class UnionVector implements ValueVector {
       }
     }
 
-    public byte[] get(int index) {
-      return null;
-    }
+    public byte[] get(int index) { return null; }
 
-    public void get(int index, ComplexHolder holder) {
-    }
+    public void get(int index, ComplexHolder holder) { }
 
     public void get(int index, UnionHolder holder) {
       FieldReader reader = new UnionReader(UnionVector.this);
@@ -420,9 +408,7 @@ public class UnionVector implements ValueVector {
     }
 
     @Override
-    public int getValueCount() {
-      return valueCount;
-    }
+    public int getValueCount() { return valueCount; }
 
     @Override
     public boolean isNull(int index) {
@@ -436,7 +422,7 @@ public class UnionVector implements ValueVector {
 
   public class Mutator extends BaseValueVector.BaseMutator {
 
-    UnionWriter writer;
+    protected UnionWriter writer;
 
     @Override
     public void setValueCount(int valueCount) {

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/VariableLengthVectors.java b/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
index e5432da..a29194a 100644
--- a/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
+++ b/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
@@ -54,7 +54,6 @@ package org.apache.drill.exec.vector;
  */
 
 public final class ${minor.class}Vector extends BaseDataValueVector implements VariableWidthVector {
-  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(${minor.class}Vector.class);
 
   private static final int DEFAULT_RECORD_BYTE_COUNT = 8;
   private static final int INITIAL_BYTE_COUNT = Math.min(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT, MAX_BUFFER_SIZE);
@@ -68,20 +67,17 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
   private final Accessor accessor;
   private final Mutator mutator;
 
-  private final UInt${type.width}Vector.Accessor oAccessor;
-
   private int allocationSizeInBytes = INITIAL_BYTE_COUNT;
   private int allocationMonitor = 0;
 
   public ${minor.class}Vector(MaterializedField field, BufferAllocator allocator) {
     super(field, allocator);
-    this.oAccessor = offsetVector.getAccessor();
     this.accessor = new Accessor();
     this.mutator = new Mutator();
   }
 
   @Override
-  public FieldReader getReader(){
+  public FieldReader getReader() {
     return reader;
   }
 
@@ -94,6 +90,11 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
   }
 
   @Override
+  public int getAllocatedSize() {
+    return offsetVector.getAllocatedSize() + data.capacity();
+  }
+
+  @Override
   public int getBufferSizeFor(final int valueCount) {
     if (valueCount == 0) {
       return 0;
@@ -104,12 +105,12 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
   }
 
   @Override
-  public int getValueCapacity(){
+  public int getValueCapacity() {
     return Math.max(offsetVector.getValueCapacity() - 1, 0);
   }
 
   @Override
-  public int getByteCapacity(){
+  public int getByteCapacity() {
     return data.capacity();
   }
 
@@ -124,7 +125,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
    */
   public int getVarByteLength(){
     final int valueCount = getAccessor().getValueCount();
-    if(valueCount == 0) {
+    if (valueCount == 0) {
       return 0;
     }
     return offsetVector.getAccessor().get(valueCount);
@@ -132,10 +133,10 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
 
   @Override
   public SerializedField getMetadata() {
-    return getMetadataBuilder() //
+    return getMetadataBuilder()
              .addChild(offsetVector.getMetadata())
-             .setValueCount(getAccessor().getValueCount()) //
-             .setBufferLength(getBufferSize()) //
+             .setValueCount(getAccessor().getValueCount())
+             .setBufferLength(getBufferSize())
              .build();
   }
 
@@ -170,21 +171,21 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
     return buffers;
   }
 
-  public long getOffsetAddr(){
+  public long getOffsetAddr() {
     return offsetVector.getBuffer().memoryAddress();
   }
 
-  public UInt${type.width}Vector getOffsetVector(){
+  public UInt${type.width}Vector getOffsetVector() {
     return offsetVector;
   }
 
   @Override
-  public TransferPair getTransferPair(BufferAllocator allocator){
+  public TransferPair getTransferPair(BufferAllocator allocator) {
     return new TransferImpl(getField(), allocator);
   }
 
   @Override
-  public TransferPair getTransferPair(String ref, BufferAllocator allocator){
+  public TransferPair getTransferPair(String ref, BufferAllocator allocator) {
     return new TransferImpl(getField().withPath(ref), allocator);
   }
 
@@ -193,7 +194,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
     return new TransferImpl((${minor.class}Vector) to);
   }
 
-  public void transferTo(${minor.class}Vector target){
+  public void transferTo(${minor.class}Vector target) {
     target.clear();
     this.offsetVector.transferTo(target.offsetVector);
     target.data = data.transferOwnership(target.allocator).buffer;
@@ -272,23 +273,23 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
   }
 
   private class TransferImpl implements TransferPair{
-    ${minor.class}Vector to;
+    private final ${minor.class}Vector to;
 
     public TransferImpl(MaterializedField field, BufferAllocator allocator){
       to = new ${minor.class}Vector(field, allocator);
     }
 
-    public TransferImpl(${minor.class}Vector to){
+    public TransferImpl(${minor.class}Vector to) {
       this.to = to;
     }
 
     @Override
-    public ${minor.class}Vector getTo(){
+    public ${minor.class}Vector getTo() {
       return to;
     }
 
     @Override
-    public void transfer(){
+    public void transfer() {
       transferTo(to);
     }
 
@@ -309,7 +310,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
     if (size > MAX_ALLOCATION_SIZE) {
       throw new OversizedAllocationException("Requested amount of memory is more than max allowed allocation size");
     }
-    allocationSizeInBytes = (int) size;
+    allocationSizeInBytes = (int)size;
     offsetVector.setInitialCapacity(valueCount + 1);
   }
 
@@ -386,12 +387,17 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       throw new OversizedAllocationException("Unable to expand the buffer. Max allowed buffer size is reached.");
     }
 
-    logger.trace("Reallocating VarChar, new size {}", newAllocationSize);
-    final DrillBuf newBuf = allocator.buffer((int)newAllocationSize);
+    reallocRaw((int) newAllocationSize);
+  }
+
+  @Override
+  public DrillBuf reallocRaw(int newAllocationSize) {
+    final DrillBuf newBuf = allocator.buffer(newAllocationSize);
     newBuf.setBytes(0, data, 0, data.capacity());
     data.release();
     data = newBuf;
-    allocationSizeInBytes = (int)newAllocationSize;
+    allocationSizeInBytes = newAllocationSize;
+    return data;
   }
 
   public void decrementAllocationMonitor() {
@@ -430,6 +436,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
 
   public final class Accessor extends BaseValueVector.BaseAccessor implements VariableWidthAccessor {
     final UInt${type.width}Vector.Accessor oAccessor = offsetVector.getAccessor();
+    
     public long getStartEnd(int index){
       return oAccessor.getTwoAsLong(index);
     }
@@ -463,7 +470,6 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       holder.buffer = data;
     }
 
-
     <#switch minor.class>
     <#case "VarChar">
     @Override
@@ -541,10 +547,6 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       }
     }
 
-    public void setScalar(int index, byte[] bytes) throws VectorOverflowException {
-      setScalar(index, bytes, 0, bytes.length);
-    }
-
     /**
      * Set the variable length element at the specified index to the supplied byte array.
      *
@@ -575,23 +577,6 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       }
     }
 
-    public void setScalar(int index, DrillBuf bytes, int start, int length) throws VectorOverflowException {
-      assert index >= 0;
-
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      int currentOffset = offsetVector.getAccessor().get(index);
-      final int newSize = currentOffset + length;
-      if (newSize > MAX_BUFFER_SIZE) {
-        throw new VectorOverflowException();
-      }
-      while (! data.setBytesBounded(currentOffset, bytes, start, length)) {
-        reAlloc();
-      }
-      offsetVector.getMutator().setSafe(index + 1, newSize);
-    }
-
     public void setSafe(int index, byte[] bytes, int start, int length) {
       assert index >= 0;
 
@@ -608,28 +593,6 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       }
     }
 
-    public void setScalar(int index, byte[] bytes, int start, int length) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      setArrayItem(index, bytes, start, length);
-    }
-
-    public void setArrayItem(int index, byte[] bytes, int start, int length) throws VectorOverflowException {
-      assert index >= 0;
-
-      final int currentOffset = offsetVector.getAccessor().get(index);
-      final int newSize = currentOffset + length;
-      if (newSize > MAX_BUFFER_SIZE) {
-        throw new VectorOverflowException();
-      }
-
-      while (! data.setBytesBounded(currentOffset, bytes, start, length)) {
-        reAlloc();
-      }
-      offsetVector.getMutator().setSafe(index + 1, newSize);
-    }
-
     @Override
     public void setValueLengthSafe(int index, int length) {
       final int offset = offsetVector.getAccessor().get(index);
@@ -654,32 +617,6 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       }
     }
 
-    public void setScalar(int index, int start, int end, DrillBuf buffer) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      setArrayItem(index, start, end, buffer);
-    }
-
-    public void setArrayItem(int index, int start, int end, DrillBuf buffer) throws VectorOverflowException {
-      final int len = end - start;
-      final int outputStart = offsetVector.data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width});
-      final int newSize = outputStart + len;
-      if (newSize > MAX_BUFFER_SIZE) {
-        throw new VectorOverflowException();
-      }
-
-      offsetVector.getMutator().setSafe(index+1, newSize);
-      try{
-        buffer.getBytes(start, data, outputStart, len);
-      } catch (IndexOutOfBoundsException e) {
-        while (data.capacity() < newSize) {
-          reAlloc();
-        }
-        buffer.getBytes(start, data, outputStart, len);
-      }
-    }
-
     public void setSafe(int index, Nullable${minor.class}Holder holder) {
       assert holder.isSet == 1;
 
@@ -700,37 +637,6 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       offsetVector.getMutator().setSafe(index+1,  outputStart + len);
     }
 
-    public void setScalar(int index, Nullable${minor.class}Holder holder) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      setArrayItem(index, holder);
-    }
-
-    public void setArrayItem(int index, Nullable${minor.class}Holder holder) throws VectorOverflowException {
-      assert holder.isSet == 1;
-
-      final int start = holder.start;
-      final int end =   holder.end;
-      final int len = end - start;
-
-      final int outputStart = offsetVector.data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width});
-      final int newSize = outputStart + len;
-      if (newSize > MAX_BUFFER_SIZE) {
-        throw new VectorOverflowException();
-      }
-
-      try {
-        holder.buffer.getBytes(start, data, outputStart, len);
-      } catch (IndexOutOfBoundsException e) {
-        while (data.capacity() < newSize) {
-          reAlloc();
-        }
-        holder.buffer.getBytes(start, data, outputStart, len);
-      }
-      offsetVector.getMutator().setSafe(index+1, newSize);
-    }
-
     public void setSafe(int index, ${minor.class}Holder holder) {
       final int start = holder.start;
       final int end =   holder.end;
@@ -748,34 +654,6 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       offsetVector.getMutator().setSafe( index+1,  outputStart + len);
     }
 
-    public void setScalar(int index, ${minor.class}Holder holder) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      setArrayItem(index, holder);
-   }
-
-    public void setArrayItem(int index, ${minor.class}Holder holder) throws VectorOverflowException {
-      final int start = holder.start;
-      final int end =   holder.end;
-      final int len = end - start;
-      final int outputStart = offsetVector.data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width});
-      final int newSize = outputStart + len;
-      if (newSize > MAX_BUFFER_SIZE) {
-        throw new VectorOverflowException();
-      }
-
-      try {
-        holder.buffer.getBytes(start, data, outputStart, len);
-      } catch (IndexOutOfBoundsException e) {
-        while(data.capacity() < newSize) {
-          reAlloc();
-        }
-        holder.buffer.getBytes(start, data, outputStart, len);
-      }
-      offsetVector.getMutator().setSafe( index+1, newSize);
-    }
-
     /**
      * Backfill missing offsets from the given last written position to the
      * given current write position. Used by the "new" size-safe column
@@ -785,20 +663,9 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
      * to be copied forward
      * @param index the current write position filling occurs up to,
      * but not including, this position
-     * @throws VectorOverflowException if the item was written, false if the index would
-     * overfill the vector
      */
 
-    public void fillEmptiesBounded(int lastWrite, int index)
-            throws VectorOverflowException {
-
-      // Index is the next write index, which might be "virtual",
-      // that is, past the last row at EOF. This check only protects
-      // the actual data written here, which is up to index-1.
-
-      if (index > UInt4Vector.MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
+    public void fillEmpties(int lastWrite, int index) {
       // If last write was 2, offsets are [0, 3, 6]
       // If next write is 4, offsets must be: [0, 3, 6, 6, 6]
       // Remember the offsets are one more than row count.
@@ -810,7 +677,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       }
     }
 
-    protected void set(int index, int start, int length, DrillBuf buffer){
+    protected void set(int index, int start, int length, DrillBuf buffer) {
       assert index >= 0;
       final int currentOffset = offsetVector.getAccessor().get(index);
       offsetVector.getMutator().set(index + 1, currentOffset + length);
@@ -818,33 +685,20 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       data.setBytes(currentOffset, bb);
     }
 
-    protected void set(int index, Nullable${minor.class}Holder holder){
+    protected void set(int index, Nullable${minor.class}Holder holder) {
       final int length = holder.end - holder.start;
       final int currentOffset = offsetVector.getAccessor().get(index);
       offsetVector.getMutator().set(index + 1, currentOffset + length);
       data.setBytes(currentOffset, holder.buffer, holder.start, length);
     }
 
-    protected void set(int index, ${minor.class}Holder holder){
+    protected void set(int index, ${minor.class}Holder holder) {
       final int length = holder.end - holder.start;
       final int currentOffset = offsetVector.getAccessor().get(index);
       offsetVector.getMutator().set(index + 1, currentOffset + length);
       data.setBytes(currentOffset, holder.buffer, holder.start, length);
     }
 
-  <#if (minor.class == "VarChar")>
-    public void setScalar(int index, String value) throws VectorOverflowException {
-      if (index >= MAX_ROW_COUNT) {
-        throw new VectorOverflowException();
-      }
-      // Treat a null string as an empty string.
-      if (value != null) {
-        byte encoded[] = value.getBytes(Charsets.UTF_8);
-        setScalar(index, encoded, 0, encoded.length);
-      }
-    }
-
-  </#if>
     @Override
     public void setValueCount(int valueCount) {
       final int currentByteCapacity = getByteCapacity();

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/record/ColumnMetadata.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/record/ColumnMetadata.java b/exec/vector/src/main/java/org/apache/drill/exec/record/ColumnMetadata.java
new file mode 100644
index 0000000..558aab8
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/record/ColumnMetadata.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.record;
+
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
+
+/**
+ * Metadata description of a column including names, types and structure
+ * information.
+ */
+
+public interface ColumnMetadata {
+  enum StructureType {
+    PRIMITIVE, LIST, TUPLE
+  }
+
+  public static final int DEFAULT_ARRAY_SIZE = 10;
+
+  ColumnMetadata.StructureType structureType();
+  TupleMetadata mapSchema();
+  MaterializedField schema();
+  String name();
+  MajorType majorType();
+  MinorType type();
+  DataMode mode();
+  boolean isNullable();
+  boolean isArray();
+  boolean isVariableWidth();
+  boolean isMap();
+  boolean isList();
+
+  /**
+   * Report whether one column is equivalent to another. Columns are equivalent
+   * if they have the same name, type and structure (ignoring internal structure
+   * such as offset vectors.)
+   */
+
+  boolean isEquivalent(ColumnMetadata other);
+
+  /**
+   * For variable-width columns, specify the expected column width to be used
+   * when allocating a new vector. Does nothing for fixed-width columns.
+   *
+   * @param width the expected column width
+   */
+
+  void setExpectedWidth(int width);
+
+  /**
+   * Get the expected width for a column. This is the actual width for fixed-
+   * width columns, the specified width (defaulting to 50) for variable-width
+   * columns.
+   * @return the expected column width of the each data value. Does not include
+   * "overhead" space such as for the null-value vector or offset vector
+   */
+
+  int expectedWidth();
+
+  /**
+   * For an array column, specify the expected average array cardinality.
+   * Ignored for non-array columns. Used when allocating new vectors.
+   *
+   * @param childCount the expected average array cardinality. Defaults to
+   * 1 for non-array columns, 10 for array columns
+   */
+
+  void setExpectedElementCount(int childCount);
+
+  /**
+   * Returns the expected array cardinality for array columns, or 1 for
+   * non-array columns.
+   *
+   * @return the expected value cardinality per value (per-row for top-level
+   * columns, per array element for arrays within lists)
+   */
+
+  int expectedElementCount();
+
+  /**
+   * Create an empty version of this column. If the column is a scalar,
+   * produces a simple copy. If a map, produces a clone without child
+   * columns.
+   *
+   * @return empty clone of this column
+   */
+
+  ColumnMetadata cloneEmpty();
+
+  /**
+   * Reports whether, in this context, the column is projected outside
+   * of the context. (That is, whether the column is backed by an actual
+   * value vector.)
+   */
+
+  boolean isProjected();
+  void setProjected(boolean projected);
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/record/MaterializedField.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/record/MaterializedField.java b/exec/vector/src/main/java/org/apache/drill/exec/record/MaterializedField.java
index 4d29d55..b4b23c7 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/record/MaterializedField.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/record/MaterializedField.java
@@ -92,6 +92,10 @@ public class MaterializedField {
     return withPathAndType(name, getType());
   }
 
+  public MaterializedField cloneEmpty() {
+    return create(name, type);
+  }
+
   public MaterializedField withType(MajorType type) {
     return withPathAndType(name, type);
   }
@@ -170,7 +174,37 @@ public class MaterializedField {
             Objects.equals(this.type, other.type);
   }
 
+  /**
+   * Determine if one column is logically equivalent to another. This is
+   * a tricky issue. The rules here:
+   * <ul>
+   * <li>The other schema is assumed to be non-null (unlike
+   * <tt>equals()</tt>).</li>
+   * <li>Names must be identical, ignoring case. (Drill, like SQL, is
+   * case insensitive.)
+   * <li>Type, mode, precision and scale must be identical.</li>
+   * <li>Child columns are ignored unless the type is a map. That is, the
+   * hidden "$bits" and "$offsets" vector columns are not compared, as
+   * one schema may be an "original" (without these hidden columns) while
+   * the other may come from a vector (which has the hidden columns added.
+   * The standard <tt>equals()</tt> comparison does consider hidden
+   * columns.</li>
+   * <li>For maps, the child columns are compared recursively. This version
+   * requires that the two sets of columns appear in the same order. (It
+   * assumes it is being used in a context where column indexes make
+   * sense.) Operators that want to reconcile two maps that differ only in
+   * column order need a different comparison.</li>
+   * </ul>
+   *
+   * @param other another field
+   * @return <tt>true</tt> if the columns are identical according to the
+   * above rules, <tt>false</tt> if they differ
+   */
+
   public boolean isEquivalent(MaterializedField other) {
+    if (this == other) {
+      return true;
+    }
     if (! name.equalsIgnoreCase(other.name)) {
       return false;
     }
@@ -199,7 +233,7 @@ public class MaterializedField {
       return true;
     }
 
-    if (children == null  ||  other.children == null) {
+    if (children == null || other.children == null) {
       return children == other.children;
     }
     if (children.size() != other.children.size()) {
@@ -226,11 +260,12 @@ public class MaterializedField {
    * Includes field name, its type with precision and scale if any and data mode.
    * Nested fields if any are included. Number of nested fields to include is limited to 10.</p>
    *
-   * <b>FIELD_NAME(TYPE(PRECISION,SCALE):DATA_MODE)[NESTED_FIELD_1, NESTED_FIELD_2]</b>
+   * <b>FIELD_NAME(TYPE(PRECISION,SCALE):DATA_MODE)[NESTED_FIELD_1, NESTED_FIELD_2]</b><br>
    * <p>Example: ok(BIT:REQUIRED), col(VARCHAR(3):OPTIONAL), emp_id(DECIMAL28SPARSE(6,0):REQUIRED)</p>
    *
    * @return materialized field string representation
    */
+
   @Override
   public String toString() {
     final int maxLen = 10;
@@ -258,7 +293,7 @@ public class MaterializedField {
         .append(childString);
 
     return builder.toString();
-}
+  }
 
   /**
    * Return true if two fields have identical MinorType and Mode.

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/record/TupleMetadata.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/record/TupleMetadata.java b/exec/vector/src/main/java/org/apache/drill/exec/record/TupleMetadata.java
new file mode 100644
index 0000000..8f597be
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/record/TupleMetadata.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.record;
+
+import java.util.List;
+
+/**
+ * Metadata description of the schema of a row or a map.
+ * In Drill, both rows and maps are
+ * tuples: both are an ordered collection of values, defined by a
+ * schema. Each tuple has a schema that defines the column ordering
+ * for indexed access. Each tuple also provides methods to get column
+ * accessors by name or index.
+ * <p>
+ * Models the physical schema of a row set showing the logical hierarchy of fields
+ * with map fields as first-class fields. Map members appear as children
+ * under the map, much as they appear in the physical value-vector
+ * implementation.
+ * <ul>
+ * <li>Provides fast lookup by name or index.</li>
+ * <li>Provides a nested schema, in this same form, for maps.</li>
+ * </ul>
+ * This form is useful when performing semantic analysis and when
+ * working with vectors.
+ * <p>
+ * In the future, this structure will also gather metadata useful
+ * for vector processing such as expected widths and so on.
+ */
+
+public interface TupleMetadata extends Iterable<ColumnMetadata> {
+
+  /**
+   * Add a new column to the schema.
+   *
+   * @param columnSchema
+   * @return the index of the new column
+   */
+  ColumnMetadata add(MaterializedField field);
+  int addColumn(ColumnMetadata column);
+
+  int size();
+  boolean isEmpty();
+  int index(String name);
+  ColumnMetadata metadata(int index);
+  ColumnMetadata metadata(String name);
+  MaterializedField column(int index);
+  MaterializedField column(String name);
+  boolean isEquivalent(TupleMetadata other);
+  ColumnMetadata parent();
+
+  /**
+   * Return the schema as a list of <tt>MaterializedField</tt> objects
+   * which can be used to create other schemas. Not valid for a
+   * flattened schema.
+   *
+   * @return a list of the top-level fields. Maps contain their child
+   * fields
+   */
+
+  List<MaterializedField> toFieldList();
+
+  /**
+   * Full name of the column. Note: this name cannot be used to look up
+   * the column because of ambiguity. The name "a.b.c" may mean a single
+   * column with that name, or may mean maps "a", and "b" with column "c",
+   * etc.
+   *
+   * @return full, dotted, column name
+   */
+
+  String fullName(ColumnMetadata column);
+  String fullName(int index);
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/record/TupleNameSpace.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/record/TupleNameSpace.java b/exec/vector/src/main/java/org/apache/drill/exec/record/TupleNameSpace.java
new file mode 100644
index 0000000..5853c93
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/record/TupleNameSpace.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.record;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.drill.common.map.CaseInsensitiveMap;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Implementation of a tuple name space. Tuples allow both indexed and
+ * named access to their members.
+ *
+ * @param <T> the type of object representing each column
+ */
+
+public class TupleNameSpace<T> implements Iterable<T> {
+  private final Map<String,Integer> nameSpace = CaseInsensitiveMap.newHashMap();
+  private final List<T> entries = new ArrayList<>();
+
+  public int add(String key, T value) {
+    if (indexOf(key) != -1) {
+      throw new IllegalArgumentException("Duplicate entry: " + key);
+    }
+    int index = entries.size();
+    nameSpace.put(key, index);
+    entries.add(value);
+    return index;
+  }
+
+  public T get(int index) {
+    return entries.get(index);
+  }
+
+  public T get(String key) {
+    int index = indexOf(key);
+    if (index == -1) {
+      return null;
+    }
+    return get(index);
+  }
+
+  public int indexOf(String key) {
+    Integer index = nameSpace.get(key);
+    if (index == null) {
+      return -1;
+    }
+    return index;
+  }
+
+  public int count() { return entries.size(); }
+
+  @Override
+  public Iterator<T> iterator() {
+    return entries.iterator();
+  }
+
+  public boolean isEmpty() {
+    return entries.isEmpty();
+  }
+
+  public List<T> entries() {
+    return ImmutableList.copyOf(entries);
+  }
+
+  @Override
+  public String toString() {
+    return entries.toString();
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/AllocationHelper.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/AllocationHelper.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/AllocationHelper.java
index 100997e..4fd0cbd 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/AllocationHelper.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/AllocationHelper.java
@@ -39,7 +39,7 @@ public class AllocationHelper {
       ((VariableWidthVector) vector).allocateNew(valueCount * bytesPerValue, valueCount);
     } else if (vector instanceof RepeatedFixedWidthVectorLike) {
       ((RepeatedFixedWidthVectorLike) vector).allocateNew(valueCount, childValCount);
-    } else if (vector instanceof RepeatedVariableWidthVectorLike && childValCount > 0 && bytesPerValue > 0) {
+    } else if (vector instanceof RepeatedVariableWidthVectorLike) {
       // Assertion thrown if byte count is zero in the full allocateNew,
       // so use default version instead.
       ((RepeatedVariableWidthVectorLike) vector).allocateNew(childValCount * bytesPerValue, valueCount, childValCount);

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/BaseDataValueVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/BaseDataValueVector.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/BaseDataValueVector.java
index e98a417..4391e8c 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/BaseDataValueVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/BaseDataValueVector.java
@@ -37,6 +37,16 @@ public abstract class BaseDataValueVector extends BaseValueVector {
     data = allocator.getEmpty();
   }
 
+  /**
+   * Core of vector allocation. Given a new size (which must be a power of two), allocate
+   * the new buffer, copy the current values, and leave the unused parts garbage-filled.
+   *
+   * @param newAllocationSize new buffer size as a power of two
+   * @return the new buffer
+   */
+
+  public abstract DrillBuf reallocRaw(int newAllocationSize);
+
   @Override
   public void clear() {
     if (data != null) {
@@ -82,6 +92,11 @@ public abstract class BaseDataValueVector extends BaseValueVector {
     return data.writerIndex();
   }
 
+  @Override
+  public int getAllocatedSize() {
+    return data.capacity();
+  }
+
   public DrillBuf getBuffer() { return data; }
 
   /**
@@ -101,6 +116,7 @@ public abstract class BaseDataValueVector extends BaseValueVector {
     // No state in an Accessor to reset
   }
 
+  @Override
   public void collectLedgers(Set<BufferLedger> ledgers) {
     BufferLedger ledger = data.getLedger();
     if (ledger != null) {

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/BitVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/BitVector.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/BitVector.java
index f879fc4..219db12 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/BitVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/BitVector.java
@@ -193,6 +193,16 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe
     allocationSizeInBytes = curSize;
   }
 
+  // This version uses the base version because this vector appears to not be
+  // used, so not worth the effort to avoid zero-fill.
+
+  public DrillBuf reallocRaw(int newAllocationSize) {
+    while (allocationSizeInBytes < newAllocationSize) {
+      reAlloc();
+    }
+    return data;
+  }
+
   /**
    * {@inheritDoc}
    */
@@ -438,20 +448,6 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe
       set(index, value);
     }
 
-    public void setScalar(int index, int value) throws VectorOverflowException {
-      if (index >= MAX_COUNT) {
-        throw new VectorOverflowException();
-      }
-      setSafe(index, value);
-    }
-
-    public void setArrayItem(int index, int value) throws VectorOverflowException {
-      if (index >= MAX_CAPACITY) {
-        throw new VectorOverflowException();
-      }
-      setSafe(index, value);
-    }
-
     public void setSafe(int index, BitHolder holder) {
       while(index >= getValueCapacity()) {
         reAlloc();
@@ -459,20 +455,6 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe
       set(index, holder.value);
     }
 
-    public void setScalar(int index, BitHolder holder) throws VectorOverflowException {
-      if (index >= MAX_COUNT) {
-        throw new VectorOverflowException();
-      }
-      setSafe(index, holder);
-    }
-
-    public void setArrayItem(int index, BitHolder holder) throws VectorOverflowException {
-      if (index >= MAX_CAPACITY) {
-        throw new VectorOverflowException();
-      }
-      setSafe(index, holder);
-    }
-
     public void setSafe(int index, NullableBitHolder holder) {
       while(index >= getValueCapacity()) {
         reAlloc();
@@ -480,20 +462,6 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe
       set(index, holder.value);
     }
 
-    public void setScalar(int index, NullableBitHolder holder) throws VectorOverflowException {
-      if (index >= MAX_COUNT) {
-        throw new VectorOverflowException();
-      }
-      setSafe(index, holder);
-    }
-
-    public void setArrayItem(int index, NullableBitHolder holder) throws VectorOverflowException {
-      if (index >= MAX_CAPACITY) {
-        throw new VectorOverflowException();
-      }
-      setSafe(index, holder);
-    }
-
     @Override
     public final void setValueCount(int valueCount) {
       int currentValueCapacity = getValueCapacity();

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/FixedWidthVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/FixedWidthVector.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/FixedWidthVector.java
index a9a1631..09bcdd8 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/FixedWidthVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/FixedWidthVector.java
@@ -17,7 +17,6 @@
  */
 package org.apache.drill.exec.vector;
 
-
 public interface FixedWidthVector extends ValueVector {
 
   /**
@@ -27,8 +26,8 @@ public interface FixedWidthVector extends ValueVector {
    */
   void allocateNew(int valueCount);
 
-/**
- * Zero out the underlying buffer backing this vector.
- */
+  /**
+   * Zero out the underlying buffer backing this vector.
+   */
   void zeroVector();
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/ObjectVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/ObjectVector.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/ObjectVector.java
index c9edeb0..8d515d8 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/ObjectVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/ObjectVector.java
@@ -95,8 +95,7 @@ public class ObjectVector extends BaseValueVector {
     }
 
     @Override
-    public void generateTestData(int values) {
-    }
+    public void generateTestData(int values) { }
 
     @Override
     public void exchange(ValueVector.Mutator other) { }
@@ -130,6 +129,9 @@ public class ObjectVector extends BaseValueVector {
   }
 
   @Override
+  public int getAllocatedSize() { return 0; }
+
+  @Override
   public int getBufferSizeFor(final int valueCount) {
     throw new UnsupportedOperationException("ObjectVector does not support this");
   }
@@ -147,9 +149,7 @@ public class ObjectVector extends BaseValueVector {
   }
 
   @Override
-  public MaterializedField getField() {
-    return field;
-  }
+  public MaterializedField getField() { return field; }
 
   @Override
   public TransferPair getTransferPair(BufferAllocator allocator) {
@@ -172,14 +172,10 @@ public class ObjectVector extends BaseValueVector {
   }
 
   @Override
-  public int getValueCapacity() {
-    return maxCount;
-  }
+  public int getValueCapacity() { return maxCount; }
 
   @Override
-  public Accessor getAccessor() {
-    return accessor;
-  }
+  public Accessor getAccessor() { return accessor; }
 
   @Override
   public DrillBuf[] getBuffers(boolean clear) {
@@ -197,9 +193,7 @@ public class ObjectVector extends BaseValueVector {
   }
 
   @Override
-  public Mutator getMutator() {
-    return mutator;
-  }
+  public Mutator getMutator() { return mutator; }
 
   @Override
   public Iterator<ValueVector> iterator() {
@@ -222,9 +216,7 @@ public class ObjectVector extends BaseValueVector {
     }
 
     @Override
-    public int getValueCount() {
-      return count;
-    }
+    public int getValueCount() { return count; }
 
     public Object get(int index) {
       return getObject(index);

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java
index 8288fe2..5565fa4 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java
@@ -27,8 +27,6 @@ import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.record.TransferPair;
 import org.apache.drill.exec.vector.complex.reader.FieldReader;
 
-import static org.apache.calcite.sql.parser.impl.SqlParserImplConstants.C;
-
 /** UntypedNullVector is to represent a value vector with {@link org.apache.drill.common.types.MinorType#NULL}
  *  All values in the vector represent two semantic implications: 1) the value is unknown, 2) the type is unknown.
  *  Because of this, we only have to keep track of the number of values in value vector,
@@ -37,7 +35,6 @@ import static org.apache.calcite.sql.parser.impl.SqlParserImplConstants.C;
  *
  */
 public final class UntypedNullVector extends BaseDataValueVector implements FixedWidthVector {
-  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(UntypedNullVector.class);
 
   /**
    * Width of each fixed-width value.
@@ -57,14 +54,10 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
   public FieldReader getReader() { throw new UnsupportedOperationException(); }
 
   @Override
-  public int getBufferSizeFor(final int valueCount) {
-    return 0;
-  }
+  public int getBufferSizeFor(final int valueCount) { return 0; }
 
   @Override
-  public int getValueCapacity(){
-    return ValueVector.MAX_ROW_COUNT;
-  }
+  public int getValueCapacity() { return ValueVector.MAX_ROW_COUNT; }
 
   @Override
   public Accessor getAccessor() { return accessor; }
@@ -73,31 +66,29 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
   public Mutator getMutator() { return mutator; }
 
   @Override
-  public void setInitialCapacity(final int valueCount) {
-  }
+  public void setInitialCapacity(final int valueCount) { }
 
   @Override
-  public void allocateNew() {
-  }
+  public void allocateNew() { }
 
   @Override
-  public boolean allocateNewSafe() {
-    return true;
-  }
+  public boolean allocateNewSafe() { return true; }
 
   @Override
-  public void allocateNew(final int valueCount) {
-  }
+  public void allocateNew(final int valueCount) { }
 
   @Override
-  public void reset() {
-  }
+  public void reset() { }
 
   /**
    * {@inheritDoc}
    */
   @Override
-  public void zeroVector() {
+  public void zeroVector() { }
+
+  @Override
+  public DrillBuf reallocRaw(int newAllocationSize) {
+    throw new UnsupportedOperationException();
   }
 
   @Override
@@ -127,19 +118,15 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
     return new TransferImpl((UntypedNullVector) to);
   }
 
-  public void transferTo(UntypedNullVector target){
-  }
+  public void transferTo(UntypedNullVector target) { }
 
-  public void splitAndTransferTo(int startIndex, int length, UntypedNullVector target) {
-  }
+  public void splitAndTransferTo(int startIndex, int length, UntypedNullVector target) { }
 
   @Override
-  public int getPayloadByteCount(int valueCount) {
-    return 0;
-  }
+  public int getPayloadByteCount(int valueCount) { return 0; }
 
   private class TransferImpl implements TransferPair{
-    private UntypedNullVector to;
+    private final UntypedNullVector to;
 
     public TransferImpl(MaterializedField field, BufferAllocator allocator){
       to = new UntypedNullVector(field, allocator);
@@ -150,9 +137,7 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
     }
 
     @Override
-    public UntypedNullVector getTo(){
-      return to;
-    }
+    public UntypedNullVector getTo() { return to; }
 
     @Override
     public void transfer(){
@@ -173,11 +158,9 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
     }
   }
 
-  public void copyFrom(int fromIndex, int thisIndex, UntypedNullVector from){
-  }
+  public void copyFrom(int fromIndex, int thisIndex, UntypedNullVector from) { }
 
-  public void copyFromSafe(int fromIndex, int thisIndex, UntypedNullVector from){
-  }
+  public void copyFromSafe(int fromIndex, int thisIndex, UntypedNullVector from) { }
 
   private void checkBounds(int index) {
     if (index < 0 || index >= valueCount) {
@@ -216,7 +199,6 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
     public void get(int index, UntypedNullHolder holder) {
       checkBounds(index);
     }
-
   }
 
   /**
@@ -224,7 +206,7 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
    * value counts.
    *
    */
-   public final class Mutator extends BaseMutator {
+  public final class Mutator extends BaseMutator {
 
     private Mutator() {}
 
@@ -266,5 +248,4 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
       UntypedNullVector.this.valueCount = valueCount;
     }
   }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/ValueVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/ValueVector.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/ValueVector.java
index a090cad..bc06803 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/ValueVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/ValueVector.java
@@ -25,6 +25,7 @@ import io.netty.buffer.DrillBuf;
 
 import org.apache.drill.exec.exception.OutOfMemoryException;
 import org.apache.drill.exec.memory.AllocationManager.BufferLedger;
+import org.apache.drill.exec.memory.AllocationManager;
 import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.proto.UserBitShared.SerializedField;
 import org.apache.drill.exec.record.MaterializedField;
@@ -32,12 +33,15 @@ import org.apache.drill.exec.record.TransferPair;
 import org.apache.drill.exec.vector.complex.reader.FieldReader;
 
 /**
- * An abstraction that is used to store a sequence of values in an individual column.
+ * An abstraction that is used to store a sequence of values in an individual
+ * column.
  *
- * A {@link ValueVector value vector} stores underlying data in-memory in a columnar fashion that is compact and
- * efficient. The column whose data is stored, is referred by {@link #getField()}.
+ * A {@link ValueVector value vector} stores underlying data in-memory in a
+ * columnar fashion that is compact and efficient. The column whose data is
+ * stored, is referred by {@link #getField()}.
  *
- * A vector when instantiated, relies on a {@link org.apache.drill.exec.record.DeadBuf dead buffer}. It is important
+ * A vector when instantiated, relies on a
+ * {@link org.apache.drill.exec.record.DeadBuf dead buffer}. It is important
  * that vector is allocated before attempting to read or write.
  *
  * There are a few "rules" around vectors:
@@ -45,37 +49,34 @@ import org.apache.drill.exec.vector.complex.reader.FieldReader;
  * <ul>
  *   <li>Values need to be written in order (e.g. index 0, 1, 2, 5).</li>
  *   <li>Null vectors start with all values as null before writing anything.</li>
- *   <li>For variable width types, the offset vector should be all zeros before writing.</li>
+ *   <li>For variable width types, the offset vector should be all zeros before
+ *   writing.</li>
  *   <li>You must call setValueCount before a vector can be read.</li>
  *   <li>You should never write to a vector once it has been read.</li>
- *   <li>Vectors may not grow larger than the number of bytes specified
- *   in {@link #MAX_BUFFER_SIZE} to prevent memory fragmentation. Use the
+ *   <li>Vectors may not grow larger than the number of bytes specified in
+ *   {@link #MAX_BUFFER_SIZE} to prevent memory fragmentation. Use the
  *   <tt>setBounded()</tt> methods in the mutator to enforce this rule.</li>
  * </ul>
  *
- * Please note that the current implementation doesn't enforce those rules, hence we may find few places that
- * deviate from these rules (e.g. offset vectors in Variable Length and Repeated vector)
+ * Please note that the current implementation doesn't enforce those rules,
+ * hence we may find few places that deviate from these rules (e.g. offset
+ * vectors in Variable Length and Repeated vector)
  *
  * This interface "should" strive to guarantee this order of operation:
  * <blockquote>
- * allocate > mutate > setvaluecount > access > clear (or allocate to start the process over).
+ * allocate > mutate > setvaluecount > access > clear (or allocate
+ * to start the process over).
  * </blockquote>
  */
+
 public interface ValueVector extends Closeable, Iterable<ValueVector> {
 
   /**
    * Maximum allowed size of the buffer backing a value vector.
+   * Set to the Netty chunk size to prevent memory fragmentation.
    */
 
-  int MAX_BUFFER_SIZE = VectorUtils.maxSize();
-
-  /**
-   * Debug-time system option that artificially limits vector lengths
-   * for testing. Must be set prior to the first reference to this
-   * class. (Made deliberately difficult to prevent misuse...)
-   */
-
-  String MAX_BUFFER_SIZE_KEY = "drill.max_vector";
+  int MAX_BUFFER_SIZE = AllocationManager.chunkSize();
 
   /**
    * Maximum allowed row count in a vector. Repeated vectors
@@ -167,10 +168,24 @@ public interface ValueVector extends Closeable, Iterable<ValueVector> {
 
   /**
    * Returns the number of bytes that is used by this vector instance.
+   * This is a bit of a misnomer. Returns the number of bytes used by
+   * data in this instance.
    */
   int getBufferSize();
 
   /**
+   * Returns the total size of buffers allocated by this vector. Has
+   * meaning only when vectors are directly allocated and each vector
+   * has its own buffer. Does not have meaning for vectors deserialized
+   * from the network or disk in which multiple vectors share the
+   * same vector.
+   *
+   * @return allocated buffer size, in bytes
+   */
+
+  int getAllocatedSize();
+
+  /**
    * Returns the number of bytes that is used by this vector if it holds the given number
    * of values. The result will be the same as if Mutator.setValueCount() were called, followed
    * by calling getBufferSize(), but without any of the closing side-effects that setValueCount()

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/VariableWidthVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/VariableWidthVector.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/VariableWidthVector.java
index d04234c..f5373d0 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/VariableWidthVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/VariableWidthVector.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -33,8 +33,10 @@ public interface VariableWidthVector extends ValueVector {
    */
   int getByteCapacity();
 
+  @Override
   VariableWidthMutator getMutator();
 
+  @Override
   VariableWidthAccessor getAccessor();
 
   interface VariableWidthAccessor extends Accessor {

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/VectorUtils.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/VectorUtils.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/VectorUtils.java
deleted file mode 100644
index 6b29eb2..0000000
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/VectorUtils.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.vector;
-
-public class VectorUtils {
-
-  /**
-   * Vectors cannot be any larger than the Netty memory allocation
-   * block size.
-   */
-
-  private static final int ABSOLUTE_MAX_SIZE = 16 * 1024 * 1024;
-
-  /**
-   * Minimum size selected to prevent pathological performance if vectors
-   * are limited to an unusably small size. This limit is a judgment call,
-   * not based on any known limits.
-   */
-
-  private static final int ABSOLUTE_MIN_SIZE = 16 * 1024;
-
-  private VectorUtils() { }
-
-  /**
-   * Static function called once per run to compute the maximum
-   * vector size, in bytes. Normally uses the hard-coded limit,
-   * but allows setting a system property to override the limit
-   * for testing. The configured value must be within reasonable
-   * bounds.
-   * @return the maximum vector size, in bytes
-   */
-
-  static int maxSize() {
-    String prop = System.getProperty( ValueVector.MAX_BUFFER_SIZE_KEY );
-    int value = ABSOLUTE_MAX_SIZE;
-    if (prop != null) {
-      try {
-        value = Integer.parseInt(prop);
-        value = Math.max(value, ABSOLUTE_MIN_SIZE);
-        value = Math.min(value, ABSOLUTE_MAX_SIZE);
-      } catch (NumberFormatException e) {
-        // Ignore
-      }
-    }
-    return value;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/ZeroVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/ZeroVector.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/ZeroVector.java
index e6f0544..fc89d71 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/ZeroVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/ZeroVector.java
@@ -17,6 +17,7 @@
  */
 package org.apache.drill.exec.vector;
 
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.Set;
 
@@ -105,13 +106,16 @@ public class ZeroVector implements ValueVector {
 
   @Override
   public Iterator<ValueVector> iterator() {
-    return Iterators.emptyIterator();
+    return Collections.emptyIterator();
   }
 
   @Override
   public int getBufferSize() { return 0; }
 
   @Override
+  public int getAllocatedSize() { return 0; }
+
+  @Override
   public int getBufferSizeFor(final int valueCount) { return 0; }
 
   @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/AccessorUtilities.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/AccessorUtilities.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/AccessorUtilities.java
deleted file mode 100644
index 708d0db..0000000
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/AccessorUtilities.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.vector.accessor;
-
-import java.math.BigDecimal;
-
-import org.joda.time.Duration;
-import org.joda.time.Period;
-
-public class AccessorUtilities {
-
-  private AccessorUtilities() { }
-
-  public static void setFromInt(ColumnWriter writer, int value) {
-    switch (writer.valueType()) {
-    case BYTES:
-      writer.setBytes(Integer.toHexString(value).getBytes());
-      break;
-    case DOUBLE:
-      writer.setDouble(value);
-      break;
-    case INTEGER:
-      writer.setInt(value);
-      break;
-    case LONG:
-      writer.setLong(value);
-      break;
-    case STRING:
-      writer.setString(Integer.toString(value));
-      break;
-    case DECIMAL:
-      writer.setDecimal(BigDecimal.valueOf(value));
-      break;
-    case PERIOD:
-      writer.setPeriod(Duration.millis(value).toPeriod());
-      break;
-    default:
-      throw new IllegalStateException("Unknown writer type: " + writer.valueType());
-    }
-  }
-
-  public static int sv4Batch(int sv4Index) {
-    return sv4Index >>> 16;
-  }
-
-  public static int sv4Index(int sv4Index) {
-    return sv4Index & 0xFFFF;
-  }
-
-  public static void setBooleanArray(ArrayWriter arrayWriter, boolean[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setInt(value[i] ? 1 : 0);
-    }
-  }
-
-  public static void setByteArray(ArrayWriter arrayWriter, byte[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setInt(value[i]);
-    }
-  }
-
-  public static void setShortArray(ArrayWriter arrayWriter, short[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setInt(value[i]);
-    }
-  }
-
-  public static void setIntArray(ArrayWriter arrayWriter, int[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setInt(value[i]);
-    }
-  }
-
-  public static void setLongArray(ArrayWriter arrayWriter, long[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setLong(value[i]);
-    }
-  }
-
-  public static void setFloatArray(ArrayWriter arrayWriter, float[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setDouble(value[i]);
-    }
-  }
-
-  public static void setDoubleArray(ArrayWriter arrayWriter, double[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setDouble(value[i]);
-    }
-  }
-
-  public static void setStringArray(ArrayWriter arrayWriter, String[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setString(value[i]);
-    }
-  }
-
-  public static void setPeriodArray(ArrayWriter arrayWriter, Period[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setPeriod(value[i]);
-    }
-  }
-
-  public static void setBigDecimalArray(ArrayWriter arrayWriter,
-      BigDecimal[] value) {
-    for (int i = 0; i < value.length; i++) {
-      arrayWriter.setDecimal(value[i]);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayReader.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayReader.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayReader.java
index 040dcda..8f33f0e 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayReader.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayReader.java
@@ -17,36 +17,90 @@
  */
 package org.apache.drill.exec.vector.accessor;
 
-import java.math.BigDecimal;
-
-import org.joda.time.Period;
-
 /**
- * Interface to access the values of an array column. In general, each
- * vector implements just one of the get methods. Check the vector type
- * to know which method to use. Though, generally, when writing test
- * code, the type is known to the test writer.
- * <p>
- * Arrays allow random access to the values within the array. The index
- * passed to each method is the index into the array for the current
- * row and column. (This means that arrays are three dimensional:
- * the usual (row, column) dimensions plus an array index dimension:
- * (row, column, array index).
- * <p>
- * Note that the <tt>isNull()</tt> method is provided for completeness,
- * but no Drill array allows null values at present.
+ * Generic array reader. An array is one of the following:
+ * <ul>
+ * <li>Array of scalars. Read the values using {@link #elements()}, which provides
+ * an array-like access to the scalars.</li>
+ * <li>A repeated map. Use {@link #tuple(int)} to get a tuple reader for a
+ * specific array element. Use {@link #size()} to learn the number of maps in
+ * the array.</li>
+ * <li>List of lists. Use the {@link #array(int)} method to get the nested list
+ * at a given index. Use {@link #size()} to learn the number of maps in
+ * the array.</li>
+ * </ul>
+ * {@see ArrayWriter}
  */
 
-public interface ArrayReader extends ColumnAccessor {
+public interface ArrayReader {
+
+  /**
+   * Number of elements in the array.
+   * @return the number of elements
+   */
+
   int size();
-  boolean isNull(int index);
-  int getInt(int index);
-  long getLong(int index);
-  double getDouble(int index);
-  String getString(int index);
-  byte[] getBytes(int index);
-  BigDecimal getDecimal(int index);
-  Period getPeriod(int index);
-  TupleReader map(int index);
+
+  /**
+   * The object type of the list entry. All entries have the same
+   * type.
+   * @return the object type of each entry
+   */
+
+  ObjectType entryType();
+
+  /**
+   * Return a reader for the elements of a scalar array.
+   * @return reader for scalar elements
+   */
+
+  ScalarElementReader elements();
+
+  /**
+   * Return a generic object reader for the array entry. Not available
+   * for scalar elements. Positions the reader to read the selected
+   * element.
+   *
+   * @param index array index
+   * @return generic object reader
+   */
+
+  ObjectReader entry(int index);
+  TupleReader tuple(int index);
   ArrayReader array(int index);
+
+  /**
+   * Return the generic object reader for the array element. This
+   * version <i>does not</i> position the reader, the client must
+   * call {@link setPosn()} to set the position. This form allows
+   * up-front setup of the readers when convenient for the caller.
+   */
+
+  ObjectReader entry();
+  TupleReader tuple();
+  ArrayReader array();
+
+  /**
+   * Set the array reader to read a given array entry. Not used for
+   * scalars, only for maps and arrays when using the non-indexed
+   * methods {@link #entry()}, {@link #tuple()} and {@link #array()}.
+   */
+
+  void setPosn(int index);
+
+  /**
+   * Return the entire array as an <tt>List</tt> of objects.
+   * Note, even if the array is scalar, the elements are still returned
+   * as a list. This method is primarily for testing.
+   * @return array as a <tt>List</tt> of objects
+   */
+
+  Object getObject();
+
+  /**
+   * Return the entire array as a string. Primarily for debugging.
+   * @return string representation of the array
+   */
+
+  String getAsString();
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayWriter.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayWriter.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayWriter.java
index 16ff89e..49a1e77 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayWriter.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ArrayWriter.java
@@ -18,25 +18,65 @@
 package org.apache.drill.exec.vector.accessor;
 
 /**
- * Writer for values into an array. Array writes are write-once,
- * sequential: each call to a <tt>setFoo()</tt> method writes a
- * value and advances the array index.
+ * Writer for values into an array. Array writes are write-once, sequential:
+ * each call to a <tt>setFoo()</tt> method writes a value and advances the array
+ * index.
  * <p>
  * {@see ArrayReader}
  */
 
-public interface ArrayWriter extends ColumnAccessor, ScalarWriter {
+public interface ArrayWriter {
+
+  /**
+   * Number of elements written thus far to the array.
+   * @return the number of elements
+   */
 
   int size();
 
   /**
-   * Determine if the next position is valid for writing. Will be invalid
-   * if the writer hits a size or other limit.
+   * The object type of the list entry. All entries have the same
+   * type.
+   * @return the object type of each entry
+   */
+
+  ObjectWriter entry();
+
+  /**
+   * Return a generic object writer for the array entry.
+   *
+   * @return generic object reader
+   */
+
+  ObjectType entryType();
+  ScalarWriter scalar();
+  TupleWriter tuple();
+  ArrayWriter array();
+
+  /**
+   * When the array contains a tuple or an array, call <tt>save()</tt>
+   * after each array value. Not necessary when writing scalars; each
+   * set operation calls save automatically.
+   */
+
+  void save();
+
+  /**
+   * Write the values of an array from a list of arguments.
+   * @param values values for each array element
+   * @throws VectorOverflowException
+   */
+  void set(Object ...values);
+
+  /**
+   * Write the array given an array of values. The type of array must match
+   * the type of element in the array. That is, if the value is an <tt>int</tt>,
+   * provide an <tt>int[]</tt> array.
    *
-   * @return true if another item is available and the reader is positioned
-   * at that item, false if no more items are available and the reader
-   * is no longer valid
+   * @param array array of values to write
+   * @throws VectorOverflowException
    */
 
-  boolean valid();
+  void setObject(Object array);
+//  void setList(List<? extends Object> list);
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnAccessor.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnAccessor.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnAccessor.java
deleted file mode 100644
index 44cd48a..0000000
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnAccessor.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.vector.accessor;
-
-/**
- * Common base interface for columns readers and writers. Provides
- * the access type for the column. Note that multiple Drill types and
- * data modes map to the same access type.
- */
-
-public interface ColumnAccessor {
-  public enum ValueType {
-    INTEGER, LONG, DOUBLE, STRING, BYTES, DECIMAL, PERIOD, ARRAY, MAP
-  }
-
-  /**
-   * Describe the type of the value. This is a compression of the
-   * value vector type: it describes which method will return the
-   * vector value.
-   * @return the value type which indicates which get method
-   * is valid for the column
-   */
-
-  ColumnAccessor.ValueType valueType();
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnReader.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnReader.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnReader.java
deleted file mode 100644
index 4932567..0000000
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnReader.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.vector.accessor;
-
-import java.math.BigDecimal;
-
-import org.joda.time.Period;
-
-/**
- * Defines a reader to obtain values from value vectors using
- * a simple, uniform interface. Vector values are mapped to
- * their "natural" representations: the representation closest
- * to the actual vector value. For date and time values, this
- * generally means a numeric value. Applications can then map
- * this value to Java objects as desired. Decimal types all
- * map to BigDecimal as that is the only way in Java to
- * represent large decimal values.
- * <p>
- * In general, a column maps to just one value. However, derived
- * classes may choose to provide type conversions if convenient.
- * An exception is thrown if a call is made to a method that
- * is not supported by the column type.
- * <p>
- * Values of scalars are provided directly, using the get method
- * for the target type. Maps and arrays are structured types and
- * require another level of reader abstraction to access each value
- * in the structure.
- */
-
-public interface ColumnReader extends ColumnAccessor {
-
-  /**
-   * Report if the column is null. Non-nullable columns always
-   * return <tt>false</tt>.
-   * @return true if the column value is null, false if the
-   * value is set
-   */
-  boolean isNull();
-  int getInt();
-  long getLong();
-  double getDouble();
-  String getString();
-  byte[] getBytes();
-  BigDecimal getDecimal();
-  Period getPeriod();
-  Object getObject();
-  TupleReader map();
-  ArrayReader array();
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnReaderIndex.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnReaderIndex.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnReaderIndex.java
new file mode 100644
index 0000000..b40b705
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnReaderIndex.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.vector.accessor;
+
+/**
+ * Index into a vector batch, or an array, at read time.
+ * Supports direct, indirect and hyper-batches.
+ */
+
+public interface ColumnReaderIndex {
+  int batchIndex();
+  int vectorIndex();
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/40de8ca4/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnWriter.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnWriter.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnWriter.java
deleted file mode 100644
index 0cc691c..0000000
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/ColumnWriter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.vector.accessor;
-
-/**
- * Defines a writer to set values for value vectors using
- * a simple, uniform interface. Vector values are mapped to
- * their "natural" representations: the representation closest
- * to the actual vector value. For date and time values, this
- * generally means a numeric value. Applications can then map
- * this value to Java objects as desired. Decimal types all
- * map to BigDecimal as that is the only way in Java to
- * represent large decimal values.
- * <p>
- * In general, a column maps to just one value. However, derived
- * classes may choose to provide type conversions if convenient.
- * An exception is thrown if a call is made to a method that
- * is not supported by the column type.
- * <p>
- * Values of scalars are set directly, using the get method
- * for the target type. Maps and arrays are structured types and
- * require another level of writer abstraction to access each value
- * in the structure.
- */
-
-public interface ColumnWriter extends ColumnAccessor, ScalarWriter {
-  void setNull();
-  TupleWriter map();
-  ArrayWriter array();
-}