use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testTimeObjectRW.
@Test
public void testTimeObjectRW() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.TIME).buildSchema();
LocalTime v1 = LocalTime.of(12, 13, 14);
SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(v1).build();
assertEquals(1, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.TIME, colReader.extendedType());
assertTrue(reader.next());
assertEquals(v1, colReader.getTime());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testIntervalDayArray.
@Test
public void testIntervalDayArray() {
TupleMetadata schema = new SchemaBuilder().addArray("col", MinorType.INTERVALDAY).buildSchema();
Period p1 = Period.days(0);
Period p2 = Period.days(3).plusHours(4).plusMinutes(5).plusSeconds(23);
Period p3 = Period.days(999).plusHours(23).plusMinutes(59).plusSeconds(59);
SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(new Period[] {}).addSingleCol(new Period[] { p1, p2, p3 }).build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ArrayReader arrayReader = reader.array(0);
ScalarReader colReader = arrayReader.scalar();
assertEquals(ValueType.PERIOD, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, arrayReader.size());
assertTrue(reader.next());
assertEquals(3, arrayReader.size());
assertTrue(arrayReader.next());
assertEquals(p1, colReader.getPeriod().normalizedStandard());
assertTrue(arrayReader.next());
assertEquals(p2, colReader.getPeriod().normalizedStandard());
assertEquals(p2, ((Period) colReader.getObject()).normalizedStandard());
assertEquals(p2.toString(), colReader.getAsString());
assertTrue(arrayReader.next());
assertEquals(p3.normalizedStandard(), colReader.getPeriod().normalizedStandard());
assertFalse(arrayReader.next());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader 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();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testSmallIntRW.
@Test
public void testSmallIntRW() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.SMALLINT).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(0).addRow(Short.MAX_VALUE).addRow(Short.MIN_VALUE).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(Short.MAX_VALUE, colReader.getInt());
assertEquals((int) Short.MAX_VALUE, colReader.getObject());
assertEquals(Short.toString(Short.MAX_VALUE), colReader.getAsString());
assertTrue(reader.next());
assertEquals(Short.MIN_VALUE, 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 testNullableIntervalYear.
@Test
public void testNullableIntervalYear() {
TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.INTERVALYEAR).buildSchema();
Period p1 = Period.years(0);
Period p2 = Period.years(2).plusMonths(3);
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(p1).addSingleCol(null).addRow(p2).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.PERIOD, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(p1, colReader.getPeriod());
assertTrue(reader.next());
assertTrue(colReader.isNull());
assertNull(colReader.getObject());
assertEquals("null", colReader.getAsString());
assertTrue(reader.next());
assertEquals(p2, colReader.getPeriod());
assertFalse(reader.next());
rs.clear();
}
Aggregations