use of org.apache.drill.exec.vector.UInt1Vector 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.UInt1Vector in project drill by apache.
the class TestScalarAccessors method testNullableBitRW.
@Test
public void testNullableBitRW() {
TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.BIT).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(true).addSingleCol(false).addSingleCol(null).addSingleCol(1).addSingleCol(2).addSingleCol(null).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 NullableBitVector);
NullableBitVector nv = (NullableBitVector) v;
assertEquals(6, nv.getAccessor().getValueCount());
BitVector dv = nv.getValuesVector();
assertEquals(6, dv.getAccessor().getValueCount());
assertEquals(1, dv.getBuffer().writerIndex());
// Verify bits vector. (Assumes UInt1 implementation.)
UInt1Vector bv = nv.getBitsVector();
assertEquals(6, bv.getAccessor().getValueCount());
assertEquals(6, bv.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());
assertFalse(colReader.isNull());
assertTrue(reader.next());
assertEquals(false, colReader.getBoolean());
assertEquals(0, colReader.getInt());
assertFalse(colReader.isNull());
assertTrue(reader.next());
assertTrue(colReader.isNull());
assertTrue(reader.next());
assertEquals(true, colReader.getBoolean());
assertEquals(1, colReader.getInt());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(true, colReader.getBoolean());
assertEquals(1, colReader.getInt());
assertFalse(colReader.isNull());
assertTrue(reader.next());
assertTrue(colReader.isNull());
assertFalse(reader.next());
rs.clear();
}
Aggregations