use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testNullableFloat.
@Test
public void testNullableFloat() {
TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.FLOAT4).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).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.getFloat(), 0.000001);
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.getFloat(), 0.000001);
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 testVarDecimalRange.
@Test
public void testVarDecimalRange() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.VARDECIMAL, 38, 4).buildSchema();
String big = repeat("9", 34) + ".9999";
SingleRowSet rs = new RowSetBuilder(fixture.allocator(), schema).addSingleCol(dec("0")).addSingleCol(dec("-0.0000")).addSingleCol(dec("0.0001")).addSingleCol(dec("-0.0001")).addSingleCol(dec(big)).addSingleCol(dec("-" + big)).addSingleCol(dec("1234.56789")).build();
RowSetReader reader = rs.reader();
ScalarReader decReader = reader.scalar(0);
assertTrue(reader.next());
assertEquals(dec("0.0000"), decReader.getDecimal());
assertTrue(reader.next());
assertEquals(dec("0.0000"), decReader.getDecimal());
assertTrue(reader.next());
assertEquals(dec("0.0001"), decReader.getDecimal());
assertTrue(reader.next());
assertEquals(dec("-0.0001"), decReader.getDecimal());
assertTrue(reader.next());
assertEquals(dec(big), decReader.getDecimal());
assertTrue(reader.next());
assertEquals(dec("-" + big), decReader.getDecimal());
assertTrue(reader.next());
assertEquals(dec("1234.5679"), decReader.getDecimal());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method intArrayTester.
private void intArrayTester(MinorType type) {
TupleMetadata schema = new SchemaBuilder().addArray("col", type).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(new int[] {}).addSingleCol(new int[] { 0, 20, 30 }).build();
assertEquals(2, rs.rowCount());
// Verify vector state
VectorContainer container = rs.container();
assertEquals(1, container.getNumberOfColumns());
ValueVector v = container.getValueVector(0).getValueVector();
assertTrue(v instanceof RepeatedValueVector);
RepeatedValueVector rv = (RepeatedValueVector) v;
assertEquals(2, rv.getAccessor().getValueCount());
// Data vector: 3 values written above.
ValueVector vv = rv.getDataVector();
assertEquals(3, vv.getAccessor().getValueCount());
assertEquals(3 * BasicTypeHelper.getSize(Types.required(type)), ((BaseDataValueVector) vv).getBuffer().writerIndex());
// Offsets vector: one more than row count
UInt4Vector ov = rv.getOffsetVector();
assertEquals(3, ov.getAccessor().getValueCount());
assertEquals(3 * 4, ov.getBuffer().writerIndex());
RowSetReader reader = rs.reader();
ArrayReader arrayReader = reader.array(0);
ScalarReader colReader = arrayReader.scalar();
assertEquals(ValueType.INTEGER, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, arrayReader.size());
assertTrue(reader.next());
assertEquals(3, arrayReader.size());
assertTrue(arrayReader.next());
assertFalse(colReader.isNull());
assertEquals(0, colReader.getInt());
assertEquals(0, colReader.getObject());
assertEquals("0", colReader.getAsString());
assertTrue(arrayReader.next());
assertFalse(colReader.isNull());
assertEquals(20, colReader.getInt());
assertEquals(20, colReader.getObject());
assertEquals("20", colReader.getAsString());
assertTrue(arrayReader.next());
assertFalse(colReader.isNull());
assertEquals(30, colReader.getInt());
assertEquals(30, colReader.getObject());
assertEquals("30", colReader.getAsString());
assertFalse(arrayReader.next());
assertEquals("[0, 20, 30]", arrayReader.getAsString());
assertEquals(Arrays.asList(0, 20, 30), 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 testIntervalArray.
@Test
public void testIntervalArray() {
TupleMetadata schema = new SchemaBuilder().addArray("col", MinorType.INTERVAL).buildSchema();
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(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 decimalArrayTester.
private void decimalArrayTester(MinorType type, int precision) {
MajorType majorType = MajorType.newBuilder().setMinorType(type).setScale(3).setPrecision(precision).setMode(DataMode.REPEATED).build();
TupleMetadata schema = new SchemaBuilder().add("col", majorType).buildSchema();
BigDecimal v1 = BigDecimal.ZERO;
BigDecimal v2 = BigDecimal.valueOf(123_456_789, 3);
BigDecimal v3 = BigDecimal.TEN;
SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(new BigDecimal[] {}).addSingleCol(new BigDecimal[] { v1, v2, v3 }).build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ArrayReader arrayReader = reader.array(0);
ScalarReader colReader = arrayReader.scalar();
assertEquals(ValueType.DECIMAL, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, arrayReader.size());
assertTrue(reader.next());
assertEquals(3, arrayReader.size());
assertTrue(arrayReader.next());
assertEquals(0, v1.compareTo(colReader.getDecimal()));
assertTrue(arrayReader.next());
assertEquals(0, v2.compareTo(colReader.getDecimal()));
assertEquals(0, v2.compareTo((BigDecimal) colReader.getObject()));
assertEquals(v2.toString(), colReader.getAsString());
assertTrue(arrayReader.next());
assertEquals(0, v3.compareTo(colReader.getDecimal()));
assertFalse(arrayReader.next());
assertFalse(reader.next());
rs.clear();
}
Aggregations