drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amansi...@apache.org
Subject [1/3] drill git commit: Test-specific column accessor implementation. Provides a simplified, unified set of access methods for value vectors specifically for wrting simple, compact unit test code.
Date Tue, 18 Apr 2017 02:05:51 GMT
Repository: drill
Updated Branches:
  refs/heads/master 72903d014 -> 381eab668


http://git-wip-us.apache.org/repos/asf/drill/blob/381eab66/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/ColumnAccessorFactory.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/ColumnAccessorFactory.java
b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/ColumnAccessorFactory.java
new file mode 100644
index 0000000..019d3be
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/ColumnAccessorFactory.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.vector.accessor.impl;
+
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.exec.vector.accessor.ColumnAccessors;
+import org.apache.drill.exec.vector.accessor.impl.AbstractArrayReader.ArrayColumnReader;
+import org.apache.drill.exec.vector.accessor.impl.AbstractArrayWriter.ArrayColumnWriter;
+
+/**
+ * Gather generated accessor classes into a set of class
+ * tables to allow rapid run-time creation of accessors.
+ * The caller is responsible for binding the accessor to
+ * a vector and a row index.
+ */
+
+public class ColumnAccessorFactory {
+
+  private static Class<? extends AbstractColumnWriter> columnWriters[][] = buildColumnWriters();
+  private static Class<? extends AbstractColumnReader> columnReaders[][] = buildColumnReaders();
+  private static Class<? extends AbstractArrayWriter> arrayWriters[] = buildArrayWriters();
+  private static Class<? extends AbstractArrayReader> arrayReaders[] = buildArrayReaders();
+
+  @SuppressWarnings("unchecked")
+  private static Class<? extends AbstractColumnWriter>[][] buildColumnWriters() {
+    int typeCount = MinorType.values().length;
+    int modeCount = DataMode.values().length;
+    Class<? extends AbstractColumnWriter> writers[][] = new Class[typeCount][];
+    for (int i = 0; i < typeCount; i++) {
+      writers[i] = new Class[modeCount];
+    }
+
+    ColumnAccessors.defineWriters(writers);
+    return writers;
+  }
+
+  @SuppressWarnings("unchecked")
+  private static Class<? extends AbstractColumnReader>[][] buildColumnReaders() {
+    int typeCount = MinorType.values().length;
+    int modeCount = DataMode.values().length;
+    Class<? extends AbstractColumnReader> readers[][] = new Class[typeCount][];
+    for (int i = 0; i < typeCount; i++) {
+      readers[i] = new Class[modeCount];
+    }
+
+    ColumnAccessors.defineReaders(readers);
+    return readers;
+  }
+
+  @SuppressWarnings("unchecked")
+  private static Class<? extends AbstractArrayWriter>[] buildArrayWriters() {
+    int typeCount = MinorType.values().length;
+    Class<? extends AbstractArrayWriter> writers[] = new Class[typeCount];
+    ColumnAccessors.defineArrayWriters(writers);
+    return writers;
+  }
+
+  @SuppressWarnings("unchecked")
+  private static Class<? extends AbstractArrayReader>[] buildArrayReaders() {
+    int typeCount = MinorType.values().length;
+    Class<? extends AbstractArrayReader> readers[] = new Class[typeCount];
+    ColumnAccessors.defineArrayReaders(readers);
+    return readers;
+  }
+
+  public static AbstractColumnWriter newWriter(MajorType type) {
+    try {
+      if (type.getMode() == DataMode.REPEATED) {
+        Class<? extends AbstractArrayWriter> writerClass = arrayWriters[type.getMinorType().ordinal()];
+        if (writerClass == null) {
+          throw new UnsupportedOperationException();
+        }
+        return new ArrayColumnWriter(writerClass.newInstance());
+      } else {
+        Class<? extends AbstractColumnWriter> writerClass = columnWriters[type.getMinorType().ordinal()][type.getMode().ordinal()];
+        if (writerClass == null) {
+          throw new UnsupportedOperationException();
+        }
+        return writerClass.newInstance();
+      }
+    } catch (InstantiationException | IllegalAccessException e) {
+      throw new IllegalStateException(e);
+    }
+  }
+
+  public static AbstractColumnReader newReader(MajorType type) {
+    try {
+      if (type.getMode() == DataMode.REPEATED) {
+        Class<? extends AbstractArrayReader> readerClass = arrayReaders[type.getMinorType().ordinal()];
+        if (readerClass == null) {
+          throw new UnsupportedOperationException();
+        }
+        return new ArrayColumnReader(readerClass.newInstance());
+      } else {
+        Class<? extends AbstractColumnReader> readerClass = columnReaders[type.getMinorType().ordinal()][type.getMode().ordinal()];
+        if (readerClass == null) {
+          throw new UnsupportedOperationException();
+        }
+        return readerClass.newInstance();
+      }
+    } catch (InstantiationException | IllegalAccessException e) {
+      throw new IllegalStateException(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/381eab66/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/TupleReaderImpl.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/TupleReaderImpl.java
b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/TupleReaderImpl.java
new file mode 100644
index 0000000..041023b
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/TupleReaderImpl.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.vector.accessor.impl;
+
+import org.apache.drill.exec.vector.accessor.ColumnReader;
+import org.apache.drill.exec.vector.accessor.TupleReader;
+
+/**
+ * Reader for a tuple (a row or a map.) Provides access to each
+ * column using either a name or a numeric index.
+ */
+
+public class TupleReaderImpl extends AbstractTupleAccessor implements TupleReader {
+
+  private final AbstractColumnReader readers[];
+
+  public TupleReaderImpl(TupleSchema schema, AbstractColumnReader readers[]) {
+    super(schema);
+    this.readers = readers;
+  }
+
+  @Override
+  public ColumnReader column(int colIndex) {
+    return readers[colIndex];
+  }
+
+  @Override
+  public ColumnReader column(String colName) {
+    int index = schema.columnIndex(colName);
+    if (index == -1) {
+      return null; }
+    return readers[index];
+  }
+
+  @Override
+  public Object get(int colIndex) {
+    ColumnReader colReader = column(colIndex);
+    if (colReader.isNull()) {
+      return null; }
+    switch (colReader.valueType()) {
+    case BYTES:
+      return colReader.getBytes();
+    case DOUBLE:
+      return colReader.getDouble();
+    case INTEGER:
+      return colReader.getInt();
+    case LONG:
+      return colReader.getLong();
+    case STRING:
+      return colReader.getString();
+    default:
+      throw new IllegalArgumentException("Unsupported type " + colReader.valueType());
+    }
+  }
+
+  @Override
+  public String getAsString(int colIndex) {
+    ColumnReader colReader = column(colIndex);
+    if (colReader.isNull()) {
+      return "null";
+    }
+    switch (colReader.valueType()) {
+    case BYTES:
+      StringBuilder buf = new StringBuilder()
+          .append("[");
+      byte value[] = colReader.getBytes();
+      int len = Math.min(value.length, 20);
+      for (int i = 0; i < len;  i++) {
+        if (i > 0) {
+          buf.append(", ");
+        }
+        buf.append((int) value[i]);
+      }
+      if (value.length > len) {
+        buf.append("...");
+      }
+      buf.append("]");
+      return buf.toString();
+    case DOUBLE:
+      return Double.toString(colReader.getDouble());
+    case INTEGER:
+      return Integer.toString(colReader.getInt());
+    case LONG:
+      return Long.toString(colReader.getLong());
+    case STRING:
+      return "\"" + colReader.getString() + "\"";
+    case DECIMAL:
+      return colReader.getDecimal().toPlainString();
+    default:
+      throw new IllegalArgumentException("Unsupported type " + colReader.valueType());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/381eab66/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/TupleWriterImpl.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/TupleWriterImpl.java
b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/TupleWriterImpl.java
new file mode 100644
index 0000000..015b099
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/TupleWriterImpl.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.vector.accessor.impl;
+
+import java.math.BigDecimal;
+
+import org.apache.drill.exec.vector.accessor.AccessorUtilities;
+import org.apache.drill.exec.vector.accessor.ArrayWriter;
+import org.apache.drill.exec.vector.accessor.ColumnAccessor.ValueType;
+import org.apache.drill.exec.vector.accessor.ColumnWriter;
+import org.apache.drill.exec.vector.accessor.TupleWriter;
+import org.joda.time.Period;
+
+/**
+ * Implementation for a writer for a tuple (a row or a map.) Provides access to each
+ * column using either a name or a numeric index.
+ */
+
+public class TupleWriterImpl extends AbstractTupleAccessor implements TupleWriter {
+
+  private final AbstractColumnWriter writers[];
+
+  public TupleWriterImpl(TupleSchema schema, AbstractColumnWriter writers[]) {
+    super(schema);
+    this.writers = writers;
+  }
+
+  public void start() {
+    for (int i = 0; i < writers.length;  i++) {
+      writers[i].start();
+    }
+  }
+
+  @Override
+  public ColumnWriter column(int colIndex) {
+    return writers[colIndex];
+  }
+
+  @Override
+  public ColumnWriter column(String colName) {
+    int index = schema.columnIndex(colName);
+    if (index == -1) {
+      return null; }
+    return writers[index];
+  }
+
+  @Override
+  public void set(int colIndex, Object value) {
+    ColumnWriter colWriter = column(colIndex);
+    if (value == null) {
+      // Arrays have no null concept, just an empty array.
+      if (colWriter.valueType() != ValueType.ARRAY) {
+        colWriter.setNull();
+      }
+    } else if (value instanceof Integer) {
+      colWriter.setInt((Integer) value);
+    } else if (value instanceof Long) {
+      colWriter.setLong((Long) value);
+    } else if (value instanceof String) {
+      colWriter.setString((String) value);
+    } else if (value instanceof BigDecimal) {
+      colWriter.setDecimal((BigDecimal) value);
+    } else if (value instanceof Period) {
+      colWriter.setPeriod((Period) value);
+    } else if (value instanceof byte[]) {
+      colWriter.setBytes((byte[]) value);
+    } else if (value instanceof Byte) {
+      colWriter.setInt((Byte) value);
+    } else if (value instanceof Short) {
+      colWriter.setInt((Short) value);
+    } else if (value instanceof Double) {
+      colWriter.setDouble((Double) value);
+    } else if (value instanceof Float) {
+      colWriter.setDouble((Float) value);
+    } else if (value.getClass().getName().startsWith("[")) {
+      setArray(colIndex, value);
+    } else {
+      throw new IllegalArgumentException("Unsupported type " +
+                value.getClass().getSimpleName() + " for column " + colIndex);
+    }
+  }
+
+  public void setArray(int colIndex, Object value) {
+    if (value == null) {
+      // Assume null means a 0-element array since Drill does
+      // not support null for the whole array.
+
+      return;
+    }
+    String objClass = value.getClass().getName();
+    if (!objClass.startsWith("[")) {
+      throw new IllegalArgumentException("Argument is not an array");
+    }
+
+    ColumnWriter colWriter = column(colIndex);
+    if (colWriter.valueType() != ValueType.ARRAY) {
+      throw new IllegalArgumentException("Column is not an array");
+    }
+
+    ArrayWriter arrayWriter = colWriter.array();
+
+    // Figure out type
+
+    char second = objClass.charAt( 1 );
+    switch ( second ) {
+    case  'B':
+      AccessorUtilities.setByteArray(arrayWriter, (byte[]) value );
+      break;
+    case  'S':
+      AccessorUtilities.setShortArray(arrayWriter, (short[]) value );
+      break;
+    case  'I':
+      AccessorUtilities.setIntArray(arrayWriter, (int[]) value );
+      break;
+    case  'J':
+      AccessorUtilities.setLongArray(arrayWriter, (long[]) value );
+      break;
+    case  'F':
+      AccessorUtilities.setFloatArray(arrayWriter, (float[]) value );
+      break;
+    case  'D':
+      AccessorUtilities.setDoubleArray(arrayWriter, (double[]) value );
+      break;
+    case  'Z':
+      AccessorUtilities.setBooleanArray(arrayWriter, (boolean[]) value );
+      break;
+    case 'L':
+     int posn = objClass.indexOf(';');
+
+      // If the array is of type Object, then we have no type info.
+
+      String memberClassName = objClass.substring( 2, posn );
+      if (memberClassName.equals(String.class.getName())) {
+        AccessorUtilities.setStringArray(arrayWriter, (String[]) value );
+      } else if (memberClassName.equals(Period.class.getName())) {
+        AccessorUtilities.setPeriodArray(arrayWriter, (Period[]) value );
+      } else if (memberClassName.equals(BigDecimal.class.getName())) {
+        AccessorUtilities.setBigDecimalArray(arrayWriter, (BigDecimal[]) value );
+      } else {
+        throw new IllegalArgumentException( "Unknown Java array type: " + memberClassName
);
+      }
+      break;
+    default:
+      throw new IllegalArgumentException( "Unknown Java array type: " + second );
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/381eab66/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/package-info.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/package-info.java
b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/package-info.java
new file mode 100644
index 0000000..92c2a16
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/impl/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/**
+ * Provides implementations of the API defined in the parent package.
+ * For the most part, code here provides base classes for the generated
+ * accessors. The code here implements the common bits, so that the
+ * generated code can be as simple as possible. While there may be some
+ * slight performance benefits from repeated code, this code is designed
+ * for testing, so simplicity is more important that the last tiny bit
+ * of performance.
+ */
+package org.apache.drill.exec.vector.accessor.impl;

http://git-wip-us.apache.org/repos/asf/drill/blob/381eab66/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/package-info.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/package-info.java
b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/package-info.java
new file mode 100644
index 0000000..f51c1a9
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/package-info.java
@@ -0,0 +1,127 @@
+/*
+ * 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.
+ */
+/**
+ * Provides a light-weight, simplified set of column readers and writers that
+ * can be plugged into a variety of row-level readers and writers. The classes
+ * and interfaces here form a framework for accessing rows and columns, but do
+ * not provide the code to build accessors for a given row batch. This code is
+ * meant to be generic, but the first (and, thus far, only) use is with the test
+ * framework for the java-exec project. That one implementation is specific to
+ * unit tests, but the accessor framework could easily be used for other
+ * purposes as well.
+ * <p>
+ * Drill provides a set of column readers and writers. Compared to those, this
+ * set:
+ * <ul>
+ * <li>Works with all Drill data types. The other set works only with repeated
+ * and nullable types.</li>
+ * <li>Is a generic interface. The other set is bound tightly to the
+ * {@link ScanBatch} class.</li>
+ * <li>Uses generic types such as <tt>getInt()</tt> for most numeric types.
The
+ * other set has accessors specific to each of the ~30 data types which Drill
+ * supports.</li>
+ * </ul>
+ * The key difference is that this set is designed for developer ease-of-use, a
+ * primary requirement for unit tests. The other set is designed to be used in
+ * machine-generated or write-once code and so can be much more complex.
+ * <p>
+ * That is, the accessors here are optimized for test code: they trade
+ * convenience for a slight decrease in speed (the performance hit comes from
+ * the extra level of indirection which hides the complex, type-specific code
+ * otherwise required.)
+ * <p>
+ * {@link ColumnReader} and {@link ColumnWriter} are the core abstractions: they
+ * provide simplified access to the myriad of Drill column types via a
+ * simplified, uniform API. {@link TupleReader} and {@link TupleWriter} provide
+ * a simplified API to rows or maps (both of which are tuples in Drill.)
+ * {@link AccessorUtilities} provides a number of data conversion tools.
+ * <p>
+ * Overview of the code structure:
+ * <dl>
+ * <dt>TupleWriter, TupleReader</dt>
+ * <dd>In relational terms, a tuple is an ordered collection of values, where
+ * the meaning of the order is provided by a schema (usually a name/type pair.)
+ * It turns out that Drill rows and maps are both tuples. The tuple classes
+ * provide the means to work with a tuple: get the schema, get a column by name
+ * or by position. Note that Drill code normally references columns by name.
+ * But, doing so is slower than access by position (index). To provide efficient
+ * code, the tuple classes assume that the implementation imposes a column
+ * ordering which can be exposed via the indexes.</dd>
+ * <dt>ColumnAccessor</dt>
+ * <dd>A generic base class for column readers and writers that provides the
+ * column data type.</dd>
+ * <dt>ColumnWriter, ColumnReader</dt>
+ * <dd>A uniform interface implemented for each column type ("major type" in
+ * Drill terminology). The scalar types: Nullable (Drill optional) and
+ * non-nullable (Drill required) fields use the same interface. Arrays (Drill
+ * repeated) are special. To handle the array aspect, even array fields use the
+ * same interface, but the <tt>getArray</tt> method returns another layer of
+ * accessor (writer or reader) specific for arrays.
+ * <p>
+ * Both the column reader and writer use a reduced set of data types to access
+ * values. Drill provides about 38 different types, but they can be mapped to a
+ * smaller set for programmatic access. For example, the signed byte, short,
+ * int; and the unsigned 8-bit, and 16-bit values can all be mapped to ints for
+ * get/set. The result is a much simpler set of get/set methods compared to the
+ * underlying set of vector types.</dt>
+ * <dt>ArrayWriter, ArrayReader
+ * <dt>
+ * <dd>The interface for the array accessors as described above. Of particular
+ * note is the difference in the form of the methods. The writer has only a
+ * <tt>setInt()</tt> method, no index. The methods assume write-only, write-once
+ * semantics: each set adds a new value. The reader, by contrast has a
+ * <tt>getInt(int index)</tt> method: read access is random.</tt>
+ * <dt>ScalarWriter<dt>
+ * <dd>Because of the form of the array writer, both the array writer and
+ * column writer have the same method signatures. To avoid repeating these
+ * methods, they are factored out into the common <tt>ScalarWriter</tt>
+ * interface.</dd>
+ * <dt>ColumnAccessors (templates)</dt>
+ * <dd>The Freemarker-based template used to generate the actual accessor
+ * implementations.</dd>
+ * <dt>ColumnAccessors (accessors)</dt>
+ * <dd>The generated accessors: one for each combination of write/read, data
+ * (minor) type and cardinality (data model).
+ * <dd>
+ * <dt>RowIndex</dt>
+ * <dd>This nested class binds the accessor to the current row position for the
+ * entire record batch. That is, you don't ask for the value of column a for row
+ * 5, then the value of column b for row 5, etc. as with the "raw" vectors.
+ * Instead, the implementation sets the row position (with, say an interator.)
+ * Then, all columns implicitly return values for the current row.
+ * <p>
+ * Different implementations of the row index handle the case of no selection
+ * vector, a selection vector 2, or a selection vector 4.</dd>
+ * <dt>VectorAccessor</dt>
+ * <dd>The readers can work with single batches or "hyper"
+ * batches. A hyper batch occurs in operators such as sort where an operator
+ * references a collection of batches as if they were one huge batch. In this
+ * case, each column consists of a "stack" of vectors. The vector accessor picks
+ * out one vector from the stack for each row. Vector accessors are used only
+ * for hyper batches; single batches work directly with the corresponding
+ * vector.
+ * <p>
+ * You can think of the (row index + vector accessor, column index) as forming a
+ * coordinate pair. The row index provides the y index (vertical position along
+ * the rows.) The vector accessor maps the row position to a vector when needed.
+ * The column index picks out the x coordinate (horizontal position along the
+ * columns.)</dt>
+ * </dl>
+ */
+
+package org.apache.drill.exec.vector.accessor;

http://git-wip-us.apache.org/repos/asf/drill/blob/381eab66/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/BaseRepeatedValueVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/BaseRepeatedValueVector.java
b/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/BaseRepeatedValueVector.java
index 1664b0a..8a54535 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/BaseRepeatedValueVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/BaseRepeatedValueVector.java
@@ -266,5 +266,9 @@ public abstract class BaseRepeatedValueVector extends BaseValueVector
implements
       final int childValueCount = valueCount == 0 ? 0 : offsets.getAccessor().get(valueCount);
       vector.getMutator().setValueCount(childValueCount);
     }
+
+    public int getInnerValueCountAt(int index) {
+      return offsets.getAccessor().get(index+1) - offsets.getAccessor().get(index);
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/381eab66/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
b/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
index 3707ff0..d930728 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
@@ -48,7 +48,6 @@ import org.apache.drill.exec.vector.complex.impl.NullReader;
 import org.apache.drill.exec.vector.complex.impl.RepeatedMapReaderImpl;
 import org.apache.drill.exec.vector.complex.reader.FieldReader;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 
 public class RepeatedMapVector extends AbstractMapVector


Mime
View raw message