use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testDoubleRW.
@Test
public void testDoubleRW() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.FLOAT8).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(0D).addRow(Double.MAX_VALUE).addRow(Double.MIN_VALUE).addRow(100D).build();
assertEquals(4, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.DOUBLE, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(0, colReader.getDouble(), 0.000001);
assertTrue(reader.next());
assertEquals(Double.MAX_VALUE, colReader.getDouble(), 0.000001);
assertEquals(Double.MAX_VALUE, (double) colReader.getObject(), 0.000001);
assertTrue(reader.next());
assertEquals(Double.MIN_VALUE, colReader.getDouble(), 0.000001);
assertTrue(reader.next());
assertEquals(100, colReader.getDouble(), 0.000001);
assertEquals("100.0", colReader.getAsString());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method longArrayTester.
private void longArrayTester(MinorType type) {
TupleMetadata schema = new SchemaBuilder().addArray("col", type).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(new long[] {}).addSingleCol(new long[] { 0, 20, 30 }).build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ArrayReader arrayReader = reader.array(0);
ScalarReader colReader = arrayReader.scalar();
assertEquals(ValueType.LONG, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, arrayReader.size());
assertTrue(reader.next());
assertEquals(3, arrayReader.size());
assertTrue(arrayReader.next());
assertEquals(0, colReader.getLong());
if (colReader.extendedType() == ValueType.LONG) {
assertEquals(0L, colReader.getObject());
assertEquals("0", colReader.getAsString());
}
assertTrue(arrayReader.next());
assertEquals(20, colReader.getLong());
if (colReader.extendedType() == ValueType.LONG) {
assertEquals(20L, colReader.getObject());
assertEquals("20", colReader.getAsString());
}
assertTrue(arrayReader.next());
assertEquals(30, colReader.getLong());
if (colReader.extendedType() == ValueType.LONG) {
assertEquals(30L, colReader.getObject());
assertEquals("30", colReader.getAsString());
}
assertFalse(arrayReader.next());
if (colReader.extendedType() == ValueType.LONG) {
assertEquals("[0, 20, 30]", arrayReader.getAsString());
assertEquals(Arrays.asList(0L, 20L, 30L), arrayReader.getObject());
}
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testDecimal9RW.
@Test
public void testDecimal9RW() {
MajorType type = MajorType.newBuilder().setMinorType(MinorType.DECIMAL9).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, 3);
BigDecimal v3 = BigDecimal.valueOf(999_999_999, 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 testNullableVarchar.
@Test
public void testNullableVarchar() {
TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.VARCHAR).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow("").addSingleCol(null).addRow("abcd").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 NullableVarCharVector);
NullableVarCharVector nvcv = (NullableVarCharVector) v;
assertEquals(3, nvcv.getAccessor().getValueCount());
assertEquals(2, nvcv.getMutator().getLastSet());
// Data vector: 3 values written above.
VarCharVector vv = nvcv.getValuesVector();
assertEquals(3, vv.getAccessor().getValueCount());
// Offsets vector: one more than row count
UInt4Vector ov = vv.getOffsetVector();
assertEquals(4, ov.getAccessor().getValueCount());
assertEquals(4 * 4, ov.getBuffer().writerIndex());
// Last offset and bytes buf length must agree
int lastIndex = ov.getAccessor().get(3);
assertEquals(lastIndex, vv.getBuffer().writerIndex());
// Verify using the reader
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals("", colReader.getString());
assertTrue(reader.next());
assertTrue(colReader.isNull());
assertNull(colReader.getObject());
assertEquals("null", colReader.getAsString());
assertTrue(reader.next());
assertEquals("abcd", colReader.getString());
assertEquals("abcd", colReader.getObject());
assertEquals("\"abcd\"", colReader.getAsString());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testNullableInterval.
@Test
public void testNullableInterval() {
TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.INTERVAL).buildSchema();
Period p1 = Period.years(0);
Period p2 = Period.years(7).plusMonths(8).plusDays(3).plusHours(4).plusMinutes(5).plusSeconds(23);
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().normalizedStandard());
assertTrue(reader.next());
assertTrue(colReader.isNull());
assertNull(colReader.getObject());
assertEquals("null", colReader.getAsString());
assertTrue(reader.next());
assertEquals(p2, colReader.getPeriod().normalizedStandard());
assertFalse(reader.next());
rs.clear();
}
Aggregations