use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestFillEmpties method dofillEmptiesRepeated.
private void dofillEmptiesRepeated(MajorType majorType) {
TupleMetadata schema = new SchemaBuilder().add("a", majorType).buildSchema();
ExtendableRowSet rs = fixture.rowSet(schema);
RowSetWriter writer = rs.writer();
ScalarWriter colWriter = writer.array(0).scalar();
ValueType valueType = colWriter.valueType();
for (int i = 0; i < ROW_COUNT; i++) {
if (i % 5 == 0) {
// Write two values so we can exercise a bit of the array logic.
colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i));
colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i + 1));
}
writer.save();
}
SingleRowSet result = writer.done();
RowSetReader reader = result.reader();
ScalarElementReader colReader = reader.array(0).elements();
for (int i = 0; i < ROW_COUNT; i++) {
assertTrue(reader.next());
if (i % 5 != 0) {
// Empty arrays are defined to be the same as a zero-length array.
assertEquals(0, colReader.size());
} else {
for (int j = 0; j < 2; j++) {
Object actual = colReader.getObject(j);
Object expected = RowSetUtilities.testDataFromInt(valueType, majorType, i + j);
RowSetUtilities.assertEqualValues(majorType.toString().replace('\n', ' ') + "[" + i + "][" + j + "]", valueType, expected, actual);
}
}
}
result.clear();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestRecordBatchSizer method testSizerNullableVariableWidth.
@Test
public void testSizerNullableVariableWidth() {
BatchSchema schema = new SchemaBuilder().addNullable("b", MinorType.VARCHAR).build();
RowSetBuilder builder = fixture.rowSetBuilder(schema);
StringBuilder stringBuilder = new StringBuilder();
for (long i = 0; i < 10; i++) {
stringBuilder.append("a");
builder.addRow((Object) stringBuilder.toString());
}
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, stdNetSize:50+4+1, dataSizePerEntry:ceil((10*11)/2)*10),
* netSizePerEntry: dataSizePerEntry+4+1,
* totalDataSize:(10*11)/2, totalNetSize: (10*11)/2 + (4*10) + (1*10),
* valueCount:10,
* elementCount:10, estElementCountPerArray:1, isVariableWidth:true
*/
verifyColumnValues(sizer.columns().get("b"), 50, 55, 6, 11, 55, 105, 10, 10, 1, true);
SingleRowSet empty = fixture.rowSet(schema);
VectorAccessible accessible = empty.vectorAccessible();
ValueVector bitVector, valueVector;
VariableWidthVector vwVector;
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);
bitVector = ((NullableVector) v).getBitsVector();
assertEquals((Integer.highestOneBit(testRowCount) << 1), bitVector.getValueCapacity());
vwVector = (VariableWidthVector) ((NullableVector) v).getValuesVector();
offsetVector = vwVector.getOffsetVector();
assertEquals((Integer.highestOneBit(testRowCount) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(testRowCount << 1) - 1, vwVector.getValueCapacity());
// Allocates the same as value passed since it is already power of two.
colSize.allocateVector(v, testRowCountPowerTwo - 1);
bitVector = ((NullableVector) v).getBitsVector();
assertEquals(Integer.highestOneBit(testRowCountPowerTwo), bitVector.getValueCapacity());
vwVector = (VariableWidthVector) ((NullableVector) v).getValuesVector();
offsetVector = vwVector.getOffsetVector();
assertEquals(testRowCountPowerTwo, offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(testRowCountPowerTwo) - 1, vwVector.getValueCapacity());
// Allocate for max rows.
colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT - 1);
bitVector = ((NullableVector) v).getBitsVector();
assertEquals((Integer.highestOneBit(ValueVector.MAX_ROW_COUNT)), bitVector.getValueCapacity());
vwVector = (VariableWidthVector) ((NullableVector) v).getValuesVector();
offsetVector = vwVector.getOffsetVector();
assertEquals(ValueVector.MAX_ROW_COUNT, offsetVector.getValueCapacity());
assertEquals(ValueVector.MAX_ROW_COUNT - 1, vwVector.getValueCapacity());
// Allocate for 0 rows. should atleast do allocation for 1 row.
colSize.allocateVector(v, 0);
bitVector = ((NullableVector) v).getBitsVector();
assertEquals((Integer.highestOneBit(ValueVector.MIN_ROW_COUNT)), bitVector.getValueCapacity());
vwVector = (VariableWidthVector) ((NullableVector) v).getValuesVector();
offsetVector = vwVector.getOffsetVector();
assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
assertEquals(ValueVector.MIN_ROW_COUNT, vwVector.getValueCapacity());
}
empty.clear();
rows.clear();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestRecordBatchSizer method testSizerNestedMap.
@Test
public void testSizerNestedMap() {
BatchSchema schema = new SchemaBuilder().addMap("map").add("key", MinorType.INT).add("value", MinorType.VARCHAR).addMap("childMap").add("childKey", MinorType.INT).add("childValue", MinorType.VARCHAR).resumeMap().resumeSchema().build();
RowSetBuilder builder = fixture.rowSetBuilder(schema);
for (int i = 0; i < 10; i++) {
builder.addRow((Object) (new Object[] { 10, "a", new Object[] { 5, "b" } }));
}
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)*2, stdNetSize:(50+4)*2+4+4, dataSizePerEntry:(4+1)*2,
* netSizePerEntry: 4*2+1*2+4*2,
* totalDataSize:5*2*10, totalNetSize:netSizePerEntry*2,
* valueCount:10,
* elementCount:10, estElementCountPerArray:1, isVariableWidth:true
*/
verifyColumnValues(sizer.columns().get("map"), 108, 116, 10, 18, 100, 180, 10, 10, 1, false);
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);
MapVector mapVector = (MapVector) v;
ValueVector keyVector = mapVector.getChild("key");
ValueVector valueVector1 = mapVector.getChild("value");
assertEquals((Integer.highestOneBit(testRowCount) << 1), keyVector.getValueCapacity());
offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals((Integer.highestOneBit(testRowCount) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(testRowCount << 1) - 1, valueVector1.getValueCapacity());
MapVector childMapVector = (MapVector) mapVector.getChild("childMap");
ValueVector childKeyVector = childMapVector.getChild("childKey");
ValueVector childValueVector1 = childMapVector.getChild("childValue");
assertEquals((Integer.highestOneBit(testRowCount) << 1), childKeyVector.getValueCapacity());
offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals((Integer.highestOneBit(testRowCount) << 1), offsetVector.getValueCapacity());
assertEquals(Integer.highestOneBit(testRowCount << 1) - 1, childValueVector1.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(testRowCountPowerTwo, keyVector.getValueCapacity());
offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals(testRowCountPowerTwo, offsetVector.getValueCapacity());
assertEquals(testRowCountPowerTwo - 1, valueVector1.getValueCapacity());
childMapVector = (MapVector) mapVector.getChild("childMap");
childKeyVector = childMapVector.getChild("childKey");
childValueVector1 = childMapVector.getChild("childValue");
assertEquals(testRowCountPowerTwo, childKeyVector.getValueCapacity());
offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals(testRowCountPowerTwo, offsetVector.getValueCapacity());
assertEquals(testRowCountPowerTwo - 1, childValueVector1.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());
childMapVector = (MapVector) mapVector.getChild("childMap");
childKeyVector = childMapVector.getChild("childKey");
childValueVector1 = childMapVector.getChild("childValue");
assertEquals(ValueVector.MAX_ROW_COUNT, childKeyVector.getValueCapacity());
offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals(ValueVector.MAX_ROW_COUNT, offsetVector.getValueCapacity());
assertEquals(ValueVector.MAX_ROW_COUNT - 1, childValueVector1.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());
childMapVector = (MapVector) mapVector.getChild("childMap");
childKeyVector = childMapVector.getChild("childKey");
childValueVector1 = childMapVector.getChild("childValue");
assertEquals(ValueVector.MIN_ROW_COUNT, childKeyVector.getValueCapacity());
offsetVector = ((VariableWidthVector) valueVector1).getOffsetVector();
assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
assertEquals(ValueVector.MIN_ROW_COUNT, childValueVector1.getValueCapacity());
v.clear();
}
empty.clear();
rows.clear();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet 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();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestRecordBatchSizer method testSizerFixedWidth.
@Test
public void testSizerFixedWidth() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.BIGINT).add("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");
/**
* stdDataSize:8, stdNetSize:8, dataSizePerEntry:8, netSizePerEntry:8,
* totalDataSize:8*10, totalNetSize:8*10, valueCount:10,
* elementCount:10, estElementCountPerArray:1, isVariableWidth:false
*/
verifyColumnValues(aColumn, 8, 8, 8, 8, 80, 80, 10, 10, 1, false);
ColumnSize bColumn = sizer.columns().get("b");
verifyColumnValues(bColumn, 8, 8, 8, 8, 80, 80, 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);
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();
}
Aggregations