Search in sources :

Example 16 with ColumnSize

use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize in project drill by apache.

the class TestRecordBatchSizer method testEmptyBatchVariableWidth.

@Test
public void testEmptyBatchVariableWidth() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.VARCHAR).buildSchema();
    RowSetBuilder builder = fixture.rowSetBuilder(schema);
    RowSet rows = builder.build();
    // Run the record batch sizer on the resulting batch.
    RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
    assertEquals(1, sizer.columns().size());
    ColumnSize aColumn = sizer.columns().get("a");
    /**
     * stdDataSize:50, stdNetSize:50+4, dataSizePerEntry:0, netSizePerEntry:0,
     * totalDataSize:0, totalNetSize:0, valueCount:0,
     * elementCount:0, cardinality:0, isVariableWidth:true
     */
    verifyColumnValues(aColumn, 50, 54, 0, 0, 0, 0, 0, 0, 0, true);
    // Verify memory allocation is done correctly based on std size for empty batch.
    SingleRowSet empty = fixture.rowSet(schema);
    VectorAccessible accessible = empty.vectorAccessible();
    UInt4Vector offsetVector;
    for (VectorWrapper<?> vw : accessible) {
        ValueVector v = vw.getValueVector();
        RecordBatchSizer.ColumnSize colSize = sizer.getColumn(v.getField().getName());
        // Allocates to nearest power of two
        colSize.allocateVector(v, testRowCount);
        offsetVector = ((VariableWidthVector) v).getOffsetVector();
        assertEquals((Integer.highestOneBit(testRowCount) << 1), offsetVector.getValueCapacity());
        assertEquals(Integer.highestOneBit(testRowCount << 1) - 1, v.getValueCapacity());
        v.clear();
        // Allocates the same as value passed since it is already power of two.
        // -1 is done for adjustment needed for offset vector.
        colSize.allocateVector(v, testRowCountPowerTwo - 1);
        offsetVector = ((VariableWidthVector) v).getOffsetVector();
        assertEquals(testRowCountPowerTwo, offsetVector.getValueCapacity());
        assertEquals(testRowCountPowerTwo - 1, v.getValueCapacity());
        v.clear();
        // Allocate for max rows.
        colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT - 1);
        offsetVector = ((VariableWidthVector) v).getOffsetVector();
        assertEquals(ValueVector.MAX_ROW_COUNT, offsetVector.getValueCapacity());
        assertEquals(ValueVector.MAX_ROW_COUNT - 1, v.getValueCapacity());
        v.clear();
        // Allocate for 0 rows. should atleast do allocation for 1 row.
        colSize.allocateVector(v, 0);
        offsetVector = ((VariableWidthVector) v).getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
        assertEquals(ValueVector.MIN_ROW_COUNT, v.getValueCapacity());
        v.clear();
    }
    empty.clear();
    rows.clear();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) 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) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 17 with ColumnSize

use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize in project drill by apache.

the class TestRecordBatchSizer method testEmptyVariableWidthVector.

/**
 * Test to verify that record batch sizer handles the actual empty vectors correctly. RowSetBuilder by default
 * allocates Drillbuf of 10bytes for each vector type which makes their capacity >0 and not ==0 which will be in
 * case of empty vectors.
 */
@Test
public void testEmptyVariableWidthVector() {
    final TupleMetadata schema = new SchemaBuilder().add("key", MinorType.INT).add("value", MinorType.VARCHAR).buildSchema();
    final RowSetBuilder builder = fixture.rowSetBuilder(schema);
    final RowSet rows = builder.build();
    // Release the initial bytes allocated by RowSetBuilder
    VectorAccessibleUtilities.clear(rows.container());
    try {
        // Create RecordBatchSizer for this empty container and it should not fail
        final RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
        int totalDataSize = 0;
        for (ColumnSize colSize : sizer.columns().values()) {
            totalDataSize += colSize.getTotalDataSize();
        }
        // Verify that the totalDataSize for all the columns is zero
        assertEquals(0, totalDataSize);
    } catch (Exception ex) {
        fail();
    } finally {
        rows.clear();
    }
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) 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) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ColumnSize (org.apache.drill.exec.record.RecordBatchSizer.ColumnSize)17 SubOperatorTest (org.apache.drill.test.SubOperatorTest)16 Test (org.junit.Test)16 ValueVector (org.apache.drill.exec.vector.ValueVector)14 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)12 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)10 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)10 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)10 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)10 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)10 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)6 RowSet (org.apache.drill.test.rowSet.RowSet)6 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)6 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)6 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)6 VariableWidthVector (org.apache.drill.exec.vector.VariableWidthVector)3 RecordBatchSizer (org.apache.drill.exec.record.RecordBatchSizer)2 VectorInitializer (org.apache.drill.exec.record.VectorInitializer)2 AllocationHint (org.apache.drill.exec.record.VectorInitializer.AllocationHint)2 RepeatedIntVector (org.apache.drill.exec.vector.RepeatedIntVector)2