use of org.apache.drill.exec.vector.BaseDataValueVector in project drill by axbaretto.
the class BatchValidator method validateRepeatedVector.
private void validateRepeatedVector(String name, BaseRepeatedValueVector vector) {
int dataLength = Integer.MAX_VALUE;
if (vector instanceof RepeatedVarCharVector) {
dataLength = ((RepeatedVarCharVector) vector).getOffsetVector().getValueCapacity();
} else if (vector instanceof RepeatedFixedWidthVectorLike) {
dataLength = ((BaseDataValueVector) ((BaseRepeatedValueVector) vector).getDataVector()).getBuffer().capacity();
}
int itemCount = validateOffsetVector(name + "-offsets", vector.getOffsetVector(), rowCount, dataLength);
// Special handling of repeated VarChar vectors
// The nested data vectors are not quite exactly like top-level vectors.
@SuppressWarnings("resource") ValueVector dataVector = vector.getDataVector();
if (dataVector instanceof VariableWidthVector) {
validateVariableWidthVector(name + "-data", (VariableWidthVector) dataVector, itemCount);
}
}
use of org.apache.drill.exec.vector.BaseDataValueVector 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.BaseDataValueVector 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.BaseDataValueVector in project drill by apache.
the class TestScalarAccessors method intArrayTester.
private void intArrayTester(MinorType type) {
TupleMetadata schema = new SchemaBuilder().addArray("col", type).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(new int[] {}).addSingleCol(new int[] { 0, 20, 30 }).build();
assertEquals(2, rs.rowCount());
// Verify vector state
VectorContainer container = rs.container();
assertEquals(1, container.getNumberOfColumns());
ValueVector v = container.getValueVector(0).getValueVector();
assertTrue(v instanceof RepeatedValueVector);
RepeatedValueVector rv = (RepeatedValueVector) v;
assertEquals(2, rv.getAccessor().getValueCount());
// Data vector: 3 values written above.
ValueVector vv = rv.getDataVector();
assertEquals(3, vv.getAccessor().getValueCount());
assertEquals(3 * BasicTypeHelper.getSize(Types.required(type)), ((BaseDataValueVector) vv).getBuffer().writerIndex());
// Offsets vector: one more than row count
UInt4Vector ov = rv.getOffsetVector();
assertEquals(3, ov.getAccessor().getValueCount());
assertEquals(3 * 4, ov.getBuffer().writerIndex());
RowSetReader reader = rs.reader();
ArrayReader arrayReader = reader.array(0);
ScalarReader colReader = arrayReader.scalar();
assertEquals(ValueType.INTEGER, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, arrayReader.size());
assertTrue(reader.next());
assertEquals(3, arrayReader.size());
assertTrue(arrayReader.next());
assertFalse(colReader.isNull());
assertEquals(0, colReader.getInt());
assertEquals(0, colReader.getObject());
assertEquals("0", colReader.getAsString());
assertTrue(arrayReader.next());
assertFalse(colReader.isNull());
assertEquals(20, colReader.getInt());
assertEquals(20, colReader.getObject());
assertEquals("20", colReader.getAsString());
assertTrue(arrayReader.next());
assertFalse(colReader.isNull());
assertEquals(30, colReader.getInt());
assertEquals(30, colReader.getObject());
assertEquals("30", colReader.getAsString());
assertFalse(arrayReader.next());
assertEquals("[0, 20, 30]", arrayReader.getAsString());
assertEquals(Arrays.asList(0, 20, 30), arrayReader.getObject());
assertFalse(reader.next());
rs.clear();
}
Aggregations