use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestResultSetLoaderOverflow method testSizeLimitOnArray.
/**
* Test a row with a single array column which overflows. Verifies
* that all the fiddly bits about offset vectors and so on works
* correctly. Run this test (the simplest case) if you change anything
* about the array handling code.
*/
@Test
public void testSizeLimitOnArray() {
TupleMetadata schema = new SchemaBuilder().addArray("s", MinorType.VARCHAR).buildSchema();
ResultSetOptions options = new ResultSetOptionBuilder().rowCountLimit(ValueVector.MAX_ROW_COUNT).readerSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
// Fill batch with rows of with a single array, three values each. Tack on
// a suffix to each so we can be sure the proper data is written and moved
// to the overflow batch.
rsLoader.startBatch();
byte[] value = new byte[473];
Arrays.fill(value, (byte) 'X');
String strValue = new String(value, Charsets.UTF_8);
int valuesPerArray = 13;
int count = 0;
{
int rowSize = 0;
int totalSize = 0;
while (rootWriter.start()) {
totalSize += rowSize;
rowSize = 0;
ScalarWriter array = rootWriter.array(0).scalar();
for (int i = 0; i < valuesPerArray; i++) {
String cellValue = strValue + (count + 1) + "." + i;
array.setString(cellValue);
rowSize += cellValue.length();
}
rootWriter.save();
count++;
}
// Row count should include the overflow row.
int expectedCount = count - 1;
// Size without overflow row should fit in the vector, size
// with overflow should not.
assertTrue(totalSize <= ValueVector.MAX_BUFFER_SIZE);
assertTrue(totalSize + rowSize > ValueVector.MAX_BUFFER_SIZE);
// Result should exclude the overflow row. Last row
// should hold the last full array.
VectorContainer container = rsLoader.harvest();
BatchValidator.validate(container);
RowSet result = fixture.wrap(container);
assertEquals(expectedCount, result.rowCount());
RowSetReader reader = result.reader();
reader.setPosition(expectedCount - 1);
ArrayReader arrayReader = reader.array(0);
ScalarReader strReader = arrayReader.scalar();
assertEquals(valuesPerArray, arrayReader.size());
for (int i = 0; i < valuesPerArray; i++) {
assertTrue(arrayReader.next());
String cellValue = strValue + (count - 1) + "." + i;
assertEquals(cellValue, strReader.getString());
}
result.clear();
}
// Next batch should start with the overflow row.
// The only row in this next batch should be the whole
// array being written at the time of overflow.
{
rsLoader.startBatch();
assertEquals(1, rootWriter.rowCount());
assertEquals(count, rsLoader.totalRowCount());
VectorContainer container = rsLoader.harvest();
BatchValidator.validate(container);
RowSet result = fixture.wrap(container);
assertEquals(1, result.rowCount());
RowSetReader reader = result.reader();
reader.next();
ArrayReader arrayReader = reader.array(0);
ScalarReader strReader = arrayReader.scalar();
assertEquals(valuesPerArray, arrayReader.size());
for (int i = 0; i < valuesPerArray; i++) {
assertTrue(arrayReader.next());
String cellValue = strValue + count + "." + i;
assertEquals(cellValue, strReader.getString());
}
result.clear();
}
rsLoader.close();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testUInt2RW.
@Test
public void testUInt2RW() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.UINT2).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(0).addRow(0x7FFF).addRow(0xFFFF).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.INTEGER, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(0, colReader.getInt());
assertTrue(reader.next());
assertEquals(0x7FFF, colReader.getInt());
assertEquals(0x7FFF, colReader.getObject());
assertEquals(Integer.toString(0x7FFF), colReader.getAsString());
assertTrue(reader.next());
assertEquals(0xFFFF, colReader.getInt());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method nullableIntTester.
private void nullableIntTester(MinorType type) {
TupleMetadata schema = new SchemaBuilder().addNullable("col", type).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10).addSingleCol(null).addRow(30).build();
assertEquals(3, rs.rowCount());
// Verify vector state
VectorContainer container = rs.container();
assertEquals(1, container.getNumberOfColumns());
ValueVector v = container.getValueVector(0).getValueVector();
assertTrue(v instanceof NullableVector);
NullableVector nv = (NullableVector) v;
assertEquals(3, nv.getAccessor().getValueCount());
assertEquals(3 * BasicTypeHelper.getSize(Types.required(type)), ((BaseDataValueVector) v).getBuffer().writerIndex());
// Verify bits vector. (Assumes UInt1 implementation.)
UInt1Vector bv = (UInt1Vector) nv.getBitsVector();
assertEquals(3, bv.getAccessor().getValueCount());
assertEquals(3, bv.getBuffer().writerIndex());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(10, colReader.getInt());
assertTrue(reader.next());
assertTrue(colReader.isNull());
assertNull(colReader.getObject());
assertEquals("null", colReader.getAsString());
// Data value is undefined, may be garbage
assertTrue(reader.next());
assertEquals(30, colReader.getInt());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testBitRW.
@Test
public void testBitRW() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.BIT).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(true).addSingleCol(false).addSingleCol(0).addSingleCol(1).addSingleCol(2).addSingleCol(3).build();
assertEquals(6, rs.rowCount());
// Verify vector state
VectorContainer container = rs.container();
assertEquals(1, container.getNumberOfColumns());
ValueVector v = container.getValueVector(0).getValueVector();
assertTrue(v instanceof BitVector);
BitVector bv = (BitVector) v;
assertEquals(6, bv.getAccessor().getValueCount());
assertEquals(1, ((BaseDataValueVector) v).getBuffer().writerIndex());
// Verify using a reader
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertTrue(reader.next());
assertEquals(true, colReader.getBoolean());
assertEquals(1, colReader.getInt());
assertTrue(reader.next());
assertEquals(false, colReader.getBoolean());
assertEquals(0, colReader.getInt());
assertTrue(reader.next());
assertEquals(false, colReader.getBoolean());
assertEquals(0, colReader.getInt());
assertTrue(reader.next());
assertEquals(true, colReader.getBoolean());
assertEquals(1, colReader.getInt());
assertTrue(reader.next());
assertEquals(true, colReader.getBoolean());
assertEquals(1, colReader.getInt());
assertTrue(reader.next());
assertEquals(true, colReader.getBoolean());
assertEquals(1, colReader.getInt());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testFloatRW.
@Test
public void testFloatRW() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.FLOAT4).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(0F).addRow(Float.MAX_VALUE).addRow(Float.MIN_VALUE).addRow(100F).build();
assertEquals(4, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.FLOAT, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(0, colReader.getFloat(), 0.000001);
assertTrue(reader.next());
assertEquals(Float.MAX_VALUE, colReader.getFloat(), 0.000001);
assertEquals(Float.MAX_VALUE, (float) colReader.getObject(), 0.000001);
assertTrue(reader.next());
assertEquals(Float.MIN_VALUE, colReader.getFloat(), 0.000001);
assertTrue(reader.next());
assertEquals(100, colReader.getFloat(), 0.000001);
assertEquals("100.0", colReader.getAsString());
assertFalse(reader.next());
rs.clear();
}
Aggregations