Search in sources :

Example 1 with RepeatedIntVector

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

the class TestValueVector method testRepeatedIntVector.

@Test
public void testRepeatedIntVector() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedIntHolder.TYPE);
    // Create a new value vector.
    @SuppressWarnings("resource") 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)

Example 2 with RepeatedIntVector

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

the class TestVectorLimits method testRepeatedFixedVectorCountLimit.

/**
 * Repeated fixed vector. Using an int vector, each column array can hold
 * 256 / 4 = 64 values. We write only 10. The vector becomes full when we
 * exceed 64K items.
 */
@Test
public void testRepeatedFixedVectorCountLimit() {
    @SuppressWarnings("resource") RepeatedIntVector vector = new RepeatedIntVector(makeField(MinorType.INT, DataMode.REPEATED), fixture.allocator());
    vector.allocateNew();
    RepeatedIntVector.Mutator mutator = vector.getMutator();
    top: for (int i = 0; i < 2 * ValueVector.MAX_ROW_COUNT; i++) {
        if (!mutator.startNewValueBounded(i)) {
            assertEquals(ValueVector.MAX_ROW_COUNT, i);
        // Continue, let's check the addBounded method also
        }
        for (int j = 0; j < 10; j++) {
            try {
                mutator.addEntry(i, i * 100 + j);
            } catch (VectorOverflowException e) {
                assertEquals(ValueVector.MAX_ROW_COUNT, i);
                mutator.setValueCount(i);
                break top;
            }
        }
    }
    vector.close();
}
Also used : RepeatedIntVector(org.apache.drill.exec.vector.RepeatedIntVector) VectorOverflowException(org.apache.drill.exec.vector.VectorOverflowException) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest) DrillTest(org.apache.drill.test.DrillTest)

Example 3 with RepeatedIntVector

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

the class TestShortArrays method testSizer.

@Test
public void testSizer() {
    // Create a row set with less than one item, on
    // average, per array.
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addArray("b", MinorType.INT).buildSchema();
    RowSetBuilder builder = fixture.rowSetBuilder(schema).addRow(1, intArray(10));
    for (int i = 2; i <= 10; i++) {
        builder.addRow(i, intArray());
    }
    RowSet rows = builder.build();
    // Run the record batch sizer on the resulting batch.
    RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
    assertEquals(2, sizer.columns().size());
    ColumnSize bCol = sizer.columns().get("b");
    assertEquals(0.1, bCol.getCardinality(), 0.01);
    assertEquals(1, bCol.getElementCount());
    // Create a vector initializer using the sizer info.
    VectorInitializer vi = sizer.buildVectorInitializer();
    AllocationHint bHint = vi.hint("b");
    assertNotNull(bHint);
    assertEquals(bHint.elementCount, bCol.getCardinality(), 0.001);
    // Create a new batch, and new vector, using the sizer and
    // initializer inferred from the previous batch.
    SingleRowSet empty = fixture.rowSet(schema);
    vi.allocateBatch(empty.container(), 100);
    assertEquals(2, empty.container().getNumberOfColumns());
    ValueVector bVector = empty.container().getValueVector(1).getValueVector();
    assertTrue(bVector instanceof RepeatedIntVector);
    assertEquals(16, ((RepeatedIntVector) bVector).getDataVector().getValueCapacity());
    rows.clear();
    empty.clear();
}
Also used : AllocationHint(org.apache.drill.exec.record.VectorInitializer.AllocationHint) ValueVector(org.apache.drill.exec.vector.ValueVector) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) RecordBatchSizer(org.apache.drill.exec.record.RecordBatchSizer) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RepeatedIntVector(org.apache.drill.exec.vector.RepeatedIntVector) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) VectorInitializer(org.apache.drill.exec.record.VectorInitializer) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) AllocationHint(org.apache.drill.exec.record.VectorInitializer.AllocationHint) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 4 with RepeatedIntVector

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

the class TestShortArrays method testSizer.

@Test
public void testSizer() {
    // Create a row set with less than one item, on
    // average, per array.
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).addArray("b", MinorType.INT).build();
    RowSetBuilder builder = fixture.rowSetBuilder(schema).addRow(1, intArray(10));
    for (int i = 2; i <= 10; i++) {
        builder.addRow(i, intArray());
    }
    RowSet rows = builder.build();
    // Run the record batch sizer on the resulting batch.
    RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
    assertEquals(2, sizer.columns().size());
    ColumnSize bCol = sizer.columns().get("b");
    assertEquals(0.1, bCol.getCardinality(), 0.01);
    assertEquals(1, bCol.getElementCount());
    // Create a vector initializer using the sizer info.
    VectorInitializer vi = sizer.buildVectorInitializer();
    AllocationHint bHint = vi.hint("b");
    assertNotNull(bHint);
    assertEquals(bHint.elementCount, bCol.getCardinality(), 0.001);
    // Create a new batch, and new vector, using the sizer and
    // initializer inferred from the previous batch.
    SingleRowSet empty = fixture.rowSet(schema);
    vi.allocateBatch(empty.container(), 100);
    assertEquals(2, empty.container().getNumberOfColumns());
    @SuppressWarnings("resource") ValueVector bVector = empty.container().getValueVector(1).getValueVector();
    assertTrue(bVector instanceof RepeatedIntVector);
    assertEquals(16, ((RepeatedIntVector) bVector).getDataVector().getValueCapacity());
    rows.clear();
    empty.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RepeatedIntVector(org.apache.drill.exec.vector.RepeatedIntVector) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) VectorInitializer(org.apache.drill.exec.record.VectorInitializer) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) AllocationHint(org.apache.drill.exec.record.VectorInitializer.AllocationHint) AllocationHint(org.apache.drill.exec.record.VectorInitializer.AllocationHint) ValueVector(org.apache.drill.exec.vector.ValueVector) RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RecordBatchSizer(org.apache.drill.exec.record.RecordBatchSizer) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 5 with RepeatedIntVector

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

the class TestVectorLimits method testRepeatedFixedVectorBufferLimit.

/**
 * Repeated fixed vector. Using an int vector, each column array can hold
 * 256 / 4 = 64 values. We write 100. The vector becomes full when we
 * exceed the 16 MB size limit.
 */
@Test
public void testRepeatedFixedVectorBufferLimit() {
    @SuppressWarnings("resource") RepeatedIntVector vector = new RepeatedIntVector(makeField(MinorType.INT, DataMode.REPEATED), fixture.allocator());
    vector.allocateNew();
    RepeatedIntVector.Mutator mutator = vector.getMutator();
    top: for (int i = 0; i < 2 * ValueVector.MAX_ROW_COUNT; i++) {
        // We'll never hit the value count limit
        assertTrue(mutator.startNewValueBounded(i));
        for (int j = 0; j < 100; j++) {
            try {
                mutator.addEntry(i, i * 100 + j);
            } catch (VectorOverflowException e) {
                // We should have hit the buffer limit before the value limit.
                assertTrue(i < ValueVector.MAX_ROW_COUNT);
                mutator.setValueCount(i);
                break top;
            }
        }
    }
    vector.close();
}
Also used : RepeatedIntVector(org.apache.drill.exec.vector.RepeatedIntVector) VectorOverflowException(org.apache.drill.exec.vector.VectorOverflowException) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest) DrillTest(org.apache.drill.test.DrillTest)

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