use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by axbaretto.
the class TestScalarAccessors method nullableLongTester.
private void nullableLongTester(MinorType type) {
BatchSchema batchSchema = new SchemaBuilder().addNullable("col", type).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(10L).addSingleCol(null).addRow(30L).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(10, colReader.getLong());
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.getLong());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by axbaretto.
the class TestScalarAccessors method testIntervalDayRW.
@Test
public void testIntervalDayRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.INTERVALDAY).build();
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(batchSchema).addRow(p1).addRow(p2).addRow(p3).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());
// The normalizedStandard() call is a hack. See DRILL-5689.
assertEquals(p1, colReader.getPeriod().normalizedStandard());
assertTrue(reader.next());
assertEquals(p2, colReader.getPeriod().normalizedStandard());
assertEquals(p2, ((Period) colReader.getObject()).normalizedStandard());
assertEquals(p2.toString(), colReader.getAsString());
assertTrue(reader.next());
assertEquals(p3.normalizedStandard(), colReader.getPeriod().normalizedStandard());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by axbaretto.
the class TestScalarAccessors method testTinyIntRW.
@Test
public void testTinyIntRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.TINYINT).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(0).addRow(Byte.MAX_VALUE).addRow(Byte.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(Byte.MAX_VALUE, colReader.getInt());
assertEquals((int) Byte.MAX_VALUE, colReader.getObject());
assertEquals(Byte.toString(Byte.MAX_VALUE), colReader.getAsString());
assertTrue(reader.next());
assertEquals(Byte.MIN_VALUE, colReader.getInt());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by axbaretto.
the class TestScalarAccessors method testNullableVarBinary.
@Test
public void testNullableVarBinary() {
BatchSchema batchSchema = new SchemaBuilder().addNullable("col", MinorType.VARBINARY).build();
byte[] v1 = new byte[] {};
byte[] v2 = new byte[] { (byte) 0x00, (byte) 0x7f, (byte) 0x80, (byte) 0xFF };
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(v1).addSingleCol(null).addRow(v2).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.BYTES, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertTrue(Arrays.equals(v1, colReader.getBytes()));
assertTrue(reader.next());
assertTrue(colReader.isNull());
assertNull(colReader.getObject());
assertEquals("null", colReader.getAsString());
assertTrue(reader.next());
assertTrue(Arrays.equals(v2, colReader.getBytes()));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by axbaretto.
the class TestScalarAccessors method testSmallIntRW.
@Test
public void testSmallIntRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.SMALLINT).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).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();
}
Aggregations