drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [08/45] drill git commit: DRILL-3987: (MOVE) Extract key vector, field reader, complex/field writer classes.
Date Fri, 13 Nov 2015 02:37:38 GMT
http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/ComplexWriterImpl.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/ComplexWriterImpl.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/ComplexWriterImpl.java
deleted file mode 100644
index 5575b5e..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/ComplexWriterImpl.java
+++ /dev/null
@@ -1,218 +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.complex.impl;
-
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.record.MaterializedField;
-import org.apache.drill.exec.record.VectorContainer;
-import org.apache.drill.exec.vector.ValueVector;
-import org.apache.drill.exec.vector.complex.MapVector;
-import org.apache.drill.exec.vector.complex.StateTool;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter;
-
-import com.google.common.base.Preconditions;
-
-public class ComplexWriterImpl extends AbstractFieldWriter implements ComplexWriter {
-//  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ComplexWriterImpl.class);
-
-  private SingleMapWriter mapRoot;
-  private SingleListWriter listRoot;
-  private final MapVector container;
-
-  Mode mode = Mode.INIT;
-  private final String name;
-  private final boolean unionEnabled;
-
-  private enum Mode { INIT, MAP, LIST };
-
-  public ComplexWriterImpl(String name, MapVector container, boolean unionEnabled){
-    super(null);
-    this.name = name;
-    this.container = container;
-    this.unionEnabled = unionEnabled;
-  }
-
-  public ComplexWriterImpl(String name, MapVector container){
-    this(name, container, false);
-  }
-
-  @Override
-  public MaterializedField getField() {
-    return container.getField();
-  }
-
-  @Override
-  public int getValueCapacity() {
-    return container.getValueCapacity();
-  }
-
-  private void check(Mode... modes){
-    StateTool.check(mode, modes);
-  }
-
-  @Override
-  public void reset(){
-    setPosition(0);
-  }
-
-  @Override
-  public void close() throws Exception {
-    clear();
-    mapRoot.close();
-    if (listRoot != null) {
-      listRoot.close();
-    }
-  }
-
-  @Override
-  public void clear(){
-    switch(mode){
-    case MAP:
-      mapRoot.clear();
-      break;
-    case LIST:
-      listRoot.clear();
-      break;
-    }
-  }
-
-  @Override
-  public void setValueCount(int count){
-    switch(mode){
-    case MAP:
-      mapRoot.setValueCount(count);
-      break;
-    case LIST:
-      listRoot.setValueCount(count);
-      break;
-    }
-  }
-
-  @Override
-  public void setPosition(int index){
-    super.setPosition(index);
-    switch(mode){
-    case MAP:
-      mapRoot.setPosition(index);
-      break;
-    case LIST:
-      listRoot.setPosition(index);
-      break;
-    }
-  }
-
-
-  public MapWriter directMap(){
-    Preconditions.checkArgument(name == null);
-
-    switch(mode){
-
-    case INIT:
-      MapVector map = (MapVector) container;
-      mapRoot = new SingleMapWriter(map, this, unionEnabled);
-      mapRoot.setPosition(idx());
-      mode = Mode.MAP;
-      break;
-
-    case MAP:
-      break;
-
-    default:
-        check(Mode.INIT, Mode.MAP);
-    }
-
-    return mapRoot;
-  }
-
-  @Override
-  public MapWriter rootAsMap() {
-    switch(mode){
-
-    case INIT:
-      MapVector map = container.addOrGet(name, Types.required(MinorType.MAP), MapVector.class);
-      mapRoot = new SingleMapWriter(map, this, unionEnabled);
-      mapRoot.setPosition(idx());
-      mode = Mode.MAP;
-      break;
-
-    case MAP:
-      break;
-
-    default:
-        check(Mode.INIT, Mode.MAP);
-    }
-
-    return mapRoot;
-  }
-
-
-  @Override
-  public void allocate() {
-    if(mapRoot != null) {
-      mapRoot.allocate();
-    } else if(listRoot != null) {
-      listRoot.allocate();
-    }
-  }
-
-  @Override
-  public ListWriter rootAsList() {
-    switch(mode){
-
-    case INIT:
-      listRoot = new SingleListWriter(name, container, this);
-      listRoot.setPosition(idx());
-      mode = Mode.LIST;
-      break;
-
-    case LIST:
-      break;
-
-    default:
-        check(Mode.INIT, Mode.MAP);
-    }
-
-    return listRoot;
-  }
-
-  private static class VectorAccessibleFacade extends MapVector {
-
-    private final VectorContainer vc;
-
-    public VectorAccessibleFacade(VectorContainer vc) {
-      super("", null, null);
-      this.vc = vc;
-    }
-
-    @Override
-    public <T extends ValueVector> T addOrGet(String name, MajorType type, Class<T> clazz) {
-      final ValueVector v = vc.addOrGet(name, type, clazz);
-      putChild(name, v);
-      return this.typeify(v, clazz);
-
-    }
-
-  }
-
-  public static ComplexWriter getWriter(String name, VectorContainer container){
-    VectorAccessibleFacade vc = new VectorAccessibleFacade(container);
-    return new ComplexWriterImpl(name, vc);
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/PromotableWriter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/PromotableWriter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/PromotableWriter.java
deleted file mode 100644
index 5f57c01..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/PromotableWriter.java
+++ /dev/null
@@ -1,194 +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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.complex.impl;
-
-import org.apache.drill.common.expression.FieldReference;
-import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.TypeHelper;
-import org.apache.drill.exec.record.MaterializedField;
-import org.apache.drill.exec.record.TransferPair;
-import org.apache.drill.exec.vector.ValueVector;
-import org.apache.drill.exec.vector.VectorDescriptor;
-import org.apache.drill.exec.vector.ZeroVector;
-import org.apache.drill.exec.vector.complex.AbstractMapVector;
-import org.apache.drill.exec.vector.complex.ListVector;
-import org.apache.drill.exec.vector.complex.UnionVector;
-import org.apache.drill.exec.vector.complex.writer.FieldWriter;
-
-import java.lang.reflect.Constructor;
-
-/**
- * This FieldWriter implementation delegates all FieldWriter API calls to an inner FieldWriter. This inner field writer
- * can start as a specific type, and this class will promote the writer to a UnionWriter if a call is made that the specifically
- * typed writer cannot handle. A new UnionVector is created, wrapping the original vector, and replaces the original vector
- * in the parent vector, which can be either an AbstractMapVector or a ListVector.
- */
-public class PromotableWriter extends AbstractPromotableFieldWriter {
-
-  private final AbstractMapVector parentContainer;
-  private final ListVector listVector;
-  private int position;
-
-  private enum State {
-    UNTYPED, SINGLE, UNION
-  }
-
-  private MinorType type;
-  private ValueVector vector;
-  private UnionVector unionVector;
-  private State state;
-  private FieldWriter writer;
-
-  public PromotableWriter(ValueVector v, AbstractMapVector parentContainer) {
-    super(null);
-    this.parentContainer = parentContainer;
-    this.listVector = null;
-    init(v);
-  }
-
-  public PromotableWriter(ValueVector v, ListVector listVector) {
-    super(null);
-    this.listVector = listVector;
-    this.parentContainer = null;
-    init(v);
-  }
-
-  private void init(ValueVector v) {
-    if (v instanceof UnionVector) {
-      state = State.UNION;
-      unionVector = (UnionVector) v;
-      writer = new UnionWriter(unionVector);
-    } else if (v instanceof ZeroVector) {
-      state = State.UNTYPED;
-    } else {
-      setWriter(v);
-    }
-  }
-
-  private void setWriter(ValueVector v) {
-    state = State.SINGLE;
-    vector = v;
-    type = v.getField().getType().getMinorType();
-    Class writerClass = TypeHelper.getWriterImpl(v.getField().getType().getMinorType(), v.getField().getDataMode());
-    if (writerClass.equals(SingleListWriter.class)) {
-      writerClass = UnionListWriter.class;
-    }
-    Class vectorClass = TypeHelper.getValueVectorClass(v.getField().getType().getMinorType(), v.getField().getDataMode());
-    try {
-      Constructor constructor = null;
-      for (Constructor c : writerClass.getConstructors()) {
-        if (c.getParameterTypes().length == 3) {
-          constructor = c;
-        }
-      }
-      if (constructor == null) {
-        constructor = writerClass.getConstructor(vectorClass, AbstractFieldWriter.class);
-        writer = (FieldWriter) constructor.newInstance(vector, null);
-      } else {
-        writer = (FieldWriter) constructor.newInstance(vector, null, true);
-      }
-    } catch (ReflectiveOperationException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
-  @Override
-  public void setPosition(int index) {
-    super.setPosition(index);
-    FieldWriter w = getWriter();
-    if (w == null) {
-      position = index;
-    } else {
-      w.setPosition(index);
-    }
-  }
-
-  protected FieldWriter getWriter(MinorType type) {
-    if (state == State.UNION) {
-      return writer;
-    }
-    if (state == State.UNTYPED) {
-      if (type == null) {
-        return null;
-      }
-      ValueVector v = listVector.addOrGetVector(new VectorDescriptor(Types.optional(type))).getVector();
-      v.allocateNew();
-      setWriter(v);
-      writer.setPosition(position);
-    }
-    if (type != this.type) {
-      return promoteToUnion();
-    }
-    return writer;
-  }
-
-  @Override
-  public boolean isEmptyMap() {
-    return writer.isEmptyMap();
-  }
-
-  protected FieldWriter getWriter() {
-    return getWriter(type);
-  }
-
-  private FieldWriter promoteToUnion() {
-    String name = vector.getField().getLastName();
-    TransferPair tp = vector.getTransferPair(new FieldReference(vector.getField().getType().getMinorType().name().toLowerCase()));
-    tp.transfer();
-    if (parentContainer != null) {
-      unionVector = parentContainer.addOrGet(name, Types.optional(MinorType.UNION), UnionVector.class);
-    } else if (listVector != null) {
-      unionVector = listVector.promoteToUnion();
-    }
-    unionVector.addVector(tp.getTo());
-    writer = new UnionWriter(unionVector);
-    writer.setPosition(idx());
-    for (int i = 0; i < idx(); i++) {
-      unionVector.getMutator().setType(i, vector.getField().getType().getMinorType());
-    }
-    vector = null;
-    state = State.UNION;
-    return writer;
-  }
-
-  @Override
-  public void allocate() {
-    getWriter().allocate();
-  }
-
-  @Override
-  public void clear() {
-    getWriter().clear();
-  }
-
-  @Override
-  public MaterializedField getField() {
-    return getWriter().getField();
-  }
-
-  @Override
-  public int getValueCapacity() {
-    return getWriter().getValueCapacity();
-  }
-
-  @Override
-  public void close() throws Exception {
-    getWriter().close();
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/RepeatedListReaderImpl.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/RepeatedListReaderImpl.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/RepeatedListReaderImpl.java
deleted file mode 100644
index 36e9bee..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/RepeatedListReaderImpl.java
+++ /dev/null
@@ -1,145 +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.complex.impl;
-
-
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.holders.RepeatedListHolder;
-import org.apache.drill.exec.vector.ValueVector;
-import org.apache.drill.exec.vector.complex.RepeatedListVector;
-import org.apache.drill.exec.vector.complex.reader.FieldReader;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
-
-public class RepeatedListReaderImpl extends AbstractFieldReader{
-  private static final int NO_VALUES = Integer.MAX_VALUE - 1;
-  private static final MajorType TYPE = Types.repeated(MinorType.LIST);
-  private final String name;
-  private final RepeatedListVector container;
-  private FieldReader reader;
-
-  public RepeatedListReaderImpl(String name, RepeatedListVector container) {
-    super();
-    this.name = name;
-    this.container = container;
-  }
-
-  @Override
-  public MajorType getType() {
-    return TYPE;
-  }
-
-  @Override
-  public void copyAsValue(ListWriter writer) {
-    if (currentOffset == NO_VALUES) {
-      return;
-    }
-    RepeatedListWriter impl = (RepeatedListWriter) writer;
-    impl.container.copyFromSafe(idx(), impl.idx(), container);
-  }
-
-  @Override
-  public void copyAsField(String name, MapWriter writer) {
-    if (currentOffset == NO_VALUES) {
-      return;
-    }
-    RepeatedListWriter impl = (RepeatedListWriter) writer.list(name);
-    impl.container.copyFromSafe(idx(), impl.idx(), container);
-  }
-
-  private int currentOffset;
-  private int maxOffset;
-
-  @Override
-  public void reset() {
-    super.reset();
-    currentOffset = 0;
-    maxOffset = 0;
-    if (reader != null) {
-      reader.reset();
-    }
-    reader = null;
-  }
-
-  @Override
-  public int size() {
-    return maxOffset - currentOffset;
-  }
-
-  @Override
-  public void setPosition(int index) {
-    if (index < 0 || index == NO_VALUES) {
-      currentOffset = NO_VALUES;
-      return;
-    }
-
-    super.setPosition(index);
-    RepeatedListHolder h = new RepeatedListHolder();
-    container.getAccessor().get(index, h);
-    if (h.start == h.end) {
-      currentOffset = NO_VALUES;
-    } else {
-      currentOffset = h.start-1;
-      maxOffset = h.end;
-      if(reader != null) {
-        reader.setPosition(currentOffset);
-      }
-    }
-  }
-
-  @Override
-  public boolean next() {
-    if (currentOffset +1 < maxOffset) {
-      currentOffset++;
-      if (reader != null) {
-        reader.setPosition(currentOffset);
-      }
-      return true;
-    } else {
-      currentOffset = NO_VALUES;
-      return false;
-    }
-  }
-
-  @Override
-  public Object readObject() {
-    return container.getAccessor().getObject(idx());
-  }
-
-  @Override
-  public FieldReader reader() {
-    if (reader == null) {
-      ValueVector child = container.getChild(name);
-      if (child == null) {
-        reader = NullReader.INSTANCE;
-      } else {
-        reader = child.getReader();
-      }
-      reader.setPosition(currentOffset);
-    }
-    return reader;
-  }
-
-  public boolean isSet() {
-    return true;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/RepeatedMapReaderImpl.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/RepeatedMapReaderImpl.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/RepeatedMapReaderImpl.java
deleted file mode 100644
index b2fe7b7..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/RepeatedMapReaderImpl.java
+++ /dev/null
@@ -1,192 +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.complex.impl;
-
-import java.util.Map;
-
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.exec.expr.holders.RepeatedMapHolder;
-import org.apache.drill.exec.vector.ValueVector;
-import org.apache.drill.exec.vector.complex.RepeatedMapVector;
-import org.apache.drill.exec.vector.complex.reader.FieldReader;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
-
-import com.google.common.collect.Maps;
-
-@SuppressWarnings("unused")
-public class RepeatedMapReaderImpl extends AbstractFieldReader{
-  private static final int NO_VALUES = Integer.MAX_VALUE - 1;
-
-  private final RepeatedMapVector vector;
-  private final Map<String, FieldReader> fields = Maps.newHashMap();
-
-  public RepeatedMapReaderImpl(RepeatedMapVector vector) {
-    this.vector = vector;
-  }
-
-  private void setChildrenPosition(int index) {
-    for (FieldReader r : fields.values()) {
-      r.setPosition(index);
-    }
-  }
-
-  @Override
-  public FieldReader reader(String name) {
-    FieldReader reader = fields.get(name);
-    if (reader == null) {
-      ValueVector child = vector.getChild(name);
-      if (child == null) {
-        reader = NullReader.INSTANCE;
-      } else {
-        reader = child.getReader();
-      }
-      fields.put(name, reader);
-      reader.setPosition(currentOffset);
-    }
-    return reader;
-  }
-
-  @Override
-  public FieldReader reader() {
-    if (currentOffset == NO_VALUES) {
-      return NullReader.INSTANCE;
-    }
-
-    setChildrenPosition(currentOffset);
-    return new SingleLikeRepeatedMapReaderImpl(vector, this);
-  }
-
-  private int currentOffset;
-  private int maxOffset;
-
-  @Override
-  public void reset() {
-    super.reset();
-    currentOffset = 0;
-    maxOffset = 0;
-    for (FieldReader reader:fields.values()) {
-      reader.reset();
-    }
-    fields.clear();
-  }
-
-  @Override
-  public int size() {
-    if (isNull()) {
-      return 0;
-    }
-    return maxOffset - (currentOffset < 0 ? 0 : currentOffset);
-  }
-
-  @Override
-  public void setPosition(int index) {
-    if (index < 0 || index == NO_VALUES) {
-      currentOffset = NO_VALUES;
-      return;
-    }
-
-    super.setPosition(index);
-    RepeatedMapHolder h = new RepeatedMapHolder();
-    vector.getAccessor().get(index, h);
-    if (h.start == h.end) {
-      currentOffset = NO_VALUES;
-    } else {
-      currentOffset = h.start-1;
-      maxOffset = h.end;
-      setChildrenPosition(currentOffset);
-    }
-  }
-
-  public void setSinglePosition(int index, int childIndex) {
-    super.setPosition(index);
-    RepeatedMapHolder h = new RepeatedMapHolder();
-    vector.getAccessor().get(index, h);
-    if (h.start == h.end) {
-      currentOffset = NO_VALUES;
-    } else {
-      int singleOffset = h.start + childIndex;
-      assert singleOffset < h.end;
-      currentOffset = singleOffset;
-      maxOffset = singleOffset + 1;
-      setChildrenPosition(singleOffset);
-    }
-  }
-
-  @Override
-  public boolean next() {
-    if (currentOffset +1 < maxOffset) {
-      setChildrenPosition(++currentOffset);
-      return true;
-    } else {
-      currentOffset = NO_VALUES;
-      return false;
-    }
-  }
-
-  public boolean isNull() {
-    return currentOffset == NO_VALUES;
-  }
-
-  @Override
-  public Object readObject() {
-    return vector.getAccessor().getObject(idx());
-  }
-
-  @Override
-  public MajorType getType() {
-    return vector.getField().getType();
-  }
-
-  @Override
-  public java.util.Iterator<String> iterator() {
-    return vector.fieldNameIterator();
-  }
-
-  @Override
-  public boolean isSet() {
-    return true;
-  }
-
-  @Override
-  public void copyAsValue(MapWriter writer) {
-    if (currentOffset == NO_VALUES) {
-      return;
-    }
-    RepeatedMapWriter impl = (RepeatedMapWriter) writer;
-    impl.container.copyFromSafe(idx(), impl.idx(), vector);
-  }
-
-  public void copyAsValueSingle(MapWriter writer) {
-    if (currentOffset == NO_VALUES) {
-      return;
-    }
-    SingleMapWriter impl = (SingleMapWriter) writer;
-    impl.container.copyFromSafe(currentOffset, impl.idx(), vector);
-  }
-
-  @Override
-  public void copyAsField(String name, MapWriter writer) {
-    if (currentOffset == NO_VALUES) {
-      return;
-    }
-    RepeatedMapWriter impl = (RepeatedMapWriter) writer.map(name);
-    impl.container.copyFromSafe(idx(), impl.idx(), vector);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleLikeRepeatedMapReaderImpl.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleLikeRepeatedMapReaderImpl.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleLikeRepeatedMapReaderImpl.java
deleted file mode 100644
index 3f89a9f..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleLikeRepeatedMapReaderImpl.java
+++ /dev/null
@@ -1,89 +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.complex.impl;
-
-import java.util.Iterator;
-
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.vector.complex.RepeatedMapVector;
-import org.apache.drill.exec.vector.complex.reader.FieldReader;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
-
-public class SingleLikeRepeatedMapReaderImpl extends AbstractFieldReader{
-
-  private RepeatedMapReaderImpl delegate;
-
-  public SingleLikeRepeatedMapReaderImpl(RepeatedMapVector vector, FieldReader delegate) {
-    this.delegate = (RepeatedMapReaderImpl) delegate;
-  }
-
-  @Override
-  public int size() {
-    throw new UnsupportedOperationException("You can't call size on a single map reader.");
-  }
-
-  @Override
-  public boolean next() {
-    throw new UnsupportedOperationException("You can't call next on a single map reader.");
-  }
-
-  @Override
-  public MajorType getType() {
-    return Types.required(MinorType.MAP);
-  }
-
-
-  @Override
-  public void copyAsValue(MapWriter writer) {
-    delegate.copyAsValueSingle(writer);
-  }
-
-  public void copyAsValueSingle(MapWriter writer){
-    delegate.copyAsValueSingle(writer);
-  }
-
-  @Override
-  public FieldReader reader(String name) {
-    return delegate.reader(name);
-  }
-
-  @Override
-  public void setPosition(int index) {
-    delegate.setPosition(index);
-  }
-
-  @Override
-  public Object readObject() {
-    return delegate.readObject();
-  }
-
-  @Override
-  public Iterator<String> iterator() {
-    return delegate.iterator();
-  }
-
-  @Override
-  public boolean isSet() {
-    return ! delegate.isNull();
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleListReaderImpl.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleListReaderImpl.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleListReaderImpl.java
deleted file mode 100644
index 60d8c4e..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleListReaderImpl.java
+++ /dev/null
@@ -1,88 +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.complex.impl;
-
-
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.vector.complex.AbstractContainerVector;
-import org.apache.drill.exec.vector.complex.reader.FieldReader;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
-
-@SuppressWarnings("unused")
-public class SingleListReaderImpl extends AbstractFieldReader{
-
-  private static final MajorType TYPE = Types.optional(MinorType.LIST);
-  private final String name;
-  private final AbstractContainerVector container;
-  private FieldReader reader;
-
-  public SingleListReaderImpl(String name, AbstractContainerVector container) {
-    super();
-    this.name = name;
-    this.container = container;
-  }
-
-  @Override
-  public MajorType getType() {
-    return TYPE;
-  }
-
-
-  @Override
-  public void setPosition(int index) {
-    super.setPosition(index);
-    if (reader != null) {
-      reader.setPosition(index);
-    }
-  }
-
-  @Override
-  public Object readObject() {
-    return reader.readObject();
-  }
-
-  @Override
-  public FieldReader reader() {
-    if (reader == null) {
-      reader = container.getChild(name).getReader();
-      setPosition(idx());
-    }
-    return reader;
-  }
-
-  @Override
-  public boolean isSet() {
-    return false;
-  }
-
-  @Override
-  public void copyAsValue(ListWriter writer) {
-    throw new UnsupportedOperationException("Generic list copying not yet supported.  Please resolve to typed list.");
-  }
-
-  @Override
-  public void copyAsField(String name, MapWriter writer) {
-    throw new UnsupportedOperationException("Generic list copying not yet supported.  Please resolve to typed list.");
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleMapReaderImpl.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleMapReaderImpl.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleMapReaderImpl.java
deleted file mode 100644
index 1b39775..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/SingleMapReaderImpl.java
+++ /dev/null
@@ -1,108 +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.complex.impl;
-
-
-import java.util.Map;
-
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.exec.vector.ValueVector;
-import org.apache.drill.exec.vector.complex.MapVector;
-import org.apache.drill.exec.vector.complex.reader.FieldReader;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
-
-import com.google.common.collect.Maps;
-
-@SuppressWarnings("unused")
-public class SingleMapReaderImpl extends AbstractFieldReader{
-
-  private final MapVector vector;
-  private final Map<String, FieldReader> fields = Maps.newHashMap();
-
-  public SingleMapReaderImpl(MapVector vector) {
-    this.vector = vector;
-  }
-
-  private void setChildrenPosition(int index){
-    for(FieldReader r : fields.values()){
-      r.setPosition(index);
-    }
-  }
-
-  @Override
-  public FieldReader reader(String name){
-    FieldReader reader = fields.get(name);
-    if(reader == null){
-      ValueVector child = vector.getChild(name);
-      if(child == null){
-        reader = NullReader.INSTANCE;
-      }else{
-        reader = child.getReader();
-      }
-      fields.put(name, reader);
-      reader.setPosition(idx());
-    }
-    return reader;
-  }
-
-  @Override
-  public void setPosition(int index){
-    super.setPosition(index);
-    for(FieldReader r : fields.values()){
-      r.setPosition(index);
-    }
-  }
-
-  @Override
-  public Object readObject() {
-    return vector.getAccessor().getObject(idx());
-  }
-
-  @Override
-  public boolean isSet() {
-    return true;
-  }
-
-  @Override
-  public MajorType getType(){
-    return vector.getField().getType();
-  }
-
-  @Override
-  public java.util.Iterator<String> iterator(){
-    return vector.fieldNameIterator();
-  }
-
-  @Override
-  public void copyAsValue(MapWriter writer){
-    SingleMapWriter impl = (SingleMapWriter) writer;
-    impl.container.copyFromSafe(idx(), impl.idx(), vector);
-  }
-
-  @Override
-  public void copyAsField(String name, MapWriter writer){
-    SingleMapWriter impl = (SingleMapWriter) writer.map(name);
-    impl.container.copyFromSafe(idx(), impl.idx(), vector);
-  }
-
-
-}
-

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/UnionListReader.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/UnionListReader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/UnionListReader.java
deleted file mode 100644
index 2d351f2..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/impl/UnionListReader.java
+++ /dev/null
@@ -1,100 +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.complex.impl;
-
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.holders.UnionHolder;
-import org.apache.drill.exec.vector.UInt4Vector;
-import org.apache.drill.exec.vector.ValueVector;
-import org.apache.drill.exec.vector.complex.ListVector;
-import org.apache.drill.exec.vector.complex.reader.FieldReader;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
-import org.apache.drill.exec.vector.complex.writer.FieldWriter;
-
-public class UnionListReader extends AbstractFieldReader {
-
-  private ListVector vector;
-  private ValueVector data;
-  private UInt4Vector offsets;
-
-  public UnionListReader(ListVector vector) {
-    this.vector = vector;
-    this.data = vector.getDataVector();
-    this.offsets = vector.getOffsetVector();
-  }
-
-  @Override
-  public boolean isSet() {
-    return true;
-  }
-
-  MajorType type = Types.optional(MinorType.LIST);
-
-  public MajorType getType() {
-    return type;
-  }
-
-  private int currentOffset;
-  private int maxOffset;
-
-  @Override
-  public void setPosition(int index) {
-    super.setPosition(index);
-    currentOffset = offsets.getAccessor().get(index) - 1;
-    maxOffset = offsets.getAccessor().get(index + 1);
-  }
-
-  @Override
-  public FieldReader reader() {
-    return data.getReader();
-  }
-
-  @Override
-  public Object readObject() {
-    return vector.getAccessor().getObject(idx());
-  }
-
-  @Override
-  public void read(int index, UnionHolder holder) {
-    setPosition(idx());
-    for (int i = -1; i < index; i++) {
-      next();
-    }
-    holder.reader = data.getReader();
-    holder.isSet = data.getReader().isSet() ? 1 : 0;
-  }
-
-  @Override
-  public boolean next() {
-    if (currentOffset + 1 < maxOffset) {
-      data.getReader().setPosition(++currentOffset);
-      return true;
-    } else {
-      return false;
-    }
-  }
-
-  public void copyAsValue(ListWriter writer) {
-    ComplexCopier.copy(this, (FieldWriter) writer);
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/reader/FieldReader.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/reader/FieldReader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/reader/FieldReader.java
deleted file mode 100644
index caa3aa6..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/reader/FieldReader.java
+++ /dev/null
@@ -1,29 +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.complex.reader;
-
-import org.apache.drill.exec.vector.complex.reader.BaseReader.ListReader;
-import org.apache.drill.exec.vector.complex.reader.BaseReader.MapReader;
-import org.apache.drill.exec.vector.complex.reader.BaseReader.RepeatedListReader;
-import org.apache.drill.exec.vector.complex.reader.BaseReader.RepeatedMapReader;
-import org.apache.drill.exec.vector.complex.reader.BaseReader.ScalarReader;
-
-
-
-public interface FieldReader extends MapReader, ListReader, ScalarReader, RepeatedMapReader, RepeatedListReader {
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/writer/FieldWriter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/writer/FieldWriter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/writer/FieldWriter.java
deleted file mode 100644
index 1a64978..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/writer/FieldWriter.java
+++ /dev/null
@@ -1,27 +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.complex.writer;
-
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
-import org.apache.drill.exec.vector.complex.writer.BaseWriter.ScalarWriter;
-
-public interface FieldWriter extends MapWriter, ListWriter, ScalarWriter {
-  void allocate();
-  void clear();
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/pom.xml
----------------------------------------------------------------------
diff --git a/exec/pom.xml b/exec/pom.xml
index 98a0398..ebad5fa 100644
--- a/exec/pom.xml
+++ b/exec/pom.xml
@@ -45,6 +45,7 @@
 
 
   <modules>
+    <module>vector</module>
     <module>java-exec</module>
     <module>jdbc</module>
   </modules>

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/pom.xml
----------------------------------------------------------------------
diff --git a/exec/vector/pom.xml b/exec/vector/pom.xml
new file mode 100644
index 0000000..4bd968e
--- /dev/null
+++ b/exec/vector/pom.xml
@@ -0,0 +1,146 @@
+<?xml version="1.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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>exec-parent</artifactId>
+    <groupId>org.apache.drill.exec</groupId>
+    <version>1.3.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>vector</artifactId>
+  <name>exec/Vectors</name>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.apache.drill</groupId>
+      <artifactId>drill-protocol</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.drill</groupId>
+      <artifactId>drill-common</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.drill</groupId>
+      <artifactId>drill-common</artifactId>
+      <version>${project.version}</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-common</artifactId>
+      <version>2.7.1</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.protobuf</groupId>
+      <artifactId>protobuf-java</artifactId>
+      <version>2.5.0</version>
+    </dependency>
+    <dependency>
+      <groupId>com.carrotsearch</groupId>
+      <artifactId>hppc</artifactId>
+      <version>0.4.2</version>
+    </dependency>
+
+  </dependencies>
+
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <executions>
+          <execution> <!-- copy all templates in the same location to compile them at once -->
+            <id>copy-fmpp-resources</id>
+            <phase>initialize</phase>
+            <goals><goal>copy-resources</goal></goals>
+            <configuration>
+              <outputDirectory>${project.build.directory}/codegen</outputDirectory>
+              <resources>
+                <resource>
+                  <directory>src/main/codegen</directory>
+                  <filtering>false</filtering>
+                </resource>
+              </resources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin> <!-- generate sources from fmpp -->
+        <groupId>org.apache.drill.tools</groupId>
+        <artifactId>drill-fmpp-maven-plugin</artifactId>
+        <version>${project.version}</version>
+        <dependencies>
+          <dependency>
+            <groupId>org.freemarker</groupId>
+            <artifactId>freemarker</artifactId>
+            <version>2.3.19</version>
+          </dependency>
+        </dependencies>
+        <executions>
+          <execution>
+            <id>generate-fmpp</id>
+            <phase>generate-sources</phase>
+            <goals><goal>generate</goal></goals>
+            <configuration>
+              <config>src/main/codegen/config.fmpp</config>
+              <output>${project.build.directory}/generated-sources</output>
+              <templates>${project.build.directory}/codegen/templates</templates>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+    <pluginManagement>
+      <plugins>
+        <!--This plugin's configuration is used to store Eclipse m2e settings 
+          only. It has no influence on the Maven build itself. -->
+        <plugin>
+          <groupId>org.eclipse.m2e</groupId>
+          <artifactId>lifecycle-mapping</artifactId>
+          <version>1.0.0</version>
+          <configuration>
+            <lifecycleMappingMetadata>
+              <pluginExecutions>
+                <pluginExecution>
+                  <pluginExecutionFilter>
+                    <groupId>org.apache.drill.tools</groupId>
+                    <artifactId>drill-fmpp-maven-plugin</artifactId>
+                    <versionRange>[1.0,)</versionRange>
+                    <goals>
+                      <goal>generate</goal>
+                    </goals>
+                  </pluginExecutionFilter>
+                  <action>
+                    <execute>
+                      <runOnIncremental>false</runOnIncremental>
+                      <runOnConfiguration>true</runOnConfiguration>
+                    </execute>
+                  </action>
+                </pluginExecution>
+              </pluginExecutions>
+            </lifecycleMappingMetadata>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+
+
+</project>

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/config.fmpp
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/config.fmpp b/exec/vector/src/main/codegen/config.fmpp
new file mode 100644
index 0000000..663677c
--- /dev/null
+++ b/exec/vector/src/main/codegen/config.fmpp
@@ -0,0 +1,24 @@
+# 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.
+
+data: {
+    # TODO:  Rename to ~valueVectorModesAndTypes for clarity.
+    vv:                       tdd(../data/ValueVectorTypes.tdd),
+
+}
+freemarkerLinks: {
+    includes: includes/
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/data/ValueVectorTypes.tdd
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/data/ValueVectorTypes.tdd b/exec/vector/src/main/codegen/data/ValueVectorTypes.tdd
new file mode 100644
index 0000000..26bf02d
--- /dev/null
+++ b/exec/vector/src/main/codegen/data/ValueVectorTypes.tdd
@@ -0,0 +1,168 @@
+# 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.
+
+{
+  modes: [
+    {name: "Optional", prefix: "Nullable"},
+    {name: "Required", prefix: ""},
+    {name: "Repeated", prefix: "Repeated"}
+    ],
+  types: [
+    {
+      major: "Fixed",
+      width: 1,
+      javaType: "byte",
+      boxedType: "Byte",
+      fields: [{name: "value", type: "byte"}],
+      minor: [
+        { class: "TinyInt", valueHolder: "IntHolder" },
+        { class: "UInt1", valueHolder: "UInt1Holder" }
+      ]
+    },
+    {
+      major: "Fixed",
+      width: 2,
+      javaType: "char",
+      boxedType: "Character",
+      fields: [{name: "value", type: "char"}],
+      minor: [
+        { class: "UInt2", valueHolder: "UInt2Holder"}
+      ]
+    },    {
+      major: "Fixed",
+      width: 2,
+      javaType: "short",
+      boxedType: "Short",
+      fields: [{name: "value", type: "short"}],
+      minor: [
+        { class: "SmallInt", valueHolder: "Int2Holder"},
+      ]
+    },
+    {
+      major: "Fixed",
+      width: 4,
+      javaType: "int",
+      boxedType: "Integer",
+      fields: [{name: "value", type: "int"}],
+      minor: [
+        { class: "Int", valueHolder: "IntHolder"},
+        { class: "UInt4", valueHolder: "UInt4Holder" },
+        { class: "Float4", javaType: "float" , boxedType: "Float", fields: [{name: "value", type: "float"}]},
+        { class: "Time", javaType: "int", friendlyType: "DateTime" },
+        { class: "IntervalYear", javaType: "int", friendlyType: "Period" }
+        { class: "Decimal9", maxPrecisionDigits: 9, friendlyType: "BigDecimal", fields: [{name:"value", type:"int"}, {name: "scale", type: "int", include: false}, {name: "precision", type: "int", include: false}] },
+      ]
+    },
+    {
+      major: "Fixed",
+      width: 8,
+      javaType: "long",
+      boxedType: "Long",
+      fields: [{name: "value", type: "long"}],
+      minor: [
+        { class: "BigInt"},
+        { class: "UInt8" },
+        { class: "Float8", javaType: "double" , boxedType: "Double", fields: [{name: "value", type: "double"}], },
+        { class: "Date", javaType: "long", friendlyType: "DateTime" },
+        { class: "TimeStamp", javaType: "long", friendlyType: "DateTime" }
+        { class: "Decimal18", maxPrecisionDigits: 18, friendlyType: "BigDecimal", fields: [{name:"value", type:"long"}, {name: "scale", type: "int", include: false}, {name: "precision", type: "int", include: false}] },
+        <#--
+        { class: "Money", maxPrecisionDigits: 2, scale: 1, },
+        -->
+      ]
+    },
+    {
+      major: "Fixed",
+      width: 12,
+      javaType: "DrillBuf",
+      boxedType: "DrillBuf",
+      minor: [
+        { class: "IntervalDay", millisecondsOffset: 4, friendlyType: "Period", fields: [ {name: "days", type:"int"}, {name: "milliseconds", type:"int"}] }
+      ]
+    },
+    {
+      major: "Fixed",
+      width: 16,
+      javaType: "DrillBuf"
+      boxedType: "DrillBuf",      
+      minor: [
+        { class: "Interval", daysOffset: 4, millisecondsOffset: 8, friendlyType: "Period", fields: [ {name: "months", type: "int"}, {name: "days", type:"int"}, {name: "milliseconds", type:"int"}] }
+      ]
+    },
+    {
+      major: "Fixed",
+      width: 12,
+      javaType: "DrillBuf",
+      boxedType: "DrillBuf",
+      minor: [
+        <#--
+        { class: "TimeTZ" },
+        { class: "Interval" }
+        -->
+        { class: "Decimal28Dense", maxPrecisionDigits: 28, nDecimalDigits: 3, friendlyType: "BigDecimal", fields: [{name: "start", type: "int"}, {name: "buffer", type: "DrillBuf"}, {name: "scale", type: "int", include: false}, {name: "precision", type: "int", include: false}] }
+      ]
+    },
+    {
+      major: "Fixed",
+      width: 16,
+      javaType: "DrillBuf",
+      boxedType: "DrillBuf",
+      
+      minor: [
+        { class: "Decimal38Dense", maxPrecisionDigits: 38, nDecimalDigits: 4, friendlyType: "BigDecimal", fields: [{name: "start", type: "int"}, {name: "buffer", type: "DrillBuf"}, {name: "scale", type: "int", include: false}, {name: "precision", type: "int", include: false}] }
+      ]
+    },
+    {
+      major: "Fixed",
+      width: 24,
+      javaType: "DrillBuf",
+      boxedType: "DrillBuf",
+      minor: [
+        { class: "Decimal38Sparse", maxPrecisionDigits: 38, nDecimalDigits: 6, friendlyType: "BigDecimal", fields: [{name: "start", type: "int"}, {name: "buffer", type: "DrillBuf"}, {name: "scale", type: "int", include: false}, {name: "precision", type: "int", include: false}] }
+      ]
+    },
+    {
+      major: "Fixed",
+      width: 20,
+      javaType: "DrillBuf",
+      boxedType: "DrillBuf",
+      minor: [
+        { class: "Decimal28Sparse", maxPrecisionDigits: 28, nDecimalDigits: 5, friendlyType: "BigDecimal", fields: [{name: "start", type: "int"}, {name: "buffer", type: "DrillBuf"}, {name: "scale", type: "int", include: false}, {name: "precision", type: "int", include: false}] }
+      ]
+    },
+    {
+      major: "VarLen",
+      width: 4,
+      javaType: "int",
+      boxedType: "DrillBuf",
+      fields: [{name: "start", type: "int"}, {name: "end", type: "int"}, {name: "buffer", type: "DrillBuf"}],
+      minor: [
+        { class: "VarBinary" , friendlyType: "byte[]" },
+        { class: "VarChar" , friendlyType: "Text" },
+        { class: "Var16Char" , friendlyType: "String" }
+      ]
+    },
+    {
+      major: "Bit",
+      width: 1,
+      javaType: "int",
+      boxedType: "Integer",
+      minor: [
+        { class: "Bit" , friendlyType: "Boolean", fields: [{name: "value", type: "int"}] }
+      ]
+    }
+  ]
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/includes/license.ftl
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/includes/license.ftl b/exec/vector/src/main/codegen/includes/license.ftl
new file mode 100644
index 0000000..0455fd8
--- /dev/null
+++ b/exec/vector/src/main/codegen/includes/license.ftl
@@ -0,0 +1,18 @@
+/*******************************************************************************
+
+ * 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.
+ ******************************************************************************/
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/includes/vv_imports.ftl
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/includes/vv_imports.ftl b/exec/vector/src/main/codegen/includes/vv_imports.ftl
new file mode 100644
index 0000000..0954dcf
--- /dev/null
+++ b/exec/vector/src/main/codegen/includes/vv_imports.ftl
@@ -0,0 +1,74 @@
+<#-- 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. -->
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.ObjectArrays;
+import com.google.common.base.Charsets;
+import com.google.common.collect.ObjectArrays;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.*;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.memory.*;
+import org.apache.drill.exec.proto.SchemaDefProtos;
+import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.exec.proto.UserBitShared.DrillPBError;
+import org.apache.drill.exec.proto.UserBitShared.SerializedField;
+import org.apache.drill.exec.record.*;
+import org.apache.drill.exec.vector.*;
+import org.apache.drill.common.exceptions.*;
+import org.apache.drill.exec.exception.*;
+import org.apache.drill.exec.expr.holders.*;
+import org.apache.drill.common.expression.FieldReference;
+import org.apache.drill.common.types.TypeProtos.*;
+import org.apache.drill.common.types.Types;
+import org.apache.drill.common.util.DrillStringUtils;
+import org.apache.drill.exec.vector.complex.*;
+import org.apache.drill.exec.vector.complex.reader.*;
+import org.apache.drill.exec.vector.complex.impl.*;
+import org.apache.drill.exec.vector.complex.writer.*;
+import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
+import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter;
+import org.apache.drill.exec.util.JsonStringArrayList;
+
+import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
+
+import java.util.Arrays;
+import java.util.Random;
+import java.util.List;
+
+import java.io.Closeable;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.ByteBuffer;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.joda.time.DateTime;
+import org.joda.time.Period;
+
+import org.apache.hadoop.io.Text;
+
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/templates/AbstractFieldReader.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/AbstractFieldReader.java b/exec/vector/src/main/codegen/templates/AbstractFieldReader.java
new file mode 100644
index 0000000..2b7b305
--- /dev/null
+++ b/exec/vector/src/main/codegen/templates/AbstractFieldReader.java
@@ -0,0 +1,124 @@
+/**
+ * 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 />
+<@pp.changeOutputFile name="/org/apache/drill/exec/vector/complex/impl/AbstractFieldReader.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.drill.exec.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+@SuppressWarnings("unused")
+abstract class AbstractFieldReader extends AbstractBaseReader implements FieldReader{
+  
+  AbstractFieldReader(){
+    super();
+  }
+
+  /**
+   * Returns true if the current value of the reader is not null
+   * @return
+   */
+  public boolean isSet() {
+    return true;
+  }
+
+  <#list ["Object", "BigDecimal", "Integer", "Long", "Boolean", 
+          "Character", "DateTime", "Period", "Double", "Float",
+          "Text", "String", "Byte", "Short", "byte[]"] as friendlyType>
+  <#assign safeType=friendlyType />
+  <#if safeType=="byte[]"><#assign safeType="ByteArray" /></#if>
+  
+  public ${friendlyType} read${safeType}(int arrayIndex){
+    fail("read${safeType}(int arrayIndex)");
+    return null;
+  }
+  
+  public ${friendlyType} read${safeType}(){
+    fail("read${safeType}()");
+    return null;
+  }
+  
+  </#list>
+  
+  public void copyAsValue(MapWriter writer){
+    fail("CopyAsValue MapWriter");
+  }
+  public void copyAsField(String name, MapWriter writer){
+    fail("CopyAsField MapWriter");
+  }
+
+  public void copyAsField(String name, ListWriter writer){
+    fail("CopyAsFieldList");
+  }
+  
+  <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
+  <#assign boxedType = (minor.boxedType!type.boxedType) />
+
+  public void read(${name}Holder holder){
+    fail("${name}");
+  }
+
+  public void read(Nullable${name}Holder holder){
+    fail("${name}");
+  }
+  
+  public void read(int arrayIndex, ${name}Holder holder){
+    fail("Repeated${name}");
+  }
+  
+  public void read(int arrayIndex, Nullable${name}Holder holder){
+    fail("Repeated${name}");
+  }
+  
+  public void copyAsValue(${name}Writer writer){
+    fail("CopyAsValue${name}");
+  }
+  public void copyAsField(String name, ${name}Writer writer){
+    fail("CopyAsField${name}");
+  }
+  </#list></#list>
+  
+  public FieldReader reader(String name){
+    fail("reader(String name)");
+    return null;
+  }
+
+  public FieldReader reader(){
+    fail("reader()");
+    return null;
+    
+  }
+  
+  public int size(){
+    fail("size()");
+    return -1;
+  }
+  
+  private void fail(String name){
+    throw new IllegalArgumentException(String.format("You tried to read a [%s] type when you are using a field reader of type [%s].", name, this.getClass().getSimpleName()));
+  }
+  
+  
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/templates/AbstractFieldWriter.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/AbstractFieldWriter.java b/exec/vector/src/main/codegen/templates/AbstractFieldWriter.java
new file mode 100644
index 0000000..7ab5dce
--- /dev/null
+++ b/exec/vector/src/main/codegen/templates/AbstractFieldWriter.java
@@ -0,0 +1,147 @@
+/**
+ * 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 />
+<@pp.changeOutputFile name="/org/apache/drill/exec/vector/complex/impl/AbstractFieldWriter.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.drill.exec.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/*
+ * This class is generated using freemarker and the ${.template_name} template.
+ */
+@SuppressWarnings("unused")
+abstract class AbstractFieldWriter extends AbstractBaseWriter implements FieldWriter {
+  AbstractFieldWriter(FieldWriter parent) {
+    super(parent);
+  }
+
+  @Override
+  public void start() {
+    throw new IllegalStateException(String.format("You tried to start when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
+  }
+
+  @Override
+  public void end() {
+    throw new IllegalStateException(String.format("You tried to end when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
+  }
+
+  @Override
+  public void startList() {
+    throw new IllegalStateException(String.format("You tried to start when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
+  }
+
+  @Override
+  public void endList() {
+    throw new IllegalStateException(String.format("You tried to end when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
+  }
+
+  <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
+  <#assign fields = minor.fields!type.fields />
+  @Override
+  public void write(${name}Holder holder) {
+    fail("${name}");
+  }
+
+  public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
+    fail("${name}");
+  }
+
+  </#list></#list>
+
+  public void writeNull() {
+    fail("${name}");
+  }
+
+  /**
+   * This implementation returns {@code false}.
+   * <p>  
+   *   Must be overridden by map writers.
+   * </p>  
+   */
+  @Override
+  public boolean isEmptyMap() {
+    return false;
+  }
+
+  @Override
+  public MapWriter map() {
+    fail("Map");
+    return null;
+  }
+
+  @Override
+  public ListWriter list() {
+    fail("List");
+    return null;
+  }
+
+  @Override
+  public MapWriter map(String name) {
+    fail("Map");
+    return null;
+  }
+
+  @Override
+  public ListWriter list(String name) {
+    fail("List");
+    return null;
+  }
+
+  <#list vv.types as type><#list type.minor as minor>
+  <#assign lowerName = minor.class?uncap_first />
+  <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+  <#assign upperName = minor.class?upper_case />
+  <#assign capName = minor.class?cap_first />
+  <#if minor.class?starts_with("Decimal") >
+  public ${capName}Writer ${lowerName}(String name, int scale, int precision) {
+    fail("${capName}");
+    return null;
+  }
+  </#if>
+
+  @Override
+  public ${capName}Writer ${lowerName}(String name) {
+    fail("${capName}");
+    return null;
+  }
+
+  @Override
+  public ${capName}Writer ${lowerName}() {
+    fail("${capName}");
+    return null;
+  }
+
+  </#list></#list>
+
+  public void copyReader(FieldReader reader) {
+    fail("Copy FieldReader");
+  }
+
+  public void copyReaderToField(String name, FieldReader reader) {
+    fail("Copy FieldReader to STring");
+  }
+
+  private void fail(String name) {
+    throw new IllegalArgumentException(String.format("You tried to write a %s type when you are using a ValueWriter of type %s.", name, this.getClass().getSimpleName()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java b/exec/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
new file mode 100644
index 0000000..f2f8193
--- /dev/null
+++ b/exec/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
@@ -0,0 +1,142 @@
+/**
+ * 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.
+ */
+
+import org.apache.drill.common.types.TypeProtos.MinorType;
+
+<@pp.dropOutputFile />
+<@pp.changeOutputFile name="/org/apache/drill/exec/vector/complex/impl/AbstractPromotableFieldWriter.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.drill.exec.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/*
+ * A FieldWriter which delegates calls to another FieldWriter. The delegate FieldWriter can be promoted to a new type
+ * when necessary. Classes that extend this class are responsible for handling promotion.
+ *
+ * This class is generated using freemarker and the ${.template_name} template.
+ *
+ */
+@SuppressWarnings("unused")
+abstract class AbstractPromotableFieldWriter extends AbstractFieldWriter {
+  AbstractPromotableFieldWriter(FieldWriter parent) {
+    super(parent);
+  }
+
+  /**
+   * Retrieve the FieldWriter, promoting if it is not a FieldWriter of the specified type
+   * @param type
+   * @return
+   */
+  abstract protected FieldWriter getWriter(MinorType type);
+
+  /**
+   * Return the current FieldWriter
+   * @return
+   */
+  abstract protected FieldWriter getWriter();
+
+  @Override
+  public void start() {
+    getWriter(MinorType.MAP).start();
+  }
+
+  @Override
+  public void end() {
+    getWriter(MinorType.MAP).end();
+  }
+
+  @Override
+  public void startList() {
+    getWriter(MinorType.LIST).startList();
+  }
+
+  @Override
+  public void endList() {
+    getWriter(MinorType.LIST).endList();
+  }
+
+  <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
+  <#assign fields = minor.fields!type.fields />
+  <#if !minor.class?starts_with("Decimal") >
+  @Override
+  public void write(${name}Holder holder) {
+    getWriter(MinorType.${name?upper_case}).write(holder);
+  }
+
+  public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
+    getWriter(MinorType.${name?upper_case}).write${minor.class}(<#list fields as field>${field.name}<#if field_has_next>, </#if></#list>);
+  }
+
+  </#if>
+  </#list></#list>
+
+  public void writeNull() {
+  }
+
+  @Override
+  public MapWriter map() {
+    return getWriter(MinorType.LIST).map();
+  }
+
+  @Override
+  public ListWriter list() {
+    return getWriter(MinorType.LIST).list();
+  }
+
+  @Override
+  public MapWriter map(String name) {
+    return getWriter(MinorType.MAP).map(name);
+  }
+
+  @Override
+  public ListWriter list(String name) {
+    return getWriter(MinorType.MAP).list(name);
+  }
+
+  <#list vv.types as type><#list type.minor as minor>
+  <#assign lowerName = minor.class?uncap_first />
+  <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+  <#assign upperName = minor.class?upper_case />
+  <#assign capName = minor.class?cap_first />
+  <#if !minor.class?starts_with("Decimal") >
+
+  @Override
+  public ${capName}Writer ${lowerName}(String name) {
+    return getWriter(MinorType.MAP).${lowerName}(name);
+  }
+
+  @Override
+  public ${capName}Writer ${lowerName}() {
+    return getWriter(MinorType.LIST).${lowerName}();
+  }
+
+  </#if>
+  </#list></#list>
+
+  public void copyReader(FieldReader reader) {
+    getWriter().copyReader(reader);
+  }
+
+  public void copyReaderToField(String name, FieldReader reader) {
+    getWriter().copyReaderToField(name, reader);
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/templates/BaseReader.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/BaseReader.java b/exec/vector/src/main/codegen/templates/BaseReader.java
new file mode 100644
index 0000000..78f32f4
--- /dev/null
+++ b/exec/vector/src/main/codegen/templates/BaseReader.java
@@ -0,0 +1,73 @@
+/**
+ * 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 />
+<@pp.changeOutputFile name="/org/apache/drill/exec/vector/complex/reader/BaseReader.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.drill.exec.vector.complex.reader;
+
+<#include "/@includes/vv_imports.ftl" />
+
+
+
+@SuppressWarnings("unused")
+public interface BaseReader extends Positionable{
+  MajorType getType();
+  MaterializedField getField();
+  void reset();
+  void read(UnionHolder holder);
+  void read(int index, UnionHolder holder);
+  void copyAsValue(UnionWriter writer);
+  boolean isSet();
+
+  public interface MapReader extends BaseReader, Iterable<String>{
+    FieldReader reader(String name);
+  }
+  
+  public interface RepeatedMapReader extends MapReader{
+    boolean next();
+    int size();
+    void copyAsValue(MapWriter writer);
+  }
+  
+  public interface ListReader extends BaseReader{
+    FieldReader reader(); 
+  }
+  
+  public interface RepeatedListReader extends ListReader{
+    boolean next();
+    int size();
+    void copyAsValue(ListWriter writer);
+  }
+  
+  public interface ScalarReader extends  
+  <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first /> ${name}Reader, </#list></#list> 
+  <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first /> Repeated${name}Reader, </#list></#list>
+  BaseReader {}
+  
+  interface ComplexReader{
+    MapReader rootAsMap();
+    ListReader rootAsList();
+    boolean rootIsMap();
+    boolean ok();
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/templates/BaseWriter.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/BaseWriter.java b/exec/vector/src/main/codegen/templates/BaseWriter.java
new file mode 100644
index 0000000..8a9ea56
--- /dev/null
+++ b/exec/vector/src/main/codegen/templates/BaseWriter.java
@@ -0,0 +1,100 @@
+/**
+ * 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 />
+<@pp.changeOutputFile name="/org/apache/drill/exec/vector/complex/writer/BaseWriter.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.drill.exec.vector.complex.writer;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/*
+ * File generated from ${.template_name} using FreeMarker.
+ */
+@SuppressWarnings("unused")
+  public interface BaseWriter extends AutoCloseable, Positionable {
+  FieldWriter getParent();
+  int getValueCapacity();
+
+  public interface MapWriter extends BaseWriter {
+
+    MaterializedField getField();
+
+    /**
+     * Whether this writer is a map writer and is empty (has no children).
+     * 
+     * <p>
+     *   Intended only for use in determining whether to add dummy vector to
+     *   avoid empty (zero-column) schema, as in JsonReader.
+     * </p>
+     * 
+     */
+    boolean isEmptyMap();
+
+    <#list vv.types as type><#list type.minor as minor>
+    <#assign lowerName = minor.class?uncap_first />
+    <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+    <#assign upperName = minor.class?upper_case />
+    <#assign capName = minor.class?cap_first />
+    <#if minor.class?starts_with("Decimal") >
+    ${capName}Writer ${lowerName}(String name, int scale, int precision);
+    </#if>
+    ${capName}Writer ${lowerName}(String name);
+    </#list></#list>
+
+    void copyReaderToField(String name, FieldReader reader);
+    MapWriter map(String name);
+    ListWriter list(String name);
+    void start();
+    void end();
+  }
+
+  public interface ListWriter extends BaseWriter {
+    void startList();
+    void endList();
+    MapWriter map();
+    ListWriter list();
+    void copyReader(FieldReader reader);
+
+    <#list vv.types as type><#list type.minor as minor>
+    <#assign lowerName = minor.class?uncap_first />
+    <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+    <#assign upperName = minor.class?upper_case />
+    <#assign capName = minor.class?cap_first />
+    ${capName}Writer ${lowerName}();
+    </#list></#list>
+  }
+
+  public interface ScalarWriter extends
+  <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first /> ${name}Writer, </#list></#list> BaseWriter {}
+
+  public interface ComplexWriter {
+    void allocate();
+    void clear();
+    void copyReader(FieldReader reader);
+    MapWriter rootAsMap();
+    ListWriter rootAsList();
+
+    void setPosition(int index);
+    void setValueCount(int count);
+    void reset();
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/9969d8bd/exec/vector/src/main/codegen/templates/ComplexCopier.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/ComplexCopier.java b/exec/vector/src/main/codegen/templates/ComplexCopier.java
new file mode 100644
index 0000000..b8b7616
--- /dev/null
+++ b/exec/vector/src/main/codegen/templates/ComplexCopier.java
@@ -0,0 +1,131 @@
+/**
+ * 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 />
+<@pp.changeOutputFile name="/org/apache/drill/exec/vector/complex/impl/ComplexCopier.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.drill.exec.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/*
+ * This class is generated using freemarker and the ${.template_name} template.
+ */
+@SuppressWarnings("unused")
+public class ComplexCopier {
+
+  /**
+   * Do a deep copy of the value in input into output
+   * @param in
+   * @param out
+   */
+  public static void copy(FieldReader input, FieldWriter output) {
+    writeValue(input, output);
+  }
+
+  private static void writeValue(FieldReader reader, FieldWriter writer) {
+    final DataMode m = reader.getType().getMode();
+    final MinorType mt = reader.getType().getMinorType();
+
+    switch(m){
+    case OPTIONAL:
+    case REQUIRED:
+
+
+      switch (mt) {
+
+      case LIST:
+        writer.startList();
+        while (reader.next()) {
+          writeValue(reader.reader(), getListWriterForReader(reader.reader(), writer));
+        }
+        writer.endList();
+        break;
+      case MAP:
+        writer.start();
+        if (reader.isSet()) {
+          for(String name : reader){
+            FieldReader childReader = reader.reader(name);
+            if(childReader.isSet()){
+              writeValue(childReader, getMapWriterForReader(childReader, writer, name));
+            }
+          }
+        }
+        writer.end();
+        break;
+  <#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/>
+  <#if !minor.class?starts_with("Decimal")>
+
+      case ${name?upper_case}:
+        if (reader.isSet()) {
+          Nullable${name}Holder ${uncappedName}Holder = new Nullable${name}Holder();
+          reader.read(${uncappedName}Holder);
+          writer.write${name}(<#list fields as field>${uncappedName}Holder.${field.name}<#if field_has_next>, </#if></#list>);
+        }
+        break;
+
+  </#if>
+  </#list></#list>
+      }
+              break;
+    }
+ }
+
+  private static FieldWriter getMapWriterForReader(FieldReader reader, MapWriter writer, String name) {
+    switch (reader.getType().getMinorType()) {
+    <#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/>
+    <#if !minor.class?starts_with("Decimal")>
+    case ${name?upper_case}:
+      return (FieldWriter) writer.<#if name == "Int">integer<#else>${uncappedName}</#if>(name);
+    </#if>
+    </#list></#list>
+    case MAP:
+      return (FieldWriter) writer.map(name);
+    case LIST:
+      return (FieldWriter) writer.list(name);
+    default:
+      throw new UnsupportedOperationException(reader.getType().toString());
+    }
+  }
+
+  private static FieldWriter getListWriterForReader(FieldReader reader, ListWriter writer) {
+    switch (reader.getType().getMinorType()) {
+    <#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/>
+    <#if !minor.class?starts_with("Decimal")>
+    case ${name?upper_case}:
+    return (FieldWriter) writer.<#if name == "Int">integer<#else>${uncappedName}</#if>();
+    </#if>
+    </#list></#list>
+    case MAP:
+      return (FieldWriter) writer.map();
+    case LIST:
+      return (FieldWriter) writer.list();
+    default:
+      throw new UnsupportedOperationException(reader.getType().toString());
+    }
+  }
+}


Mime
View raw message