Search in sources :

Example 6 with RepeatedIntVector

use of org.apache.drill.exec.vector.RepeatedIntVector in project drill by apache.

the class TestValueVector method testRepeatedIntVector.

@Test
public void testRepeatedIntVector() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedIntHolder.TYPE);
    // Create a new value vector.
    final RepeatedIntVector vector1 = new RepeatedIntVector(field, allocator);
    // Populate the vector.
    // some tricksy primes
    final int[] values = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 27 };
    final int nRecords = 7;
    final int nElements = values.length;
    vector1.allocateNew(nRecords, nRecords * nElements);
    final RepeatedIntVector.Mutator mutator = vector1.getMutator();
    for (int recordIndex = 0; recordIndex < nRecords; ++recordIndex) {
        mutator.startNewValue(recordIndex);
        for (int elementIndex = 0; elementIndex < nElements; ++elementIndex) {
            mutator.add(recordIndex, recordIndex * values[elementIndex]);
        }
    }
    mutator.setValueCount(nRecords);
    // Verify the contents.
    final RepeatedIntVector.Accessor accessor1 = vector1.getAccessor();
    assertEquals(nRecords, accessor1.getValueCount());
    for (int recordIndex = 0; recordIndex < nRecords; ++recordIndex) {
        for (int elementIndex = 0; elementIndex < nElements; ++elementIndex) {
            final int value = accessor1.get(recordIndex, elementIndex);
            assertEquals(recordIndex * values[elementIndex], value);
        }
    }
    /* TODO(cwestin)
the interface to load has changed
    // Serialize, reify, and verify.
    final DrillBuf[] buffers1 = vector1.getBuffers(false);
    final DrillBuf buffer1 = combineBuffers(allocator, buffers1);
    final RepeatedIntVector vector2 = new RepeatedIntVector(field, allocator);
    vector2.load(nRecords, nRecords * nElements, buffer1);

    final RepeatedIntVector.Accessor accessor2 = vector2.getAccessor();
    for(int recordIndex = 0; recordIndex < nRecords; ++recordIndex) {
      for(int elementIndex = 0; elementIndex < nElements; ++elementIndex) {
        final int value = accessor2.get(recordIndex, elementIndex);
        assertEquals(accessor1.get(recordIndex,  elementIndex), value);
      }
    }
*/
    vector1.close();
/* TODO(cwestin)
    vector2.close();
    buffer1.release();
*/
}
Also used : RepeatedIntVector(org.apache.drill.exec.vector.RepeatedIntVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) VectorTest(org.apache.drill.categories.VectorTest) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Aggregations

RepeatedIntVector (org.apache.drill.exec.vector.RepeatedIntVector)6 Test (org.junit.Test)6 VectorTest (org.apache.drill.categories.VectorTest)4 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)2 ExecTest (org.apache.drill.exec.ExecTest)2 MaterializedField (org.apache.drill.exec.record.MaterializedField)2 RecordBatchSizer (org.apache.drill.exec.record.RecordBatchSizer)2 ColumnSize (org.apache.drill.exec.record.RecordBatchSizer.ColumnSize)2 VectorInitializer (org.apache.drill.exec.record.VectorInitializer)2 AllocationHint (org.apache.drill.exec.record.VectorInitializer.AllocationHint)2 ValueVector (org.apache.drill.exec.vector.ValueVector)2 VectorOverflowException (org.apache.drill.exec.vector.VectorOverflowException)2 DrillTest (org.apache.drill.test.DrillTest)2 SubOperatorTest (org.apache.drill.test.SubOperatorTest)2 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)1 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)1 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)1 BatchSchema (org.apache.drill.exec.record.BatchSchema)1 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)1 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)1