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();
}
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();
}
}
Aggregations