use of org.apache.drill.test.rowSet.RowSet in project drill by axbaretto.
the class TestRecordBatchSizer method testSizerRepeatedFixedWidth.
@Test
public void testSizerRepeatedFixedWidth() {
BatchSchema schema = new SchemaBuilder().addArray("a", MinorType.BIGINT).addArray("b", MinorType.FLOAT8).build();
RowSetBuilder builder = fixture.rowSetBuilder(schema);
for (long i = 0; i < 10; i++) {
builder.addRow(new long[] { 1, 2, 3, 4, 5 }, new double[] { i * 0.1, i * 0.1, i * 0.1, i * 0.2, i * 0.3 });
}
RowSet rows = builder.build();
// Run the record batch sizer on the resulting batch.
RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
assertEquals(2, sizer.columns().size());
/**
* stdDataSize:8*10, stdNetSize:8*10+4, dataSizePerEntry:5*8, netSizePerEntry:5*8+4,
* totalDataSize:5*8*10, totalNetSize:5*8*10+5*8, valueCount:10,
* elementCount:50, estElementCountPerArray:5, isVariableWidth:false
*/
verifyColumnValues(sizer.columns().get("a"), 80, 84, 40, 44, 400, 440, 10, 50, 5, false);
verifyColumnValues(sizer.columns().get("b"), 80, 84, 40, 44, 400, 440, 10, 50, 5, false);
SingleRowSet empty = fixture.rowSet(schema);
VectorAccessible accessible = empty.vectorAccessible();
UInt4Vector offsetVector;
ValueVector dataVector;
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 = ((RepeatedValueVector) v).getOffsetVector();
assertEquals((Integer.highestOneBit(testRowCount) << 1), offsetVector.getValueCapacity());
dataVector = ((RepeatedValueVector) v).getDataVector();
assertEquals(Integer.highestOneBit((testRowCount * 5) << 1), dataVector.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 = ((RepeatedValueVector) v).getOffsetVector();
assertEquals(testRowCountPowerTwo, offsetVector.getValueCapacity());
dataVector = ((RepeatedValueVector) v).getDataVector();
assertEquals(Integer.highestOneBit((testRowCountPowerTwo - 1) * 5) << 1, dataVector.getValueCapacity());
v.clear();
// Allocate for max rows.
colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT - 1);
offsetVector = ((RepeatedValueVector) v).getOffsetVector();
assertEquals(ValueVector.MAX_ROW_COUNT, offsetVector.getValueCapacity());
dataVector = ((RepeatedValueVector) v).getDataVector();
assertEquals(Integer.highestOneBit(((ValueVector.MAX_ROW_COUNT - 1) * 5) << 1), dataVector.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());
dataVector = ((RepeatedValueVector) v).getDataVector();
assertEquals(ValueVector.MIN_ROW_COUNT, dataVector.getValueCapacity());
v.clear();
}
empty.clear();
rows.clear();
}
use of org.apache.drill.test.rowSet.RowSet in project drill by axbaretto.
the class TestRecordBatchSizer method testSizerNullableFixedWidth.
@Test
public void testSizerNullableFixedWidth() {
BatchSchema schema = new SchemaBuilder().addNullable("a", MinorType.BIGINT).addNullable("b", MinorType.FLOAT8).build();
RowSetBuilder builder = fixture.rowSetBuilder(schema);
for (long i = 0; i < 10; i++) {
builder.addRow(i, i * 0.1);
}
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");
ColumnSize bColumn = sizer.columns().get("b");
/**
* stdDataSize:8, stdNetSize:8+1, dataSizePerEntry:8, netSizePerEntry:8+1,
* totalDataSize:8*10, totalNetSize:(8+1)*10, valueCount:10,
* elementCount:10, estElementCountPerArray:1, isVariableWidth:false
*/
verifyColumnValues(aColumn, 8, 9, 8, 9, 80, 90, 10, 10, 1, false);
verifyColumnValues(bColumn, 8, 9, 8, 9, 80, 90, 10, 10, 1, false);
SingleRowSet empty = fixture.rowSet(schema);
VectorAccessible accessible = empty.vectorAccessible();
ValueVector bitVector, valueVector;
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);
bitVector = ((NullableVector) v).getBitsVector();
assertEquals((Integer.highestOneBit(testRowCount) << 1), bitVector.getValueCapacity());
valueVector = ((NullableVector) v).getValuesVector();
assertEquals(Integer.highestOneBit(testRowCount << 1), valueVector.getValueCapacity());
v.clear();
// Allocates the same as value passed since it is already power of two.
colSize.allocateVector(v, testRowCountPowerTwo);
bitVector = ((NullableVector) v).getBitsVector();
assertEquals(testRowCountPowerTwo, bitVector.getValueCapacity());
valueVector = ((NullableVector) v).getValuesVector();
assertEquals(testRowCountPowerTwo, valueVector.getValueCapacity());
v.clear();
// Allocate for max rows.
colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT);
bitVector = ((NullableVector) v).getBitsVector();
assertEquals(ValueVector.MAX_ROW_COUNT, bitVector.getValueCapacity());
valueVector = ((NullableVector) v).getValuesVector();
assertEquals(ValueVector.MAX_ROW_COUNT, valueVector.getValueCapacity());
v.clear();
// Allocate for 0 rows. should atleast do allocation for 1 row.
colSize.allocateVector(v, 0);
bitVector = ((NullableVector) v).getBitsVector();
assertEquals(ValueVector.MIN_ROW_COUNT, bitVector.getValueCapacity());
valueVector = ((NullableVector) v).getValuesVector();
assertEquals(ValueVector.MIN_ROW_COUNT, valueVector.getValueCapacity());
v.clear();
}
empty.clear();
rows.clear();
}
use of org.apache.drill.test.rowSet.RowSet in project drill by axbaretto.
the class TestRecordBatchSizer method testSizerMap.
@Test
public void testSizerMap() {
BatchSchema schema = new SchemaBuilder().addMap("map").add("key", MinorType.INT).add("value", MinorType.VARCHAR).resumeSchema().build();
RowSetBuilder builder = fixture.rowSetBuilder(schema);
for (int i = 0; i < 10; i++) {
builder.addRow((Object) (new Object[] { 10, "a" }));
}
RowSet rows = builder.build();
// Run the record batch sizer on the resulting batch.
RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
assertEquals(1, sizer.columns().size());
/**
* stdDataSize:50+4, stdNetSize:50+4+4, dataSizePerEntry:4+1,
* netSizePerEntry: 4+1+4,
* totalDataSize:5*10, totalNetSize:4*10+4*10+1*10,
* valueCount:10,
* elementCount:10, estElementCountPerArray:1, isVariableWidth:true
*/
verifyColumnValues(sizer.columns().get("map"), 54, 58, 5, 9, 50, 90, 10, 10, 1, false);
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);
MapVector mapVector = (MapVector) v;
ValueVector keyVector = mapVector.getChild("key");
ValueVector valueVector1 = mapVector.getChild("value");
assertEquals((Integer.highestOneBit(testRowCount) << 1), keyVector.getValueCapacity());
UInt4Vector offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals((Integer.highestOneBit(testRowCount) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(testRowCount << 1) - 1, valueVector1.getValueCapacity());
// Allocates the same as value passed since it is already power of two.
colSize.allocateVector(v, testRowCountPowerTwo - 1);
mapVector = (MapVector) v;
keyVector = mapVector.getChild("key");
valueVector1 = mapVector.getChild("value");
assertEquals((Integer.highestOneBit(testRowCountPowerTwo - 1) << 1), keyVector.getValueCapacity());
offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals(testRowCountPowerTwo, offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(testRowCountPowerTwo) - 1, valueVector1.getValueCapacity());
// Allocate for max rows.
colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT - 1);
mapVector = (MapVector) v;
keyVector = mapVector.getChild("key");
valueVector1 = mapVector.getChild("value");
assertEquals(ValueVector.MAX_ROW_COUNT, keyVector.getValueCapacity());
offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals(ValueVector.MAX_ROW_COUNT, offsetVector.getValueCapacity());
assertEquals(ValueVector.MAX_ROW_COUNT - 1, valueVector1.getValueCapacity());
// Allocate for 0 rows. should atleast do allocation for 1 row.
colSize.allocateVector(v, 0);
mapVector = (MapVector) v;
keyVector = mapVector.getChild("key");
valueVector1 = mapVector.getChild("value");
assertEquals(ValueVector.MIN_ROW_COUNT, keyVector.getValueCapacity());
offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
assertEquals(ValueVector.MIN_ROW_COUNT, valueVector1.getValueCapacity());
v.clear();
}
empty.clear();
rows.clear();
}
use of org.apache.drill.test.rowSet.RowSet in project drill by axbaretto.
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 BatchSchema schema = new SchemaBuilder().add("key", MinorType.INT).add("value", MinorType.VARCHAR).build();
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();
}
}
use of org.apache.drill.test.rowSet.RowSet in project drill by axbaretto.
the class TestResultSetLoaderMaps method testEmptyMapAddition.
/**
* Test adding an empty map to a loader after writing the first row.
* Then add columns in another batch. Yes, this is a bizarre condition,
* but we must check it anyway for robustness.
*/
@Test
public void testEmptyMapAddition() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
assertEquals(1, rsLoader.schemaVersion());
RowSetLoader rootWriter = rsLoader.writer();
// Start without the map. Add a map after the first row.
rsLoader.startBatch();
rootWriter.addRow(10);
int mapIndex = rootWriter.addColumn(SchemaBuilder.columnSchema("m", MinorType.MAP, DataMode.REQUIRED));
TupleWriter mapWriter = rootWriter.tuple(mapIndex);
rootWriter.addRow(20, objArray()).addRow(30, objArray());
RowSet actual = fixture.wrap(rsLoader.harvest());
assertEquals(2, rsLoader.schemaVersion());
assertEquals(3, actual.rowCount());
// Validate first batch
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").resumeSchema().buildSchema();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, objArray()).addRow(20, objArray()).addRow(30, objArray()).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
// Now add another column to the map
rsLoader.startBatch();
mapWriter.addColumn(SchemaBuilder.columnSchema("a", MinorType.VARCHAR, DataMode.REQUIRED));
rootWriter.addRow(40, objArray("fred")).addRow(50, objArray("barney"));
actual = fixture.wrap(rsLoader.harvest());
assertEquals(3, rsLoader.schemaVersion());
assertEquals(2, actual.rowCount());
// Validate first batch
expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("a", MinorType.VARCHAR).resumeSchema().buildSchema();
expected = fixture.rowSetBuilder(expectedSchema).addRow(40, objArray("fred")).addRow(50, objArray("barney")).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
rsLoader.close();
}
Aggregations