arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject [4/5] arrow git commit: ARROW-259: Use Flatbuffer Field type instead of MaterializedField
Date Thu, 18 Aug 2016 23:30:37 GMT
http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/MapWriters.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/MapWriters.java b/java/vector/src/main/codegen/templates/MapWriters.java
index 42f3982..af29228 100644
--- a/java/vector/src/main/codegen/templates/MapWriters.java
+++ b/java/vector/src/main/codegen/templates/MapWriters.java
@@ -17,7 +17,7 @@
  */
 
 <@pp.dropOutputFile />
-<#list ["Single", "Repeated"] as mode>
+<#list ["Single"] as mode>
 <@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/${mode}MapWriter.java" />
 <#if mode == "Single">
 <#assign containerClass = "MapVector" />
@@ -51,16 +51,8 @@ public class ${mode}MapWriter extends AbstractFieldWriter {
   private final Map<String, FieldWriter> fields = Maps.newHashMap();
   <#if mode == "Repeated">private int currentChildIndex = 0;</#if>
 
-  private final boolean unionEnabled;
-
-  public ${mode}MapWriter(${containerClass} container, FieldWriter parent, boolean unionEnabled) {
-    super(parent);
+  public ${mode}MapWriter(${containerClass} container) {
     this.container = container;
-    this.unionEnabled = unionEnabled;
-  }
-
-  public ${mode}MapWriter(${containerClass} container, FieldWriter parent) {
-    this(container, parent, false);
   }
 
   @Override
@@ -74,7 +66,7 @@ public class ${mode}MapWriter extends AbstractFieldWriter {
   }
 
   @Override
-  public MaterializedField getField() {
+  public Field getField() {
       return container.getField();
   }
 
@@ -83,12 +75,8 @@ public class ${mode}MapWriter extends AbstractFieldWriter {
       FieldWriter writer = fields.get(name.toLowerCase());
     if(writer == null){
       int vectorCount=container.size();
-        MapVector vector = container.addOrGet(name, MapVector.TYPE, MapVector.class);
-      if(!unionEnabled){
-        writer = new SingleMapWriter(vector, this);
-      } else {
-        writer = new PromotableWriter(vector, container);
-      }
+      MapVector vector = container.addOrGet(name, MinorType.MAP, MapVector.class);
+      writer = new PromotableWriter(vector, container);
       if(vectorCount != container.size()) {
         writer.allocate();
       }
@@ -125,11 +113,7 @@ public class ${mode}MapWriter extends AbstractFieldWriter {
     FieldWriter writer = fields.get(name.toLowerCase());
     int vectorCount = container.size();
     if(writer == null) {
-      if (!unionEnabled){
-        writer = new SingleListWriter(name,container,this);
-      } else{
-        writer = new PromotableWriter(container.addOrGet(name, Types.optional(MinorType.LIST), ListVector.class), container);
-      }
+      writer = new PromotableWriter(container.addOrGet(name, MinorType.LIST, ListVector.class), container);
       if (container.size() > vectorCount) {
         writer.allocate();
       }
@@ -206,9 +190,7 @@ public class ${mode}MapWriter extends AbstractFieldWriter {
   }
 
   public ${minor.class}Writer ${lowerName}(String name, int scale, int precision) {
-    final MajorType ${upperName}_TYPE = new MajorType(MinorType.${upperName}, DataMode.OPTIONAL, precision, scale, 0, null);
   <#else>
-  private static final MajorType ${upperName}_TYPE = Types.optional(MinorType.${upperName});
   @Override
   public ${minor.class}Writer ${lowerName}(String name) {
   </#if>
@@ -216,15 +198,9 @@ public class ${mode}MapWriter extends AbstractFieldWriter {
     if(writer == null) {
       ValueVector vector;
       ValueVector currentVector = container.getChild(name);
-      if (unionEnabled){
-        ${vectName}Vector v = container.addOrGet(name, ${upperName}_TYPE, ${vectName}Vector.class);
-        writer = new PromotableWriter(v, container);
-        vector = v;
-      } else {
-        ${vectName}Vector v = container.addOrGet(name, ${upperName}_TYPE, ${vectName}Vector.class);
-        writer = new ${vectName}WriterImpl(v, this);
-        vector = v;
-      }
+      ${vectName}Vector v = container.addOrGet(name, MinorType.${upperName}, ${vectName}Vector.class);
+      writer = new PromotableWriter(v, container);
+      vector = v;
       if (currentVector == null || currentVector != vector) {
         vector.allocateNewSafe();
       } 

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/NullReader.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/NullReader.java b/java/vector/src/main/codegen/templates/NullReader.java
index 3ef6c7d..ba0c088 100644
--- a/java/vector/src/main/codegen/templates/NullReader.java
+++ b/java/vector/src/main/codegen/templates/NullReader.java
@@ -16,6 +16,9 @@
  * limitations under the License.
  */
 
+import org.apache.arrow.vector.types.pojo.ArrowType.Null;
+import org.apache.arrow.vector.types.pojo.Field;
+
 <@pp.dropOutputFile />
 <@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/NullReader.java" />
 
@@ -31,25 +34,31 @@ package org.apache.arrow.vector.complex.impl;
 public class NullReader extends AbstractBaseReader implements FieldReader{
   
   public static final NullReader INSTANCE = new NullReader();
-  public static final NullReader EMPTY_LIST_INSTANCE = new NullReader(Types.repeated(MinorType.NULL));
-  public static final NullReader EMPTY_MAP_INSTANCE = new NullReader(Types.required(MinorType.MAP));
-  private MajorType type;
+  public static final NullReader EMPTY_LIST_INSTANCE = new NullReader(MinorType.NULL);
+  public static final NullReader EMPTY_MAP_INSTANCE = new NullReader(MinorType.MAP);
+  private MinorType type;
   
   private NullReader(){
     super();
-    type = Types.required(MinorType.NULL);
+    type = MinorType.NULL;
   }
 
-  private NullReader(MajorType type){
+  private NullReader(MinorType type){
     super();
     this.type = type;
   }
 
   @Override
-  public MajorType getType() {
+  public MinorType getMinorType() {
     return type;
   }
-  
+
+
+  @Override
+  public Field getField() {
+    return new Field("", true, new Null(), null);
+  }
+
   public void copyAsValue(MapWriter writer) {}
 
   public void copyAsValue(ListWriter writer) {}

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/NullableValueVectors.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/NullableValueVectors.java b/java/vector/src/main/codegen/templates/NullableValueVectors.java
index b0029f7..df50897 100644
--- a/java/vector/src/main/codegen/templates/NullableValueVectors.java
+++ b/java/vector/src/main/codegen/templates/NullableValueVectors.java
@@ -42,19 +42,79 @@ package org.apache.arrow.vector;
 public final class ${className} extends BaseDataValueVector implements <#if type.major == "VarLen">VariableWidth<#else>FixedWidth</#if>Vector, NullableVector{
   private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(${className}.class);
 
-  private final FieldReader reader = new Nullable${minor.class}ReaderImpl(Nullable${minor.class}Vector.this);
+  private final FieldReader reader = new ${minor.class}ReaderImpl(Nullable${minor.class}Vector.this);
 
-  private final MaterializedField bitsField = MaterializedField.create("$bits$", new MajorType(MinorType.UINT1, DataMode.REQUIRED));
-  private final MaterializedField valuesField = MaterializedField.create("$values$", new MajorType(field.getType().getMinorType(), DataMode.REQUIRED, field.getPrecision(), field.getScale()));
+  private final String bitsField = "$bits$";
+  private final String valuesField = "$values$";
+  private final Field field;
 
   final UInt1Vector bits = new UInt1Vector(bitsField, allocator);
-  final ${valuesName} values = new ${minor.class}Vector(valuesField, allocator);
+  final ${valuesName} values;
 
-  private final Mutator mutator = new Mutator();
-  private final Accessor accessor = new Accessor();
+  private final Mutator mutator;
+  private final Accessor accessor;
 
-  public ${className}(MaterializedField field, BufferAllocator allocator) {
-    super(field, allocator);
+  <#if minor.class == "Decimal">
+  private final int precision;
+  private final int scale;
+
+  public ${className}(String name, BufferAllocator allocator, int precision, int scale) {
+    super(name, allocator);
+    values = new ${minor.class}Vector(valuesField, allocator, precision, scale);
+    this.precision = precision;
+    this.scale = scale;
+    mutator = new Mutator();
+    accessor = new Accessor();
+    field = new Field(name, true, new Decimal(precision, scale), null);
+  }
+  <#else>
+  public ${className}(String name, BufferAllocator allocator) {
+    super(name, allocator);
+    values = new ${minor.class}Vector(valuesField, allocator);
+    mutator = new Mutator();
+    accessor = new Accessor();
+  <#if minor.class == "TinyInt" ||
+        minor.class == "SmallInt" ||
+        minor.class == "Int" ||
+        minor.class == "BigInt">
+    field = new Field(name, true, new Int(${type.width} * 8, true), null);
+  <#elseif minor.class == "UInt1" ||
+        minor.class == "UInt2" ||
+        minor.class == "UInt4" ||
+        minor.class == "UInt8">
+    field = new Field(name, true, new Int(${type.width} * 8, false), null);
+  <#elseif minor.class == "Date">
+    field = new Field(name, true, new org.apache.arrow.vector.types.pojo.ArrowType.Date(), null);
+  <#elseif minor.class == "Time">
+    field = new Field(name, true, new org.apache.arrow.vector.types.pojo.ArrowType.Time(), null);
+  <#elseif minor.class == "Float4">
+    field = new Field(name, true, new FloatingPoint(0), null);
+  <#elseif minor.class == "Float8">
+    field = new Field(name, true, new FloatingPoint(1), null);
+  <#elseif minor.class == "TimeStamp">
+    field = new Field(name, true, new org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(""), null);
+  <#elseif minor.class == "IntervalDay">
+    field = new Field(name, true, new IntervalDay(), null);
+  <#elseif minor.class == "IntervalYear">
+    field = new Field(name, true, new IntervalYear(), null);
+  <#elseif minor.class == "VarChar">
+    field = new Field(name, true, new Utf8(), null);
+  <#elseif minor.class == "VarBinary">
+    field = new Field(name, true, new Binary(), null);
+  <#elseif minor.class == "Bit">
+    field = new Field(name, true, new Bool(), null);
+  </#if>
+  }
+  </#if>
+
+  @Override
+  public Field getField() {
+    return field;
+  }
+
+  @Override
+  public MinorType getMinorType() {
+    return MinorType.${minor.class?upper_case};
   }
 
   @Override
@@ -240,12 +300,13 @@ public final class ${className} extends BaseDataValueVector implements <#if type
 
   @Override
   public TransferPair getTransferPair(BufferAllocator allocator){
-    return new TransferImpl(getField(), allocator);
+    return new TransferImpl(name, allocator);
+
   }
 
   @Override
   public TransferPair getTransferPair(String ref, BufferAllocator allocator){
-    return new TransferImpl(getField().withPath(ref), allocator);
+    return new TransferImpl(ref, allocator);
   }
 
   @Override
@@ -273,8 +334,12 @@ public final class ${className} extends BaseDataValueVector implements <#if type
   private class TransferImpl implements TransferPair {
     Nullable${minor.class}Vector to;
 
-    public TransferImpl(MaterializedField field, BufferAllocator allocator){
-      to = new Nullable${minor.class}Vector(field, allocator);
+    public TransferImpl(String name, BufferAllocator allocator){
+      <#if minor.class == "Decimal">
+      to = new Nullable${minor.class}Vector(name, allocator, precision, scale);
+      <#else>
+      to = new Nullable${minor.class}Vector(name, allocator);
+      </#if>
     }
 
     public TransferImpl(Nullable${minor.class}Vector to){
@@ -312,17 +377,6 @@ public final class ${className} extends BaseDataValueVector implements <#if type
     return mutator;
   }
 
-  public ${minor.class}Vector convertToRequiredVector(){
-    ${minor.class}Vector v = new ${minor.class}Vector(getField().getOtherNullableVersion(), allocator);
-    if (v.data != null) {
-      v.data.release(1);
-    }
-    v.data = values.data;
-    v.data.retain(1);
-    clear();
-    return v;
-  }
-
   public void copyFrom(int fromIndex, int thisIndex, Nullable${minor.class}Vector from){
     final Accessor fromAccessor = from.getAccessor();
     if (!fromAccessor.isNull(fromIndex)) {
@@ -389,8 +443,8 @@ public final class ${className} extends BaseDataValueVector implements <#if type
       holder.isSet = bAccessor.get(index);
 
       <#if minor.class.startsWith("Decimal")>
-      holder.scale = getField().getScale();
-      holder.precision = getField().getPrecision();
+      holder.scale = scale;
+      holder.precision = precision;
       </#if>
     }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/RepeatedValueVectors.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/RepeatedValueVectors.java b/java/vector/src/main/codegen/templates/RepeatedValueVectors.java
deleted file mode 100644
index ceae53b..0000000
--- a/java/vector/src/main/codegen/templates/RepeatedValueVectors.java
+++ /dev/null
@@ -1,421 +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.
- */
-
-<@pp.dropOutputFile />
-<#list vv.types as type>
-<#list type.minor as minor>
-<#assign friendlyType = (minor.friendlyType!minor.boxedType!type.boxedType) />
-<#assign fields = minor.fields!type.fields />
-
-<@pp.changeOutputFile name="/org/apache/arrow/vector/Repeated${minor.class}Vector.java" />
-<#include "/@includes/license.ftl" />
-
-package org.apache.arrow.vector;
-
-<#include "/@includes/vv_imports.ftl" />
-
-/**
- * Repeated${minor.class} implements a vector with multple values per row (e.g. JSON array or
- * repeated protobuf field).  The implementation uses two additional value vectors; one to convert
- * the index offset to the underlying element offset, and another to store the number of values
- * in the vector.
- *
- * NB: this class is automatically generated from ${.template_name} and ValueVectorTypes.tdd using FreeMarker.
- */
-
-public final class Repeated${minor.class}Vector extends BaseRepeatedValueVector implements Repeated<#if type.major == "VarLen">VariableWidth<#else>FixedWidth</#if>VectorLike {
-  //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Repeated${minor.class}Vector.class);
-
-  // we maintain local reference to concrete vector type for performance reasons.
-  ${minor.class}Vector values;
-  private final FieldReader reader = new Repeated${minor.class}ReaderImpl(Repeated${minor.class}Vector.this);
-  private final Mutator mutator = new Mutator();
-  private final Accessor accessor = new Accessor();
-
-  public Repeated${minor.class}Vector(MaterializedField field, BufferAllocator allocator) {
-    super(field, allocator);
-    addOrGetVector(VectorDescriptor.create(new MajorType(field.getType().getMinorType(), DataMode.REQUIRED)));
-  }
-
-  @Override
-  public Mutator getMutator() {
-    return mutator;
-  }
-
-  @Override
-  public Accessor getAccessor() {
-    return accessor;
-  }
-
-  @Override
-  public FieldReader getReader() {
-    return reader;
-  }
-
-  @Override
-  public ${minor.class}Vector getDataVector() {
-    return values;
-  }
-
-  @Override
-  public TransferPair getTransferPair(BufferAllocator allocator) {
-    return new TransferImpl(getField(), allocator);
-  }
-
-  @Override
-  public TransferPair getTransferPair(String ref, BufferAllocator allocator){
-    return new TransferImpl(getField().withPath(ref), allocator);
-  }
-
-  @Override
-  public TransferPair makeTransferPair(ValueVector to) {
-    return new TransferImpl((Repeated${minor.class}Vector) to);
-  }
-
-  @Override
-  public AddOrGetResult<${minor.class}Vector> addOrGetVector(VectorDescriptor descriptor) {
-    final AddOrGetResult<${minor.class}Vector> result = super.addOrGetVector(descriptor);
-    if (result.isCreated()) {
-      values = result.getVector();
-    }
-    return result;
-  }
-
-  public void transferTo(Repeated${minor.class}Vector target) {
-    target.clear();
-    offsets.transferTo(target.offsets);
-    values.transferTo(target.values);
-    clear();
-  }
-
-  public void splitAndTransferTo(final int startIndex, final int groups, Repeated${minor.class}Vector to) {
-    final UInt4Vector.Accessor a = offsets.getAccessor();
-    final UInt4Vector.Mutator m = to.offsets.getMutator();
-
-    final int startPos = a.get(startIndex);
-    final int endPos = a.get(startIndex + groups);
-    final int valuesToCopy = endPos - startPos;
-
-    values.splitAndTransferTo(startPos, valuesToCopy, to.values);
-    to.offsets.clear();
-    to.offsets.allocateNew(groups + 1);
-    int normalizedPos = 0;
-    for (int i=0; i < groups + 1;i++ ) {
-      normalizedPos = a.get(startIndex+i) - startPos;
-      m.set(i, normalizedPos);
-    }
-    m.setValueCount(groups == 0 ? 0 : groups + 1);
-  }
-
-  private class TransferImpl implements TransferPair {
-    final Repeated${minor.class}Vector to;
-
-    public TransferImpl(MaterializedField field, BufferAllocator allocator) {
-      this.to = new Repeated${minor.class}Vector(field, allocator);
-    }
-
-    public TransferImpl(Repeated${minor.class}Vector to) {
-      this.to = to;
-    }
-
-    @Override
-    public Repeated${minor.class}Vector getTo() {
-      return to;
-    }
-
-    @Override
-    public void transfer() {
-      transferTo(to);
-    }
-
-    @Override
-    public void splitAndTransfer(int startIndex, int length) {
-      splitAndTransferTo(startIndex, length, to);
-    }
-
-    @Override
-    public void copyValueSafe(int fromIndex, int toIndex) {
-      to.copyFromSafe(fromIndex, toIndex, Repeated${minor.class}Vector.this);
-    }
-  }
-
-    public void copyFrom(int inIndex, int outIndex, Repeated${minor.class}Vector v) {
-      final Accessor vAccessor = v.getAccessor();
-      final int count = vAccessor.getInnerValueCountAt(inIndex);
-      mutator.startNewValue(outIndex);
-      for (int i = 0; i < count; i++) {
-        mutator.add(outIndex, vAccessor.get(inIndex, i));
-      }
-    }
-
-    public void copyFromSafe(int inIndex, int outIndex, Repeated${minor.class}Vector v) {
-      final Accessor vAccessor = v.getAccessor();
-      final int count = vAccessor.getInnerValueCountAt(inIndex);
-      mutator.startNewValue(outIndex);
-      for (int i = 0; i < count; i++) {
-        mutator.addSafe(outIndex, vAccessor.get(inIndex, i));
-      }
-    }
-
-  public boolean allocateNewSafe() {
-    /* boolean to keep track if all the memory allocation were successful
-     * Used in the case of composite vectors when we need to allocate multiple
-     * buffers for multiple vectors. If one of the allocations failed we need to
-     * clear all the memory that we allocated
-     */
-    boolean success = false;
-    try {
-      if(!offsets.allocateNewSafe()) return false;
-      if(!values.allocateNewSafe()) return false;
-      success = true;
-    } finally {
-      if (!success) {
-        clear();
-      }
-    }
-    offsets.zeroVector();
-    mutator.reset();
-    return true;
-  }
-
-  @Override
-  public void allocateNew() {
-    try {
-      offsets.allocateNew();
-      values.allocateNew();
-    } catch (OutOfMemoryException e) {
-      clear();
-      throw e;
-    }
-    offsets.zeroVector();
-    mutator.reset();
-  }
-
-  <#if type.major == "VarLen">
-//  @Override
-//  protected SerializedField.Builder getMetadataBuilder() {
-//    return super.getMetadataBuilder()
-//            .setVarByteLength(values.getVarByteLength());
-//  }
-
-  public void allocateNew(int totalBytes, int valueCount, int innerValueCount) {
-    try {
-      offsets.allocateNew(valueCount + 1);
-      values.allocateNew(totalBytes, innerValueCount);
-    } catch (OutOfMemoryException e) {
-      clear();
-      throw e;
-    }
-    offsets.zeroVector();
-    mutator.reset();
-  }
-
-  public int getByteCapacity(){
-    return values.getByteCapacity();
-  }
-
-  <#else>
-
-  @Override
-  public void allocateNew(int valueCount, int innerValueCount) {
-    clear();
-    /* boolean to keep track if all the memory allocation were successful
-     * Used in the case of composite vectors when we need to allocate multiple
-     * buffers for multiple vectors. If one of the allocations failed we need to//
-     * clear all the memory that we allocated
-     */
-    boolean success = false;
-    try {
-      offsets.allocateNew(valueCount + 1);
-      values.allocateNew(innerValueCount);
-    } catch(OutOfMemoryException e){
-      clear();
-      throw e;
-    }
-    offsets.zeroVector();
-    mutator.reset();
-  }
-
-  </#if>
-
-  // This is declared a subclass of the accessor declared inside of FixedWidthVector, this is also used for
-  // variable length vectors, as they should ahve consistent interface as much as possible, if they need to diverge
-  // in the future, the interface shold be declared in the respective value vector superclasses for fixed and variable
-  // and we should refer to each in the generation template
-  public final class Accessor extends BaseRepeatedValueVector.BaseRepeatedAccessor {
-    @Override
-    public List<${friendlyType}> getObject(int index) {
-      final List<${friendlyType}> vals = new JsonStringArrayList<>();
-      final UInt4Vector.Accessor offsetsAccessor = offsets.getAccessor();
-      final int start = offsetsAccessor.get(index);
-      final int end = offsetsAccessor.get(index + 1);
-      final ${minor.class}Vector.Accessor valuesAccessor = values.getAccessor();
-      for(int i = start; i < end; i++) {
-        vals.add(valuesAccessor.getObject(i));
-      }
-      return vals;
-    }
-
-    public ${friendlyType} getSingleObject(int index, int arrayIndex) {
-      final int start = offsets.getAccessor().get(index);
-      return values.getAccessor().getObject(start + arrayIndex);
-    }
-
-    /**
-     * Get a value for the given record.  Each element in the repeated field is accessed by
-     * the positionIndex param.
-     *
-     * @param  index           record containing the repeated field
-     * @param  positionIndex   position within the repeated field
-     * @return element at the given position in the given record
-     */
-    public <#if type.major == "VarLen">byte[]
-           <#else>${minor.javaType!type.javaType}
-           </#if> get(int index, int positionIndex) {
-      return values.getAccessor().get(offsets.getAccessor().get(index) + positionIndex);
-    }
-
-    public void get(int index, Repeated${minor.class}Holder holder) {
-      holder.start = offsets.getAccessor().get(index);
-      holder.end =  offsets.getAccessor().get(index+1);
-      holder.vector = values;
-    }
-
-    public void get(int index, int positionIndex, ${minor.class}Holder holder) {
-      final int offset = offsets.getAccessor().get(index);
-      assert offset >= 0;
-      assert positionIndex < getInnerValueCountAt(index);
-      values.getAccessor().get(offset + positionIndex, holder);
-    }
-
-    public void get(int index, int positionIndex, Nullable${minor.class}Holder holder) {
-      final int offset = offsets.getAccessor().get(index);
-      assert offset >= 0;
-      if (positionIndex >= getInnerValueCountAt(index)) {
-        holder.isSet = 0;
-        return;
-      }
-      values.getAccessor().get(offset + positionIndex, holder);
-    }
-  }
-
-  public final class Mutator extends BaseRepeatedValueVector.BaseRepeatedMutator implements RepeatedMutator {
-    private Mutator() {}
-
-    /**
-     * Add an element to the given record index.  This is similar to the set() method in other
-     * value vectors, except that it permits setting multiple values for a single record.
-     *
-     * @param index   record of the element to add
-     * @param value   value to add to the given row
-     */
-    public void add(int index, <#if type.major == "VarLen">byte[]<#elseif (type.width < 4)>int<#else>${minor.javaType!type.javaType}</#if> value) {
-      int nextOffset = offsets.getAccessor().get(index+1);
-      values.getMutator().set(nextOffset, value);
-      offsets.getMutator().set(index+1, nextOffset+1);
-    }
-
-    <#if type.major == "VarLen">
-    public void addSafe(int index, byte[] bytes) {
-      addSafe(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);
-    }
-
-    <#else>
-
-    public void addSafe(int index, ${minor.javaType!type.javaType} srcValue) {
-      final int nextOffset = offsets.getAccessor().get(index+1);
-      values.getMutator().setSafe(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();
-      final ${minor.class}Vector.Accessor hVectorAccessor = h.vector.getAccessor();
-      mutator.startNewValue(index);
-      for(int i = h.start; i < h.end; i++){
-        hVectorAccessor.get(i, ih);
-        mutator.addSafe(index, ih);
-      }
-    }
-
-    public void addSafe(int index, ${minor.class}Holder holder) {
-      int nextOffset = offsets.getAccessor().get(index+1);
-      values.getMutator().setSafe(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);
-      values.getMutator().setSafe(nextOffset, holder);
-      offsets.getMutator().setSafe(index+1, nextOffset+1);
-    }
-
-    <#if (fields?size > 1) && !(minor.class == "Decimal9" || minor.class == "Decimal18" || minor.class == "Decimal28Sparse" || minor.class == "Decimal38Sparse" || minor.class == "Decimal28Dense" || minor.class == "Decimal38Dense")>
-    public void addSafe(int arrayIndex, <#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
-      int nextOffset = offsets.getAccessor().get(arrayIndex+1);
-      values.getMutator().setSafe(nextOffset, <#list fields as field>${field.name}<#if field_has_next>, </#if></#list>);
-      offsets.getMutator().setSafe(arrayIndex+1, nextOffset+1);
-    }
-    </#if>
-
-    protected void add(int index, ${minor.class}Holder holder) {
-      int nextOffset = offsets.getAccessor().get(index+1);
-      values.getMutator().set(nextOffset, holder);
-      offsets.getMutator().set(index+1, nextOffset+1);
-    }
-
-    public void add(int index, Repeated${minor.class}Holder holder) {
-
-      ${minor.class}Vector.Accessor accessor = holder.vector.getAccessor();
-      ${minor.class}Holder innerHolder = new ${minor.class}Holder();
-
-      for(int i = holder.start; i < holder.end; i++) {
-        accessor.get(i, innerHolder);
-        add(index, innerHolder);
-      }
-    }
-
-    @Override
-    public void generateTestData(final int valCount) {
-      final int[] sizes = {1, 2, 0, 6};
-      int size = 0;
-      int runningOffset = 0;
-      final UInt4Vector.Mutator offsetsMutator = offsets.getMutator();
-      for(int i = 1; i < valCount + 1; i++, size++) {
-        runningOffset += sizes[size % sizes.length];
-        offsetsMutator.set(i, runningOffset);
-      }
-      values.getMutator().generateTestData(valCount * 9);
-      setValueCount(size);
-    }
-
-    @Override
-    public void reset() {
-    }
-  }
-}
-</#list>
-</#list>

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/UnionListWriter.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/UnionListWriter.java b/java/vector/src/main/codegen/templates/UnionListWriter.java
index 9a6b08f..49d57e7 100644
--- a/java/vector/src/main/codegen/templates/UnionListWriter.java
+++ b/java/vector/src/main/codegen/templates/UnionListWriter.java
@@ -43,7 +43,6 @@ public class UnionListWriter extends AbstractFieldWriter {
   private int lastIndex = 0;
 
   public UnionListWriter(ListVector vector) {
-    super(null);
     this.vector = vector;
     this.writer = new PromotableWriter(vector.getDataVector(), vector);
     this.offsets = vector.getOffsetVector();
@@ -64,10 +63,14 @@ public class UnionListWriter extends AbstractFieldWriter {
   }
 
   @Override
-  public MaterializedField getField() {
+  public Field getField() {
     return null;
   }
 
+  public void setValueCount(int count) {
+    vector.getMutator().setValueCount(count);
+  }
+
   @Override
   public int getValueCapacity() {
     return vector.getValueCapacity();
@@ -78,6 +81,12 @@ public class UnionListWriter extends AbstractFieldWriter {
 
   }
 
+  @Override
+  public void setPosition(int index) {
+    super.setPosition(index);
+    startList();
+  }
+
   <#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/>
@@ -91,7 +100,7 @@ public class UnionListWriter extends AbstractFieldWriter {
 
   @Override
   public ${name}Writer <#if uncappedName == "int">integer<#else>${uncappedName}</#if>(String name) {
-    assert inMap;
+//    assert inMap;
     mapName = name;
     final int nextOffset = offsets.getAccessor().get(idx() + 1);
     vector.getMutator().setNotNull(idx());
@@ -146,7 +155,7 @@ public class UnionListWriter extends AbstractFieldWriter {
 
   @Override
   public void start() {
-    assert inMap;
+//    assert inMap;
     final int nextOffset = offsets.getAccessor().get(idx() + 1);
     vector.getMutator().setNotNull(idx());
     offsets.getMutator().setSafe(idx() + 1, nextOffset);
@@ -155,11 +164,11 @@ public class UnionListWriter extends AbstractFieldWriter {
 
   @Override
   public void end() {
-    if (inMap) {
+//    if (inMap) {
       inMap = false;
       final int nextOffset = offsets.getAccessor().get(idx() + 1);
       offsets.getMutator().setSafe(idx() + 1, nextOffset + 1);
-    }
+//    }
   }
 
   <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
@@ -170,7 +179,7 @@ public class UnionListWriter extends AbstractFieldWriter {
 
   @Override
   public void write${name}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
-    assert !inMap;
+//    assert !inMap;
     final int nextOffset = offsets.getAccessor().get(idx() + 1);
     vector.getMutator().setNotNull(idx());
     writer.setPosition(nextOffset);

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/UnionReader.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/UnionReader.java b/java/vector/src/main/codegen/templates/UnionReader.java
index 44c3e55..7351ae3 100644
--- a/java/vector/src/main/codegen/templates/UnionReader.java
+++ b/java/vector/src/main/codegen/templates/UnionReader.java
@@ -17,6 +17,8 @@
  */
 
 
+import org.apache.arrow.vector.types.Types.MinorType;
+
 <@pp.dropOutputFile />
 <@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/UnionReader.java" />
 
@@ -37,18 +39,18 @@ public class UnionReader extends AbstractFieldReader {
     this.data = data;
   }
 
-  private static MajorType[] TYPES = new MajorType[43];
+  public MinorType getMinorType() {
+    return TYPES[data.getTypeValue(idx())];
+  }
+
+  private static MinorType[] TYPES = new MinorType[43];
 
   static {
     for (MinorType minorType : MinorType.values()) {
-      TYPES[minorType.ordinal()] = new MajorType(minorType, DataMode.OPTIONAL);
+      TYPES[minorType.ordinal()] = minorType;
     }
   }
 
-  public MajorType getType() {
-    return TYPES[data.getTypeValue(idx())];
-  }
-
   public boolean isSet(){
     return !data.getAccessor().isNull(idx());
   }
@@ -69,7 +71,7 @@ public class UnionReader extends AbstractFieldReader {
       return reader;
     }
     switch (MinorType.values()[typeValue]) {
-    case LATE:
+    case NULL:
       return NullReader.INSTANCE;
     case MAP:
       return (FieldReader) getMap();
@@ -119,9 +121,9 @@ public class UnionReader extends AbstractFieldReader {
     writer.data.copyFrom(idx(), writer.idx(), data);
   }
 
-  <#list ["Object", "BigDecimal", "Integer", "Long", "Boolean",
-          "Character", "DateTime", "Period", "Double", "Float",
-          "Text", "String", "Byte", "Short", "byte[]"] as friendlyType>
+  <#list ["Object", "Integer", "Long", "Boolean",
+          "Character", "DateTime", "Double", "Float",
+          "Text", "Byte", "Short", "byte[]"] as friendlyType>
   <#assign safeType=friendlyType />
   <#if safeType=="byte[]"><#assign safeType="ByteArray" /></#if>
 
@@ -141,11 +143,11 @@ public class UnionReader extends AbstractFieldReader {
   <#if safeType=="byte[]"><#assign safeType="ByteArray" /></#if>
   <#if !minor.class?starts_with("Decimal")>
 
-  private Nullable${name}ReaderImpl ${uncappedName}Reader;
+  private ${name}ReaderImpl ${uncappedName}Reader;
 
-  private Nullable${name}ReaderImpl get${name}() {
+  private ${name}ReaderImpl get${name}() {
     if (${uncappedName}Reader == null) {
-      ${uncappedName}Reader = new Nullable${name}ReaderImpl(data.get${name}Vector());
+      ${uncappedName}Reader = new ${name}ReaderImpl(data.get${name}Vector());
       ${uncappedName}Reader.setPosition(idx());
       readers[MinorType.${name?upper_case}.ordinal()] = ${uncappedName}Reader;
     }

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/UnionVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/UnionVector.java b/java/vector/src/main/codegen/templates/UnionVector.java
index 0f089b7..e2f19f4 100644
--- a/java/vector/src/main/codegen/templates/UnionVector.java
+++ b/java/vector/src/main/codegen/templates/UnionVector.java
@@ -16,6 +16,16 @@
  * limitations under the License.
  */
 
+import com.google.flatbuffers.FlatBufferBuilder;
+import org.apache.arrow.flatbuf.Field;
+import org.apache.arrow.flatbuf.Type;
+import org.apache.arrow.flatbuf.Union;
+import org.apache.arrow.vector.ValueVector;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+
+import java.util.ArrayList;
+import java.util.List;
+
 <@pp.dropOutputFile />
 <@pp.changeOutputFile name="/org/apache/arrow/vector/complex/UnionVector.java" />
 
@@ -29,7 +39,6 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import org.apache.arrow.vector.complex.impl.ComplexCopier;
 import org.apache.arrow.vector.util.CallBack;
-import org.apache.arrow.vector.util.BasicTypeHelper;
 
 /*
  * This class is generated using freemarker and the ${.template_name} template.
@@ -47,34 +56,30 @@ import org.apache.arrow.vector.util.BasicTypeHelper;
  */
 public class UnionVector implements ValueVector {
 
-  private MaterializedField field;
+  private String name;
   private BufferAllocator allocator;
   private Accessor accessor = new Accessor();
   private Mutator mutator = new Mutator();
   int valueCount;
 
   MapVector internalMap;
-  private UInt1Vector typeVector;
+  UInt1Vector typeVector;
 
   private MapVector mapVector;
   private ListVector listVector;
 
   private FieldReader reader;
-  private NullableBitVector bit;
 
   private int singleType = 0;
   private ValueVector singleVector;
-  private MajorType majorType;
 
   private final CallBack callBack;
 
-  public UnionVector(MaterializedField field, BufferAllocator allocator, CallBack callBack) {
-    this.field = field.clone();
+  public UnionVector(String name, BufferAllocator allocator, CallBack callBack) {
+    this.name = name;
     this.allocator = allocator;
     this.internalMap = new MapVector("internal", allocator, callBack);
-    this.typeVector = internalMap.addOrGet("types", new MajorType(MinorType.UINT1, DataMode.REQUIRED), UInt1Vector.class);
-    this.field.addChild(internalMap.getField().clone());
-    this.majorType = field.getType();
+    this.typeVector = new UInt1Vector("types", allocator);
     this.callBack = callBack;
   }
 
@@ -82,34 +87,20 @@ public class UnionVector implements ValueVector {
     return allocator;
   }
 
-  public List<MinorType> getSubTypes() {
-    return majorType.getSubTypes();
-  }
-
-  public void addSubType(MinorType type) {
-    if (majorType.getSubTypes().contains(type)) {
-      return;
-    }
-    List<MinorType> subTypes = this.majorType.getSubTypes();
-    List<MinorType> newSubTypes = new ArrayList<>(subTypes);
-    newSubTypes.add(type);
-    majorType =  new MajorType(this.majorType.getMinorType(), this.majorType.getMode(), this.majorType.getPrecision(),
-            this.majorType.getScale(), this.majorType.getTimezone(), newSubTypes);
-    field = MaterializedField.create(field.getName(), majorType);
-    if (callBack != null) {
-      callBack.doWork();
-    }
+  @Override
+  public MinorType getMinorType() {
+    return MinorType.UNION;
   }
 
-  private static final MajorType MAP_TYPE = new MajorType(MinorType.MAP, DataMode.OPTIONAL);
-
   public MapVector getMap() {
     if (mapVector == null) {
       int vectorCount = internalMap.size();
-      mapVector = internalMap.addOrGet("map", MAP_TYPE, MapVector.class);
-      addSubType(MinorType.MAP);
+      mapVector = internalMap.addOrGet("map", MinorType.MAP, MapVector.class);
       if (internalMap.size() > vectorCount) {
         mapVector.allocateNew();
+        if (callBack != null) {
+          callBack.doWork();
+        }
       }
     }
     return mapVector;
@@ -121,15 +112,16 @@ public class UnionVector implements ValueVector {
   <#if !minor.class?starts_with("Decimal")>
 
   private Nullable${name}Vector ${uncappedName}Vector;
-  private static final MajorType ${name?upper_case}_TYPE = new MajorType(MinorType.${name?upper_case}, DataMode.OPTIONAL);
 
   public Nullable${name}Vector get${name}Vector() {
     if (${uncappedName}Vector == null) {
       int vectorCount = internalMap.size();
-      ${uncappedName}Vector = internalMap.addOrGet("${uncappedName}", ${name?upper_case}_TYPE, Nullable${name}Vector.class);
-      addSubType(MinorType.${name?upper_case});
+      ${uncappedName}Vector = internalMap.addOrGet("${uncappedName}", MinorType.${name?upper_case}, Nullable${name}Vector.class);
       if (internalMap.size() > vectorCount) {
         ${uncappedName}Vector.allocateNew();
+        if (callBack != null) {
+          callBack.doWork();
+        }
       }
     }
     return ${uncappedName}Vector;
@@ -139,15 +131,15 @@ public class UnionVector implements ValueVector {
 
   </#list></#list>
 
-  private static final MajorType LIST_TYPE = new MajorType(MinorType.LIST, DataMode.OPTIONAL);
-
   public ListVector getList() {
     if (listVector == null) {
       int vectorCount = internalMap.size();
-      listVector = internalMap.addOrGet("list", LIST_TYPE, ListVector.class);
-      addSubType(MinorType.LIST);
+      listVector = internalMap.addOrGet("list", MinorType.LIST, ListVector.class);
       if (internalMap.size() > vectorCount) {
         listVector.allocateNew();
+        if (callBack != null) {
+          callBack.doWork();
+        }
       }
     }
     return listVector;
@@ -164,6 +156,7 @@ public class UnionVector implements ValueVector {
   @Override
   public void allocateNew() throws OutOfMemoryException {
     internalMap.allocateNew();
+    typeVector.allocateNew();
     if (typeVector != null) {
       typeVector.zeroVector();
     }
@@ -172,6 +165,7 @@ public class UnionVector implements ValueVector {
   @Override
   public boolean allocateNewSafe() {
     boolean safe = internalMap.allocateNewSafe();
+    safe = safe && typeVector.allocateNewSafe();
     if (safe) {
       if (typeVector != null) {
         typeVector.zeroVector();
@@ -196,22 +190,27 @@ public class UnionVector implements ValueVector {
 
   @Override
   public void clear() {
+    typeVector.clear();
     internalMap.clear();
   }
 
   @Override
-  public MaterializedField getField() {
-    return field;
+  public Field getField() {
+    List<org.apache.arrow.vector.types.pojo.Field> childFields = new ArrayList<>();
+    for (ValueVector v : internalMap.getChildren()) {
+      childFields.add(v.getField());
+    }
+    return new Field(name, true, new ArrowType.Union(), childFields);
   }
 
   @Override
   public TransferPair getTransferPair(BufferAllocator allocator) {
-    return new TransferImpl(field, allocator);
+    return new TransferImpl(name, allocator);
   }
 
   @Override
   public TransferPair getTransferPair(String ref, BufferAllocator allocator) {
-    return new TransferImpl(field.withPath(ref), allocator);
+    return new TransferImpl(ref, allocator);
   }
 
   @Override
@@ -219,10 +218,9 @@ public class UnionVector implements ValueVector {
     return new TransferImpl((UnionVector) target);
   }
 
-  public void transferTo(UnionVector target) {
+  public void transferTo(org.apache.arrow.vector.complex.UnionVector target) {
     internalMap.makeTransferPair(target.internalMap).transfer();
     target.valueCount = valueCount;
-    target.majorType = majorType;
   }
 
   public void copyFrom(int inIndex, int outIndex, UnionVector from) {
@@ -236,13 +234,14 @@ public class UnionVector implements ValueVector {
   }
 
   public ValueVector addVector(ValueVector v) {
-    String name = v.getField().getType().getMinorType().name().toLowerCase();
-    MajorType type = v.getField().getType();
+    String name = v.getMinorType().name().toLowerCase();
     Preconditions.checkState(internalMap.getChild(name) == null, String.format("%s vector already exists", name));
-    final ValueVector newVector = internalMap.addOrGet(name, type, (Class<ValueVector>) BasicTypeHelper.getValueVectorClass(type.getMinorType(), type.getMode()));
+    final ValueVector newVector = internalMap.addOrGet(name, v.getMinorType(), v.getClass());
     v.makeTransferPair(newVector).transfer();
     internalMap.putChild(name, newVector);
-    addSubType(v.getField().getType().getMinorType());
+    if (callBack != null) {
+      callBack.doWork();
+    }
     return newVector;
   }
 
@@ -250,8 +249,8 @@ public class UnionVector implements ValueVector {
 
     UnionVector to;
 
-    public TransferImpl(MaterializedField field, BufferAllocator allocator) {
-      to = new UnionVector(field, allocator, null);
+    public TransferImpl(String name, BufferAllocator allocator) {
+      to = new UnionVector(name, allocator, null);
     }
 
     public TransferImpl(UnionVector to) {
@@ -357,7 +356,7 @@ public class UnionVector implements ValueVector {
     public Object getObject(int index) {
       int type = typeVector.getAccessor().get(index);
       switch (MinorType.values()[type]) {
-      case LATE:
+      case NULL:
         return null;
       <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
       <#assign fields = minor.fields!type.fields />
@@ -421,7 +420,7 @@ public class UnionVector implements ValueVector {
         writer = new UnionWriter(UnionVector.this);
       }
       writer.setPosition(index);
-      MinorType type = reader.getType().getMinorType();
+      MinorType type = reader.getMinorType();
       switch (type) {
       <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
       <#assign fields = minor.fields!type.fields />
@@ -460,7 +459,7 @@ public class UnionVector implements ValueVector {
     </#list></#list>
 
     public void setType(int index, MinorType type) {
-      typeVector.getMutator().setSafe(index, type.ordinal());
+      typeVector.getMutator().setSafe(index, (byte) type.ordinal());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/UnionWriter.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/UnionWriter.java b/java/vector/src/main/codegen/templates/UnionWriter.java
index c9c29e0..1137e2c 100644
--- a/java/vector/src/main/codegen/templates/UnionWriter.java
+++ b/java/vector/src/main/codegen/templates/UnionWriter.java
@@ -37,17 +37,7 @@ public class UnionWriter extends AbstractFieldWriter implements FieldWriter {
   private UnionListWriter listWriter;
   private List<BaseWriter> writers = Lists.newArrayList();
 
-  public UnionWriter(BufferAllocator allocator) {
-    super(null);
-  }
-
   public UnionWriter(UnionVector vector) {
-    super(null);
-    data = vector;
-  }
-
-  public UnionWriter(UnionVector vector, FieldWriter parent) {
-    super(null);
     data = vector;
   }
 
@@ -84,7 +74,7 @@ public class UnionWriter extends AbstractFieldWriter implements FieldWriter {
 
   private MapWriter getMapWriter() {
     if (mapWriter == null) {
-      mapWriter = new SingleMapWriter(data.getMap(), null, true);
+      mapWriter = new SingleMapWriter(data.getMap());
       mapWriter.setPosition(idx());
       writers.add(mapWriter);
     }
@@ -120,7 +110,7 @@ public class UnionWriter extends AbstractFieldWriter implements FieldWriter {
 
   private ${name}Writer get${name}Writer() {
     if (${uncappedName}Writer == null) {
-      ${uncappedName}Writer = new Nullable${name}WriterImpl(data.get${name}Vector(), null);
+      ${uncappedName}Writer = new ${name}WriterImpl(data.get${name}Vector());
       ${uncappedName}Writer.setPosition(idx());
       writers.add(${uncappedName}Writer);
     }
@@ -217,7 +207,7 @@ public class UnionWriter extends AbstractFieldWriter implements FieldWriter {
   }
 
   @Override
-  public MaterializedField getField() {
+  public Field getField() {
     return data.getField();
   }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/ValueHolders.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/ValueHolders.java b/java/vector/src/main/codegen/templates/ValueHolders.java
index 2b14194..d744c52 100644
--- a/java/vector/src/main/codegen/templates/ValueHolders.java
+++ b/java/vector/src/main/codegen/templates/ValueHolders.java
@@ -31,10 +31,6 @@ package org.apache.arrow.vector.holders;
 
 public final class ${className} implements ValueHolder{
   
-  public static final MajorType TYPE = new MajorType(MinorType.${minor.class?upper_case}, DataMode.${mode.name?upper_case});
-
-  public MajorType getType() {return TYPE;}
-  
     <#if mode.name == "Repeated">
     
     /** The first index (inclusive) into the Vector. **/
@@ -49,48 +45,13 @@ public final class ${className} implements ValueHolder{
     <#else>
     public static final int WIDTH = ${type.width};
     
-    <#if mode.name == "Optional">public int isSet;</#if>
+    <#if mode.name == "Optional">public int isSet;
+    <#else>public final int isSet = 1;</#if>
     <#assign fields = minor.fields!type.fields />
     <#list fields as field>
     public ${field.type} ${field.name};
     </#list>
     
-    <#if minor.class.startsWith("Decimal")>
-    public static final int maxPrecision = ${minor.maxPrecisionDigits};
-    <#if minor.class.startsWith("Decimal28") || minor.class.startsWith("Decimal38")>
-    public static final int nDecimalDigits = ${minor.nDecimalDigits};
-    
-    public static int getInteger(int index, int start, ArrowBuf buffer) {
-      int value = buffer.getInt(start + (index * 4));
-
-      if (index == 0) {
-          /* the first byte contains sign bit, return value without it */
-          <#if minor.class.endsWith("Sparse")>
-          value = (value & 0x7FFFFFFF);
-          <#elseif minor.class.endsWith("Dense")>
-          value = (value & 0x0000007F);
-          </#if>
-      }
-      return value;
-    }
-
-    public static void setInteger(int index, int value, int start, ArrowBuf buffer) {
-        buffer.setInt(start + (index * 4), value);
-    }
-  
-    public static void setSign(boolean sign, int start, ArrowBuf buffer) {
-      // Set MSB to 1 if sign is negative
-      if (sign == true) {
-        int value = getInteger(0, start, buffer);
-        setInteger(0, (value | 0x80000000), start, buffer);
-      }
-    }
-  
-    public static boolean getSign(int start, ArrowBuf buffer) {
-      return ((buffer.getInt(start) & 0x80000000) != 0);
-    }
-    </#if></#if>
-    
     @Deprecated
     public int hashCode(){
       throw new UnsupportedOperationException();

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/codegen/templates/VariableLengthVectors.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/VariableLengthVectors.java b/java/vector/src/main/codegen/templates/VariableLengthVectors.java
index 84fb3eb..bcd639a 100644
--- a/java/vector/src/main/codegen/templates/VariableLengthVectors.java
+++ b/java/vector/src/main/codegen/templates/VariableLengthVectors.java
@@ -56,9 +56,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
   private static final int MIN_BYTE_COUNT = 4096;
 
   public final static String OFFSETS_VECTOR_NAME = "$offsets$";
-  private final MaterializedField offsetsField = MaterializedField.create(OFFSETS_VECTOR_NAME, new MajorType(MinorType.UINT4, DataMode.REQUIRED));
-  final UInt${type.width}Vector offsetVector = new UInt${type.width}Vector(offsetsField, allocator);
-  private final FieldReader reader = new ${minor.class}ReaderImpl(${minor.class}Vector.this);
+  final UInt${type.width}Vector offsetVector = new UInt${type.width}Vector(OFFSETS_VECTOR_NAME, allocator);
 
   private final Accessor accessor;
   private final Mutator mutator;
@@ -68,16 +66,42 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
   private int allocationSizeInBytes = INITIAL_BYTE_COUNT;
   private int allocationMonitor = 0;
 
-  public ${minor.class}Vector(MaterializedField field, BufferAllocator allocator) {
-    super(field, allocator);
+  <#if minor.class == "Decimal">
+
+  private final int precision;
+  private final int scale;
+
+  public ${minor.class}Vector(String name, BufferAllocator allocator, int precision, int scale) {
+    super(name, allocator);
+    this.oAccessor = offsetVector.getAccessor();
+    this.accessor = new Accessor();
+    this.mutator = new Mutator();
+    this.precision = precision;
+    this.scale = scale;
+  }
+  <#else>
+
+  public ${minor.class}Vector(String name, BufferAllocator allocator) {
+    super(name, allocator);
     this.oAccessor = offsetVector.getAccessor();
     this.accessor = new Accessor();
     this.mutator = new Mutator();
   }
+  </#if>
+
+  @Override
+  public Field getField() {
+    throw new UnsupportedOperationException("internal vector");
+  }
+
+  @Override
+  public MinorType getMinorType() {
+    return MinorType.${minor.class?upper_case};
+  }
 
   @Override
   public FieldReader getReader(){
-    return reader;
+    throw new UnsupportedOperationException("internal vector");
   }
 
   @Override
@@ -125,27 +149,6 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
     return offsetVector.getAccessor().get(valueCount);
   }
 
-//  @Override
-//  public SerializedField getMetadata() {
-//    return getMetadataBuilder() //
-//             .addChild(offsetVector.getMetadata())
-//             .setValueCount(getAccessor().getValueCount()) //
-//             .setBufferLength(getBufferSize()) //
-//             .build();
-//  }
-//
-//  @Override
-//  public void load(SerializedField metadata, ArrowBuf buffer) {
-//     the bits vector is the first child (the order in which the children are added in getMetadataBuilder is significant)
-//    final SerializedField offsetField = metadata.getChild(0);
-//    offsetVector.load(offsetField, buffer);
-//
-//    final int capacity = buffer.capacity();
-//    final int offsetsLength = offsetField.getBufferLength();
-//    data = buffer.slice(offsetsLength, capacity - offsetsLength);
-//    data.retain();
-//  }
-
   @Override
   public void clear() {
     super.clear();
@@ -175,12 +178,12 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
 
   @Override
   public TransferPair getTransferPair(BufferAllocator allocator){
-    return new TransferImpl(getField(), allocator);
+        return new TransferImpl(name, allocator);
   }
 
   @Override
   public TransferPair getTransferPair(String ref, BufferAllocator allocator){
-    return new TransferImpl(getField().withPath(ref), allocator);
+    return new TransferImpl(ref, allocator);
   }
 
   @Override
@@ -241,8 +244,12 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
   private class TransferImpl implements TransferPair{
     ${minor.class}Vector to;
 
-    public TransferImpl(MaterializedField field, BufferAllocator allocator){
-      to = new ${minor.class}Vector(field, allocator);
+    public TransferImpl(String name, BufferAllocator allocator){
+      <#if minor.class == "Decimal">
+      to = new ${minor.class}Vector(name, allocator, precision, scale);
+      <#else>
+      to = new ${minor.class}Vector(name, allocator);
+      </#if>
     }
 
     public TransferImpl(${minor.class}Vector to){
@@ -426,10 +433,10 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
       return text;
     }
     <#break>
-    <#case "Var16Char">
+    <#case "Decimal">
     @Override
     public ${friendlyType} getObject(int index) {
-      return new String(get(index), Charsets.UTF_16);
+      return new BigDecimal(new BigInteger(get(index)), scale);
     }
     <#break>
     <#default>

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/java/org/apache/arrow/vector/BaseDataValueVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseDataValueVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseDataValueVector.java
index b129ea9..05b7cf1 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/BaseDataValueVector.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseDataValueVector.java
@@ -20,7 +20,6 @@ package org.apache.arrow.vector;
 import io.netty.buffer.ArrowBuf;
 
 import org.apache.arrow.memory.BufferAllocator;
-import org.apache.arrow.vector.types.MaterializedField;
 
 
 public abstract class BaseDataValueVector extends BaseValueVector {
@@ -29,8 +28,8 @@ public abstract class BaseDataValueVector extends BaseValueVector {
 
   protected ArrowBuf data;
 
-  public BaseDataValueVector(MaterializedField field, BufferAllocator allocator) {
-    super(field, allocator);
+  public BaseDataValueVector(String name, BufferAllocator allocator) {
+    super(name, allocator);
     data = allocator.getEmpty();
   }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java
index 932e6f1..884cdf0 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java
@@ -19,8 +19,8 @@ package org.apache.arrow.vector;
 
 import java.util.Iterator;
 
+import com.google.flatbuffers.FlatBufferBuilder;
 import org.apache.arrow.memory.BufferAllocator;
-import org.apache.arrow.vector.types.MaterializedField;
 import org.apache.arrow.vector.util.TransferPair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,16 +38,16 @@ public abstract class BaseValueVector implements ValueVector {
   public static final int INITIAL_VALUE_ALLOCATION = 4096;
 
   protected final BufferAllocator allocator;
-  protected final MaterializedField field;
+  protected final String name;
 
-  protected BaseValueVector(MaterializedField field, BufferAllocator allocator) {
-    this.field = Preconditions.checkNotNull(field, "field cannot be null");
+  protected BaseValueVector(String name, BufferAllocator allocator) {
     this.allocator = Preconditions.checkNotNull(allocator, "allocator cannot be null");
+    this.name = name;
   }
 
   @Override
   public String toString() {
-    return super.toString() + "[field = " + field + ", ...]";
+    return super.toString() + "[name = " + name + ", ...]";
   }
 
   @Override
@@ -61,29 +61,10 @@ public abstract class BaseValueVector implements ValueVector {
   }
 
   @Override
-  public MaterializedField getField() {
-    return field;
-  }
-
-  public MaterializedField getField(String ref){
-    return getField().withPath(ref);
-  }
-
-  @Override
   public TransferPair getTransferPair(BufferAllocator allocator) {
-    return getTransferPair(getField().getPath(), allocator);
+    return getTransferPair(name, allocator);
   }
 
-//  public static SerializedField getMetadata(BaseValueVector vector) {
-//    return getMetadataBuilder(vector).build();
-//  }
-//
-//  protected static SerializedField.Builder getMetadataBuilder(BaseValueVector vector) {
-//    return SerializedFieldHelper.getAsBuilder(vector.getField())
-//        .setValueCount(vector.getAccessor().getValueCount())
-//        .setBufferLength(vector.getBufferSize());
-//  }
-
   public abstract static class BaseAccessor implements ValueVector.Accessor {
     protected BaseAccessor() { }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
index c5bcb2d..fee6e9c 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
@@ -21,11 +21,11 @@ import io.netty.buffer.ArrowBuf;
 
 import org.apache.arrow.memory.BufferAllocator;
 import org.apache.arrow.memory.OutOfMemoryException;
-import org.apache.arrow.vector.complex.impl.BitReaderImpl;
 import org.apache.arrow.vector.complex.reader.FieldReader;
 import org.apache.arrow.vector.holders.BitHolder;
 import org.apache.arrow.vector.holders.NullableBitHolder;
-import org.apache.arrow.vector.types.MaterializedField;
+import org.apache.arrow.vector.types.Types.MinorType;
+import org.apache.arrow.vector.types.pojo.Field;
 import org.apache.arrow.vector.util.OversizedAllocationException;
 import org.apache.arrow.vector.util.TransferPair;
 
@@ -37,7 +37,6 @@ import org.apache.arrow.vector.util.TransferPair;
 public final class BitVector extends BaseDataValueVector implements FixedWidthVector {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BitVector.class);
 
-  private final FieldReader reader = new BitReaderImpl(BitVector.this);
   private final Accessor accessor = new Accessor();
   private final Mutator mutator = new Mutator();
 
@@ -45,13 +44,23 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe
   private int allocationSizeInBytes = INITIAL_VALUE_ALLOCATION;
   private int allocationMonitor = 0;
 
-  public BitVector(MaterializedField field, BufferAllocator allocator) {
-    super(field, allocator);
+  public BitVector(String name, BufferAllocator allocator) {
+    super(name, allocator);
+  }
+
+  @Override
+  public Field getField() {
+    throw new UnsupportedOperationException("internal vector");
+  }
+
+  @Override
+  public MinorType getMinorType() {
+    return MinorType.BIT;
   }
 
   @Override
   public FieldReader getReader() {
-    return reader;
+    throw new UnsupportedOperationException("internal vector");
   }
 
   @Override
@@ -180,20 +189,6 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe
     return true;
   }
 
-//  @Override
-//  public void load(SerializedField metadata, DrillBuf buffer) {
-//    Preconditions.checkArgument(this.field.getPath().equals(metadata.getNamePart().getName()), "The field %s doesn't match the provided metadata %s.", this.field, metadata);
-//    final int valueCount = metadata.getValueCount();
-//    final int expectedLength = getSizeFromCount(valueCount);
-//    final int actualLength = metadata.getBufferLength();
-//    assert expectedLength == actualLength: "expected and actual buffer sizes do not match";
-//
-//    clear();
-//    data = buffer.slice(0, actualLength);
-//    data.retain();
-//    this.valueCount = valueCount;
-//  }
-
   @Override
   public Mutator getMutator() {
     return new Mutator();
@@ -206,12 +201,12 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe
 
   @Override
   public TransferPair getTransferPair(BufferAllocator allocator) {
-    return new TransferImpl(getField(), allocator);
+    return new TransferImpl(name, allocator);
   }
 
   @Override
   public TransferPair getTransferPair(String ref, BufferAllocator allocator) {
-    return new TransferImpl(getField().withPath(ref), allocator);
+    return new TransferImpl(ref, allocator);
   }
 
   @Override
@@ -270,8 +265,8 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe
   private class TransferImpl implements TransferPair {
     BitVector to;
 
-    public TransferImpl(MaterializedField field, BufferAllocator allocator) {
-      this.to = new BitVector(field, allocator);
+    public TransferImpl(String name, BufferAllocator allocator) {
+      this.to = new BitVector(name, allocator);
     }
 
     public TransferImpl(BitVector to) {

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/java/org/apache/arrow/vector/ObjectVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/ObjectVector.java b/java/vector/src/main/java/org/apache/arrow/vector/ObjectVector.java
deleted file mode 100644
index b806b18..0000000
--- a/java/vector/src/main/java/org/apache/arrow/vector/ObjectVector.java
+++ /dev/null
@@ -1,220 +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.arrow.vector;
-
-import io.netty.buffer.ArrowBuf;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.arrow.memory.BufferAllocator;
-import org.apache.arrow.memory.OutOfMemoryException;
-import org.apache.arrow.vector.complex.reader.FieldReader;
-import org.apache.arrow.vector.holders.ObjectHolder;
-import org.apache.arrow.vector.types.MaterializedField;
-import org.apache.arrow.vector.util.TransferPair;
-
-public class ObjectVector extends BaseValueVector {
-  private final Accessor accessor = new Accessor();
-  private final Mutator mutator = new Mutator();
-  private int maxCount = 0;
-  private int count = 0;
-  private int allocationSize = 4096;
-
-  private List<Object[]> objectArrayList = new ArrayList<>();
-
-  public ObjectVector(MaterializedField field, BufferAllocator allocator) {
-    super(field, allocator);
-  }
-
-  public void addNewArray() {
-    objectArrayList.add(new Object[allocationSize]);
-    maxCount += allocationSize;
-  }
-
-  @Override
-  public FieldReader getReader() {
-    throw new UnsupportedOperationException("ObjectVector does not support this");
-  }
-
-  public final class Mutator implements ValueVector.Mutator {
-
-    public void set(int index, Object obj) {
-      int listOffset = index / allocationSize;
-      if (listOffset >= objectArrayList.size()) {
-        addNewArray();
-      }
-      objectArrayList.get(listOffset)[index % allocationSize] = obj;
-    }
-
-    public boolean setSafe(int index, long value) {
-      set(index, value);
-      return true;
-    }
-
-    protected void set(int index, ObjectHolder holder) {
-      set(index, holder.obj);
-    }
-
-    public boolean setSafe(int index, ObjectHolder holder){
-      set(index, holder);
-      return true;
-    }
-
-    @Override
-    public void setValueCount(int valueCount) {
-      count = valueCount;
-    }
-
-    @Override
-    public void reset() {
-      count = 0;
-      maxCount = 0;
-      objectArrayList = new ArrayList<>();
-      addNewArray();
-    }
-
-    @Override
-    public void generateTestData(int values) {
-    }
-  }
-
-  @Override
-  public void setInitialCapacity(int numRecords) {
-    // NoOp
-  }
-
-  @Override
-  public void allocateNew() throws OutOfMemoryException {
-    addNewArray();
-  }
-
-  public void allocateNew(int valueCount) throws OutOfMemoryException {
-    while (maxCount < valueCount) {
-      addNewArray();
-    }
-  }
-
-  @Override
-  public boolean allocateNewSafe() {
-    allocateNew();
-    return true;
-  }
-
-  @Override
-  public int getBufferSize() {
-    throw new UnsupportedOperationException("ObjectVector does not support this");
-  }
-
-  @Override
-  public int getBufferSizeFor(final int valueCount) {
-    throw new UnsupportedOperationException("ObjectVector does not support this");
-  }
-
-  @Override
-  public void close() {
-    clear();
-  }
-
-  @Override
-  public void clear() {
-    objectArrayList.clear();
-    maxCount = 0;
-    count = 0;
-  }
-
-  @Override
-  public MaterializedField getField() {
-    return field;
-  }
-
-  @Override
-  public TransferPair getTransferPair(BufferAllocator allocator) {
-    throw new UnsupportedOperationException("ObjectVector does not support this");
-  }
-
-  @Override
-  public TransferPair makeTransferPair(ValueVector to) {
-    throw new UnsupportedOperationException("ObjectVector does not support this");
-  }
-
-  @Override
-  public TransferPair getTransferPair(String ref, BufferAllocator allocator) {
-    throw new UnsupportedOperationException("ObjectVector does not support this");
-  }
-
-  @Override
-  public int getValueCapacity() {
-    return maxCount;
-  }
-
-  @Override
-  public Accessor getAccessor() {
-    return accessor;
-  }
-
-  @Override
-  public ArrowBuf[] getBuffers(boolean clear) {
-    throw new UnsupportedOperationException("ObjectVector does not support this");
-  }
-
-//  @Override
-//  public void load(UserBitShared.SerializedField metadata, DrillBuf buffer) {
-//    throw new UnsupportedOperationException("ObjectVector does not support this");
-//  }
-//
-//  @Override
-//  public UserBitShared.SerializedField getMetadata() {
-//    throw new UnsupportedOperationException("ObjectVector does not support this");
-//  }
-
-  @Override
-  public Mutator getMutator() {
-    return mutator;
-  }
-
-  @Override
-  public Iterator<ValueVector> iterator() {
-    throw new UnsupportedOperationException("ObjectVector does not support this");
-  }
-
-  public final class Accessor extends BaseAccessor {
-    @Override
-    public Object getObject(int index) {
-      int listOffset = index / allocationSize;
-      if (listOffset >= objectArrayList.size()) {
-        addNewArray();
-      }
-      return objectArrayList.get(listOffset)[index % allocationSize];
-    }
-
-    @Override
-    public int getValueCount() {
-      return count;
-    }
-
-    public Object get(int index) {
-      return getObject(index);
-    }
-
-    public void get(int index, ObjectHolder holder){
-      holder.obj = getObject(index);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/java/org/apache/arrow/vector/ValueHolderHelper.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/ValueHolderHelper.java b/java/vector/src/main/java/org/apache/arrow/vector/ValueHolderHelper.java
deleted file mode 100644
index 61ce285..0000000
--- a/java/vector/src/main/java/org/apache/arrow/vector/ValueHolderHelper.java
+++ /dev/null
@@ -1,203 +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.arrow.vector;
-
-import io.netty.buffer.ArrowBuf;
-
-import java.math.BigDecimal;
-
-import org.apache.arrow.memory.BufferAllocator;
-import org.apache.arrow.vector.holders.BigIntHolder;
-import org.apache.arrow.vector.holders.BitHolder;
-import org.apache.arrow.vector.holders.DateHolder;
-import org.apache.arrow.vector.holders.Decimal18Holder;
-import org.apache.arrow.vector.holders.Decimal28SparseHolder;
-import org.apache.arrow.vector.holders.Decimal38SparseHolder;
-import org.apache.arrow.vector.holders.Decimal9Holder;
-import org.apache.arrow.vector.holders.Float4Holder;
-import org.apache.arrow.vector.holders.Float8Holder;
-import org.apache.arrow.vector.holders.IntHolder;
-import org.apache.arrow.vector.holders.IntervalDayHolder;
-import org.apache.arrow.vector.holders.IntervalYearHolder;
-import org.apache.arrow.vector.holders.NullableBitHolder;
-import org.apache.arrow.vector.holders.TimeHolder;
-import org.apache.arrow.vector.holders.TimeStampHolder;
-import org.apache.arrow.vector.holders.VarCharHolder;
-import org.apache.arrow.vector.util.DecimalUtility;
-
-import com.google.common.base.Charsets;
-
-
-public class ValueHolderHelper {
-  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ValueHolderHelper.class);
-
-  public static IntHolder getIntHolder(int value) {
-    IntHolder holder = new IntHolder();
-    holder.value = value;
-
-    return holder;
-  }
-
-  public static BigIntHolder getBigIntHolder(long value) {
-    BigIntHolder holder = new BigIntHolder();
-    holder.value = value;
-
-    return holder;
-  }
-
-  public static Float4Holder getFloat4Holder(float value) {
-    Float4Holder holder = new Float4Holder();
-    holder.value = value;
-
-    return holder;
-  }
-
-  public static Float8Holder getFloat8Holder(double value) {
-    Float8Holder holder = new Float8Holder();
-    holder.value = value;
-
-    return holder;
-  }
-
-  public static DateHolder getDateHolder(long value) {
-    DateHolder holder = new DateHolder();
-    holder.value = value;
-    return holder;
-  }
-
-  public static TimeHolder getTimeHolder(int value) {
-    TimeHolder holder = new TimeHolder();
-    holder.value = value;
-    return holder;
-  }
-
-  public static TimeStampHolder getTimeStampHolder(long value) {
-    TimeStampHolder holder = new TimeStampHolder();
-    holder.value = value;
-    return holder;
-  }
-
-  public static BitHolder getBitHolder(int value) {
-    BitHolder holder = new BitHolder();
-    holder.value = value;
-
-    return holder;
-  }
-
-  public static NullableBitHolder getNullableBitHolder(boolean isNull, int value) {
-    NullableBitHolder holder = new NullableBitHolder();
-    holder.isSet = isNull? 0 : 1;
-    if (! isNull) {
-      holder.value = value;
-    }
-
-    return holder;
-  }
-
-  public static VarCharHolder getVarCharHolder(ArrowBuf buf, String s){
-    VarCharHolder vch = new VarCharHolder();
-
-    byte[] b = s.getBytes(Charsets.UTF_8);
-    vch.start = 0;
-    vch.end = b.length;
-    vch.buffer = buf.reallocIfNeeded(b.length);
-    vch.buffer.setBytes(0, b);
-    return vch;
-  }
-
-  public static VarCharHolder getVarCharHolder(BufferAllocator a, String s){
-    VarCharHolder vch = new VarCharHolder();
-
-    byte[] b = s.getBytes(Charsets.UTF_8);
-    vch.start = 0;
-    vch.end = b.length;
-    vch.buffer = a.buffer(b.length); //
-    vch.buffer.setBytes(0, b);
-    return vch;
-  }
-
-
-  public static IntervalYearHolder getIntervalYearHolder(int intervalYear) {
-    IntervalYearHolder holder = new IntervalYearHolder();
-
-    holder.value = intervalYear;
-    return holder;
-  }
-
-  public static IntervalDayHolder getIntervalDayHolder(int days, int millis) {
-      IntervalDayHolder dch = new IntervalDayHolder();
-
-      dch.days = days;
-      dch.milliseconds = millis;
-      return dch;
-  }
-
-  public static Decimal9Holder getDecimal9Holder(int decimal, int scale, int precision) {
-    Decimal9Holder dch = new Decimal9Holder();
-
-    dch.scale = scale;
-    dch.precision = precision;
-    dch.value = decimal;
-
-    return dch;
-  }
-
-  public static Decimal18Holder getDecimal18Holder(long decimal, int scale, int precision) {
-    Decimal18Holder dch = new Decimal18Holder();
-
-    dch.scale = scale;
-    dch.precision = precision;
-    dch.value = decimal;
-
-    return dch;
-  }
-
-  public static Decimal28SparseHolder getDecimal28Holder(ArrowBuf buf, String decimal) {
-
-    Decimal28SparseHolder dch = new Decimal28SparseHolder();
-
-    BigDecimal bigDecimal = new BigDecimal(decimal);
-
-    dch.scale = bigDecimal.scale();
-    dch.precision = bigDecimal.precision();
-    Decimal28SparseHolder.setSign(bigDecimal.signum() == -1, dch.start, dch.buffer);
-    dch.start = 0;
-    dch.buffer = buf.reallocIfNeeded(5 * DecimalUtility.INTEGER_SIZE);
-    DecimalUtility
-        .getSparseFromBigDecimal(bigDecimal, dch.buffer, dch.start, dch.scale, dch.precision, dch.nDecimalDigits);
-
-    return dch;
-  }
-
-  public static Decimal38SparseHolder getDecimal38Holder(ArrowBuf buf, String decimal) {
-
-      Decimal38SparseHolder dch = new Decimal38SparseHolder();
-
-      BigDecimal bigDecimal = new BigDecimal(decimal);
-
-      dch.scale = bigDecimal.scale();
-      dch.precision = bigDecimal.precision();
-      Decimal38SparseHolder.setSign(bigDecimal.signum() == -1, dch.start, dch.buffer);
-      dch.start = 0;
-    dch.buffer = buf.reallocIfNeeded(dch.maxPrecision * DecimalUtility.INTEGER_SIZE);
-    DecimalUtility
-        .getSparseFromBigDecimal(bigDecimal, dch.buffer, dch.start, dch.scale, dch.precision, dch.nDecimalDigits);
-
-      return dch;
-  }
-}

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/java/org/apache/arrow/vector/ValueVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/ValueVector.java b/java/vector/src/main/java/org/apache/arrow/vector/ValueVector.java
index a170c59..35321c9 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/ValueVector.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/ValueVector.java
@@ -24,8 +24,9 @@ import io.netty.buffer.ArrowBuf;
 import org.apache.arrow.memory.BufferAllocator;
 import org.apache.arrow.memory.OutOfMemoryException;
 import org.apache.arrow.vector.complex.reader.FieldReader;
-import org.apache.arrow.vector.types.MaterializedField;
+import org.apache.arrow.vector.types.Types.MinorType;
 import org.apache.arrow.vector.util.TransferPair;
+import org.apache.arrow.vector.types.pojo.Field;
 
 /**
  * An abstraction that is used to store a sequence of values in an individual column.
@@ -33,8 +34,7 @@ import org.apache.arrow.vector.util.TransferPair;
  * 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
- * that vector is allocated before attempting to read or write.
+ * It is important that vector is allocated before attempting to read or write.
  *
  * There are a few "rules" around vectors:
  *
@@ -94,7 +94,9 @@ public interface ValueVector extends Closeable, Iterable<ValueVector> {
   /**
    * Get information about how this field is materialized.
    */
-  MaterializedField getField();
+  Field getField();
+
+  MinorType getMinorType();
 
   /**
    * Returns a {@link org.apache.arrow.vector.util.TransferPair transfer pair}, creating a new target vector of

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/java/org/apache/arrow/vector/VectorDescriptor.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/VectorDescriptor.java b/java/vector/src/main/java/org/apache/arrow/vector/VectorDescriptor.java
deleted file mode 100644
index fdad99a..0000000
--- a/java/vector/src/main/java/org/apache/arrow/vector/VectorDescriptor.java
+++ /dev/null
@@ -1,83 +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.arrow.vector;
-
-import java.util.Collection;
-
-import com.google.common.base.Preconditions;
-
-import org.apache.arrow.vector.types.MaterializedField;
-import org.apache.arrow.vector.types.Types.MajorType;
-
-public class VectorDescriptor {
-  private static final String DEFAULT_NAME = "NONE";
-
-  private final MaterializedField field;
-
-  public VectorDescriptor(final MajorType type) {
-    this(DEFAULT_NAME, type);
-  }
-
-  public VectorDescriptor(final String name, final MajorType type) {
-    this(MaterializedField.create(name, type));
-  }
-
-  public VectorDescriptor(final MaterializedField field) {
-    this.field = Preconditions.checkNotNull(field, "field cannot be null");
-  }
-
-  public MaterializedField getField() {
-    return field;
-  }
-
-  public MajorType getType() {
-    return field.getType();
-  }
-
-  public String getName() {
-    return field.getLastName();
-  }
-
-  public Collection<MaterializedField> getChildren() {
-    return field.getChildren();
-  }
-
-  public boolean hasName() {
-    return getName() != DEFAULT_NAME;
-  }
-
-  public VectorDescriptor withName(final String name) {
-    return new VectorDescriptor(field.withPath(name));
-  }
-
-  public VectorDescriptor withType(final MajorType type) {
-    return new VectorDescriptor(field.withType(type));
-  }
-
-  public static VectorDescriptor create(final String name, final MajorType type) {
-    return new VectorDescriptor(name, type);
-  }
-
-  public static VectorDescriptor create(final MajorType type) {
-    return new VectorDescriptor(type);
-  }
-
-  public static VectorDescriptor create(final MaterializedField field) {
-    return new VectorDescriptor(field);
-  }
-}

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/java/org/apache/arrow/vector/ZeroVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/ZeroVector.java b/java/vector/src/main/java/org/apache/arrow/vector/ZeroVector.java
index c94e8d1..705a24b 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/ZeroVector.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/ZeroVector.java
@@ -17,18 +17,20 @@
  */
 package org.apache.arrow.vector;
 
+import com.google.flatbuffers.FlatBufferBuilder;
 import io.netty.buffer.ArrowBuf;
 
 import java.util.Collections;
 import java.util.Iterator;
 
+import org.apache.arrow.flatbuf.Type;
 import org.apache.arrow.memory.BufferAllocator;
 import org.apache.arrow.memory.OutOfMemoryException;
 import org.apache.arrow.vector.complex.impl.NullReader;
 import org.apache.arrow.vector.complex.reader.FieldReader;
-import org.apache.arrow.vector.types.MaterializedField;
-import org.apache.arrow.vector.types.Types;
 import org.apache.arrow.vector.types.Types.MinorType;
+import org.apache.arrow.vector.types.pojo.ArrowType.Null;
+import org.apache.arrow.vector.types.pojo.Field;
 import org.apache.arrow.vector.util.TransferPair;
 
 import com.google.common.collect.Iterators;
@@ -36,7 +38,7 @@ import com.google.common.collect.Iterators;
 public class ZeroVector implements ValueVector {
   public final static ZeroVector INSTANCE = new ZeroVector();
 
-  private final MaterializedField field = MaterializedField.create("[DEFAULT]", Types.required(MinorType.LATE));
+  private final String name = "[DEFAULT]";
 
   private final TransferPair defaultPair = new TransferPair() {
     @Override
@@ -91,24 +93,21 @@ public class ZeroVector implements ValueVector {
   public void clear() { }
 
   @Override
-  public MaterializedField getField() {
-    return field;
+  public Field getField() {
+    return new Field(name, true, new Null(), null);
   }
 
   @Override
+  public MinorType getMinorType() {
+    return MinorType.NULL;
+  }
+
+
+  @Override
   public TransferPair getTransferPair(BufferAllocator allocator) {
     return defaultPair;
   }
 
-//  @Override
-//  public UserBitShared.SerializedField getMetadata() {
-//    return getField()
-//        .getAsBuilder()
-//        .setBufferLength(getBufferSize())
-//        .setValueCount(getAccessor().getValueCount())
-//        .build();
-//  }
-
   @Override
   public Iterator<ValueVector> iterator() {
     return Collections.emptyIterator();
@@ -176,7 +175,4 @@ public class ZeroVector implements ValueVector {
   public FieldReader getReader() {
     return NullReader.INSTANCE;
   }
-
-//  @Override
-//  public void load(UserBitShared.SerializedField metadata, DrillBuf buffer) { }
 }

http://git-wip-us.apache.org/repos/asf/arrow/blob/e7e399db/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java
index 9fae238..ed77975 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java
@@ -21,12 +21,10 @@ import java.util.Collection;
 
 import javax.annotation.Nullable;
 
+import org.apache.arrow.flatbuf.Field;
 import org.apache.arrow.memory.BufferAllocator;
 import org.apache.arrow.memory.OutOfMemoryException;
 import org.apache.arrow.vector.ValueVector;
-import org.apache.arrow.vector.types.MaterializedField;
-import org.apache.arrow.vector.types.Types.DataMode;
-import org.apache.arrow.vector.types.Types.MajorType;
 import org.apache.arrow.vector.types.Types.MinorType;
 import org.apache.arrow.vector.util.CallBack;
 
@@ -43,12 +41,12 @@ import com.google.common.collect.Sets;
 public abstract class AbstractContainerVector implements ValueVector {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractContainerVector.class);
 
-  protected MaterializedField field;
+  protected final String name;
   protected final BufferAllocator allocator;
   protected final CallBack callBack;
 
-  protected AbstractContainerVector(MaterializedField field, BufferAllocator allocator, CallBack callBack) {
-    this.field = Preconditions.checkNotNull(field);
+  protected AbstractContainerVector(String name, BufferAllocator allocator, CallBack callBack) {
+    this.name = name;
     this.allocator = allocator;
     this.callBack = callBack;
   }
@@ -65,14 +63,6 @@ public abstract class AbstractContainerVector implements ValueVector {
   }
 
   /**
-   * Returns the field definition of this instance.
-   */
-  @Override
-  public MaterializedField getField() {
-    return field;
-  }
-
-  /**
    * Returns a {@link org.apache.arrow.vector.ValueVector} corresponding to the given field name if exists or null.
    */
   public ValueVector getChild(String name) {
@@ -80,19 +70,6 @@ public abstract class AbstractContainerVector implements ValueVector {
   }
 
   /**
-   * Returns a sequence of field names in the order that they show up in the schema.
-   */
-  protected Collection<String> getChildFieldNames() {
-    return Sets.newLinkedHashSet(Iterables.transform(field.getChildren(), new Function<MaterializedField, String>() {
-      @Nullable
-      @Override
-      public String apply(MaterializedField field) {
-        return Preconditions.checkNotNull(field).getLastName();
-      }
-    }));
-  }
-
-  /**
    * Clears out all underlying child vectors.
    */
  @Override
@@ -109,22 +86,6 @@ public abstract class AbstractContainerVector implements ValueVector {
     throw new IllegalStateException(String.format("Vector requested [%s] was different than type stored [%s]. Arrow doesn't yet support hetergenous types.", clazz.getSimpleName(), v.getClass().getSimpleName()));
   }
 
-  MajorType getLastPathType() {
-    if((this.getField().getType().getMinorType() == MinorType.LIST  &&
-        this.getField().getType().getMode() == DataMode.REPEATED)) {  // Use Repeated scalar type instead of Required List.
-      VectorWithOrdinal vord = getChildVectorWithOrdinal(null);
-      ValueVector v = vord.vector;
-      if (! (v instanceof  AbstractContainerVector)) {
-        return v.getField().getType();
-      }
-    } else if (this.getField().getType().getMinorType() == MinorType.MAP  &&
-        this.getField().getType().getMode() == DataMode.REPEATED) {  // Use Required Map
-      return new MajorType(MinorType.MAP, DataMode.REQUIRED);
-    }
-
-    return this.getField().getType();
-  }
-
   protected boolean supportsDirectRead() {
     return false;
   }
@@ -133,7 +94,7 @@ public abstract class AbstractContainerVector implements ValueVector {
   public abstract int size();
 
   // add a new vector with the input MajorType or return the existing vector if we already added one with the same type
-  public abstract <T extends ValueVector> T addOrGet(String name, MajorType type, Class<T> clazz);
+  public abstract <T extends ValueVector> T addOrGet(String name, MinorType minorType, Class<T> clazz, int... precisionScale);
 
   // return the child vector with the input name
   public abstract <T extends ValueVector> T getChild(String name, Class<T> clazz);


Mime
View raw message