use of org.apache.drill.exec.record.VectorInitializer.AllocationHint 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.VectorInitializer.AllocationHint 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();
}
Aggregations