use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize in project drill by apache.
the class TestRecordBatchSizer method testEmptyBatchFixedWidth.
@Test
public void testEmptyBatchFixedWidth() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.BIGINT).add("b", MinorType.FLOAT8).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(2, sizer.columns().size());
ColumnSize aColumn = sizer.columns().get("a");
/**
* stdDataSize:8, stdNetSize:8, dataSizePerEntry:0, netSizePerEntry:0,
* totalDataSize:0, totalNetSize:0, valueCount:0,
* elementCount:0, cardinality:0, isVariableWidth:false
*/
verifyColumnValues(aColumn, 8, 8, 0, 0, 0, 0, 0, 0, 0, false);
ColumnSize bColumn = sizer.columns().get("b");
verifyColumnValues(bColumn, 8, 8, 0, 0, 0, 0, 0, 0, 0, false);
// Verify memory allocation is done correctly based on std size for empty batch.
SingleRowSet empty = fixture.rowSet(schema);
VectorAccessible accessible = empty.vectorAccessible();
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);
assertEquals((Integer.highestOneBit(testRowCount) << 1), v.getValueCapacity());
v.clear();
// Allocates the same as value passed since it is already power of two.
colSize.allocateVector(v, testRowCountPowerTwo);
assertEquals(testRowCountPowerTwo, v.getValueCapacity());
v.clear();
// Allocate for max rows.
colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT);
assertEquals(ValueVector.MAX_ROW_COUNT, v.getValueCapacity());
v.clear();
// Allocate for 0 rows. should atleast do allocation for 1 row.
colSize.allocateVector(v, 0);
assertEquals(ValueVector.MIN_ROW_COUNT, v.getValueCapacity());
v.clear();
}
rows.clear();
empty.clear();
}
use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize in project drill by apache.
the class TestRecordBatchSizer method testSizerRepeatedVariableWidth.
@Test
public void testSizerRepeatedVariableWidth() {
TupleMetadata schema = new SchemaBuilder().addArray("b", MinorType.VARCHAR).buildSchema();
RowSetBuilder builder = fixture.rowSetBuilder(schema);
// size = (5*6)/2 = 15
String[] newString = new String[] { "a", "aa", "aaa", "aaaa", "aaaaa" };
for (long i = 0; i < 10; i++) {
builder.addRow((Object) (newString));
}
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 bColumn = sizer.columns().get("b");
/**
* stdDataSize:50*5, stdNetSize:50*5+4*5+4, dataSizePerEntry:(5*6)/2, netSizePerEntry:(5*6)/2+5*4+4,
* totalDataSize:(5*6)/2 * 10, totalNetSize: ((5*6)/2+5*4+4)*10, valueCount:10,
* elementCount:50, cardinality:5, isVariableWidth:true
*/
verifyColumnValues(bColumn, 250, 274, 15, 39, 150, 390, 10, 50, 5, true);
SingleRowSet empty = fixture.rowSet(schema);
VectorAccessible accessible = empty.vectorAccessible();
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 - 1);
UInt4Vector offsetVector = ((RepeatedValueVector) v).getOffsetVector();
assertEquals(Integer.highestOneBit(testRowCount) << 1, offsetVector.getValueCapacity());
VariableWidthVector vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
offsetVector = vwVector.getOffsetVector();
assertEquals((Integer.highestOneBit((testRowCount - 1) * 5) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit((testRowCount - 1) * 5 << 1) - 1, vwVector.getValueCapacity());
v.clear();
// Allocates the same as value passed since it is already power of two.
colSize.allocateVector(v, testRowCountPowerTwo);
offsetVector = ((RepeatedValueVector) v).getOffsetVector();
assertEquals((Integer.highestOneBit(testRowCountPowerTwo) << 1), offsetVector.getValueCapacity());
vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
offsetVector = vwVector.getOffsetVector();
assertEquals((Integer.highestOneBit(testRowCountPowerTwo * 5) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(testRowCountPowerTwo * 5 << 1) - 1, vwVector.getValueCapacity());
v.clear();
// Allocate for max rows.
colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT);
offsetVector = ((RepeatedValueVector) v).getOffsetVector();
assertEquals(ValueVector.MAX_ROW_COUNT << 1, offsetVector.getValueCapacity());
vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
offsetVector = vwVector.getOffsetVector();
assertEquals((Integer.highestOneBit(ValueVector.MAX_ROW_COUNT * 5) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(ValueVector.MAX_ROW_COUNT * 5 << 1) - 1, vwVector.getValueCapacity());
v.clear();
// Allocate for 0 rows. should atleast do allocation for 1 row.
colSize.allocateVector(v, 0);
offsetVector = ((RepeatedValueVector) v).getOffsetVector();
assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
offsetVector = vwVector.getOffsetVector();
assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
assertEquals(ValueVector.MIN_ROW_COUNT, vwVector.getValueCapacity());
v.clear();
}
empty.clear();
rows.clear();
}
use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize 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();
}
use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize 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();
}
use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize in project drill by axbaretto.
the class TestRecordBatchSizer method testSizerRepeatedVariableWidth.
@Test
public void testSizerRepeatedVariableWidth() {
BatchSchema schema = new SchemaBuilder().addArray("b", MinorType.VARCHAR).build();
RowSetBuilder builder = fixture.rowSetBuilder(schema);
// size = (5*6)/2 = 15
String[] newString = new String[] { "a", "aa", "aaa", "aaaa", "aaaaa" };
for (long i = 0; i < 10; i++) {
builder.addRow((Object) (newString));
}
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 bColumn = sizer.columns().get("b");
/**
* stdDataSize:50*10, stdNetSize:50*10+4*10+4, dataSizePerEntry:(5*6)/2, netSizePerEntry:(5*6)/2+5*4+4,
* totalDataSize:(5*6)/2 * 10, totalNetSize: ((5*6)/2+5*4+4)*10, valueCount:10,
* elementCount:50, estElementCountPerArray:5, isVariableWidth:true
*/
verifyColumnValues(bColumn, 500, 544, 15, 39, 150, 390, 10, 50, 5, true);
SingleRowSet empty = fixture.rowSet(schema);
VectorAccessible accessible = empty.vectorAccessible();
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 - 1);
UInt4Vector offsetVector = ((RepeatedValueVector) v).getOffsetVector();
assertEquals(Integer.highestOneBit(testRowCount) << 1, offsetVector.getValueCapacity());
VariableWidthVector vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
offsetVector = vwVector.getOffsetVector();
assertEquals((Integer.highestOneBit((testRowCount - 1) * 5) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit((testRowCount - 1) * 5 << 1) - 1, vwVector.getValueCapacity());
v.clear();
// Allocates the same as value passed since it is already power of two.
colSize.allocateVector(v, testRowCountPowerTwo);
offsetVector = ((RepeatedValueVector) v).getOffsetVector();
assertEquals((Integer.highestOneBit(testRowCountPowerTwo) << 1), offsetVector.getValueCapacity());
vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
offsetVector = vwVector.getOffsetVector();
assertEquals((Integer.highestOneBit(testRowCountPowerTwo * 5) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(testRowCountPowerTwo * 5 << 1) - 1, vwVector.getValueCapacity());
v.clear();
// Allocate for max rows.
colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT);
offsetVector = ((RepeatedValueVector) v).getOffsetVector();
assertEquals(ValueVector.MAX_ROW_COUNT << 1, offsetVector.getValueCapacity());
vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
offsetVector = vwVector.getOffsetVector();
assertEquals((Integer.highestOneBit(ValueVector.MAX_ROW_COUNT * 5) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(ValueVector.MAX_ROW_COUNT * 5 << 1) - 1, vwVector.getValueCapacity());
v.clear();
// Allocate for 0 rows. should atleast do allocation for 1 row.
colSize.allocateVector(v, 0);
offsetVector = ((RepeatedValueVector) v).getOffsetVector();
assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
offsetVector = vwVector.getOffsetVector();
assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
assertEquals(ValueVector.MIN_ROW_COUNT, vwVector.getValueCapacity());
v.clear();
}
empty.clear();
rows.clear();
}
Aggregations