use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method longRWTester.
private void longRWTester(MinorType type) {
TupleMetadata schema = new SchemaBuilder().add("col", type).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(0L).addRow(Long.MAX_VALUE).addRow(Long.MIN_VALUE).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.LONG, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(0, colReader.getLong());
assertTrue(reader.next());
assertEquals(Long.MAX_VALUE, colReader.getLong());
if (colReader.extendedType() == ValueType.LONG) {
assertEquals(Long.MAX_VALUE, colReader.getObject());
assertEquals(Long.toString(Long.MAX_VALUE), colReader.getAsString());
}
assertTrue(reader.next());
assertEquals(Long.MIN_VALUE, colReader.getLong());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testDecimal18RW.
@Test
public void testDecimal18RW() {
MajorType type = MajorType.newBuilder().setMinorType(MinorType.DECIMAL18).setScale(3).setPrecision(9).setMode(DataMode.REQUIRED).build();
TupleMetadata schema = new SchemaBuilder().add("col", type).buildSchema();
BigDecimal v1 = BigDecimal.ZERO;
BigDecimal v2 = BigDecimal.valueOf(123_456_789_123_456_789L, 3);
BigDecimal v3 = BigDecimal.valueOf(999_999_999_999_999_999L, 3);
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(v1).addRow(v2).addRow(v3).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.DECIMAL, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(0, v1.compareTo(colReader.getDecimal()));
assertTrue(reader.next());
assertEquals(0, v2.compareTo(colReader.getDecimal()));
assertEquals(0, v2.compareTo((BigDecimal) colReader.getObject()));
assertEquals(v2.toString(), colReader.getAsString());
assertTrue(reader.next());
assertEquals(0, v3.compareTo(colReader.getDecimal()));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testNullableDouble.
@Test
public void testNullableDouble() {
TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.FLOAT8).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10D).addSingleCol(null).addRow(30D).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(10, colReader.getDouble(), 0.000001);
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.getDouble(), 0.000001);
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testBitResize.
/**
* The bit reader/writer are special and use the BitVector directly.
* Ensure that resize works in this special case.
*/
@Test
public void testBitResize() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.BIT).buildSchema();
RowSetBuilder rsb = new RowSetBuilder(fixture.allocator(), schema, 100);
ScalarWriter bitWriter = rsb.writer().scalar(0);
for (int i = 0; i < ValueVector.MAX_ROW_COUNT; i++) {
bitWriter.setBoolean((i % 5) == 0);
rsb.writer().save();
}
SingleRowSet rs = rsb.build();
RowSetReader reader = rs.reader();
ScalarReader bitReader = reader.scalar(0);
for (int i = 0; i < ValueVector.MAX_ROW_COUNT; i++) {
reader.next();
assertEquals((i % 5) == 0, bitReader.getBoolean());
}
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testTimeStampObjectRW.
@Test
public void testTimeStampObjectRW() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.TIMESTAMP).buildSchema();
LocalDate dt = LocalDate.of(2019, 3, 24);
LocalTime lt = LocalTime.of(12, 13, 14);
Instant v1 = LocalDateTime.of(dt, lt).toInstant(ZoneOffset.UTC);
SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(v1).build();
assertEquals(1, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.TIMESTAMP, colReader.extendedType());
assertTrue(reader.next());
assertEquals(v1, colReader.getTimestamp());
assertFalse(reader.next());
rs.clear();
}
Aggregations