use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize 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();
}
use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize in project drill by axbaretto.
the class TestRecordBatchSizer method testSizerVariableWidth.
@Test
public void testSizerVariableWidth() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
RowSetBuilder builder = fixture.rowSetBuilder(schema);
StringBuilder stringBuilder = new StringBuilder();
// a, aa, aaa, ... aaaaaaaaaa. totalSize = (10*11)/2 = 55
for (long i = 0; i < 10; i++) {
stringBuilder.append("a");
builder.addRow(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());
ColumnSize aColumn = sizer.columns().get("a");
/**
* stdDataSize:50, stdNetSize:50+4, dataSizePerEntry:8, netSizePerEntry:8,
* totalDataSize:(10*11)/2, totalNetSize:(10*11)/2 + 4*10, valueCount:10,
* elementCount:10, estElementCountPerArray:1, isVariableWidth:true
*/
verifyColumnValues(aColumn, 50, 54, 6, 10, 55, 95, 10, 10, 1, true);
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 RecordBatchStats method printRecordBatchStats.
/**
* Constructs record batch statistics for the input record batch
*
* @param statsId instance identifier
* @param ioType whether a record batch is an input or/and output
* @param sourceId optional source identifier for scanners
* @param batchSizer contains batch sizing information
* @param verbose whether to include fine-grained stats
*
* @return a string containing the record batch statistics
*/
private static String printRecordBatchStats(String statsId, RecordBatchIOType ioType, String sourceId, RecordBatchSizer batchSizer, boolean verbose) {
final StringBuilder msg = new StringBuilder();
msg.append(BATCH_STATS_PREFIX);
msg.append(" Operator: {");
msg.append(statsId);
if (sourceId != null) {
msg.append(':');
msg.append(sourceId);
}
msg.append("}, IO Type: {");
msg.append(toString(ioType));
msg.append("}, Batch size: {");
msg.append(" Records: ");
msg.append(batchSizer.rowCount());
msg.append(", Total size: ");
msg.append(batchSizer.getActualSize());
msg.append(", Data size: ");
msg.append(batchSizer.getNetBatchSize());
msg.append(", Gross row width: ");
msg.append(batchSizer.getGrossRowWidth());
msg.append(", Net row width: ");
msg.append(batchSizer.getNetRowWidth());
msg.append(", Density: ");
msg.append(batchSizer.getAvgDensity());
msg.append("% }\n");
if (verbose) {
msg.append("Batch schema & sizes: {\n");
for (ColumnSize colSize : batchSizer.columns().values()) {
msg.append(BATCH_STATS_PREFIX);
msg.append("\t");
msg.append(statsId);
msg.append('\t');
msg.append(colSize.toString());
msg.append(" }\n");
}
msg.append(" }\n");
}
return msg.toString();
}
use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize in project drill by apache.
the class TestRecordBatchSizer method testSizerFixedWidth.
@Test
public void testSizerFixedWidth() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.BIGINT).add("b", MinorType.FLOAT8).buildSchema();
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, cardinality: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();
}
use of org.apache.drill.exec.record.RecordBatchSizer.ColumnSize in project drill by apache.
the class TestRecordBatchSizer method testEmptyBatchNullableFixedWidth.
@Test
public void testEmptyBatchNullableFixedWidth() {
TupleMetadata schema = new SchemaBuilder().addNullable("a", MinorType.BIGINT).addNullable("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");
ColumnSize bColumn = sizer.columns().get("b");
/**
* stdDataSize:8, stdNetSize:8+1, dataSizePerEntry:0, netSizePerEntry:0,
* totalDataSize:0, totalNetSize:0, valueCount:0,
* elementCount:0, cardinality:0, isVariableWidth:false
*/
verifyColumnValues(aColumn, 8, 9, 0, 0, 0, 0, 0, 0, 0, false);
verifyColumnValues(bColumn, 8, 9, 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();
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();
}
Aggregations