use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.
the class TestScalarAccessors method longArrayTester.
private void longArrayTester(MinorType type) {
BatchSchema batchSchema = new SchemaBuilder().addArray("col", type).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new long[] {}).addSingleCol(new long[] { 0, 20, 30 }).build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarElementReader colReader = reader.elements(0);
assertEquals(ValueType.LONG, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, colReader.size());
assertTrue(reader.next());
assertEquals(3, colReader.size());
assertEquals(0, colReader.getLong(0));
assertEquals(20, colReader.getLong(1));
assertEquals(30, colReader.getLong(2));
assertEquals(0L, colReader.getObject(0));
assertEquals(20L, colReader.getObject(1));
assertEquals(30L, colReader.getObject(2));
assertEquals("0", colReader.getAsString(0));
assertEquals("20", colReader.getAsString(1));
assertEquals("30", colReader.getAsString(2));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.
the class TestScalarAccessors method nullableDecimalTester.
private void nullableDecimalTester(MinorType type, int precision) {
MajorType majorType = MajorType.newBuilder().setMinorType(type).setScale(3).setPrecision(precision).setMode(DataMode.OPTIONAL).build();
BatchSchema batchSchema = new SchemaBuilder().add("col", majorType).build();
BigDecimal v1 = BigDecimal.ZERO;
BigDecimal v2 = BigDecimal.valueOf(123_456_789, 3);
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.DECIMAL, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(0, v1.compareTo(colReader.getDecimal()));
assertTrue(reader.next());
assertTrue(colReader.isNull());
assertNull(colReader.getObject());
assertEquals("null", colReader.getAsString());
assertTrue(reader.next());
assertEquals(0, v2.compareTo(colReader.getDecimal()));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.
the class TestScalarAccessors method nullableDoubleTester.
private void nullableDoubleTester(MinorType type) {
BatchSchema batchSchema = new SchemaBuilder().addNullable("col", type).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(10F).addSingleCol(null).addRow(30F).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.test.rowSet.RowSetReader in project drill by axbaretto.
the class TestScalarAccessors method testIntervalArray.
@Test
public void testIntervalArray() {
BatchSchema batchSchema = new SchemaBuilder().addArray("col", MinorType.INTERVAL).build();
Period p1 = Period.days(0);
Period p2 = Period.years(7).plusMonths(8).plusDays(3).plusHours(4).plusMinutes(5).plusSeconds(23);
Period p3 = Period.years(9999).plusMonths(11).plusDays(365).plusHours(23).plusMinutes(59).plusSeconds(59);
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new Period[] {}).addSingleCol(new Period[] { p1, p2, p3 }).build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarElementReader colReader = reader.elements(0);
assertEquals(ValueType.PERIOD, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, colReader.size());
assertTrue(reader.next());
assertEquals(3, colReader.size());
assertEquals(p1, colReader.getPeriod(0).normalizedStandard());
assertEquals(p2, colReader.getPeriod(1).normalizedStandard());
assertEquals(p3.normalizedStandard(), colReader.getPeriod(2).normalizedStandard());
assertEquals(p2, ((Period) colReader.getObject(1)).normalizedStandard());
assertEquals(p2.toString(), colReader.getAsString(1));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.
the class TestScalarAccessors method testNullableIntervalYear.
@Test
public void testNullableIntervalYear() {
BatchSchema batchSchema = new SchemaBuilder().addNullable("col", MinorType.INTERVALYEAR).build();
Period p1 = Period.years(0);
Period p2 = Period.years(2).plusMonths(3);
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).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.getPeriod());
assertNull(colReader.getObject());
assertEquals("null", colReader.getAsString());
assertTrue(reader.next());
assertEquals(p2, colReader.getPeriod());
assertFalse(reader.next());
rs.clear();
}
Aggregations