use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by axbaretto.
the class TestScalarAccessors method testDoubleRW.
@Test
public void testDoubleRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.FLOAT8).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).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 axbaretto.
the class TestScalarAccessors method testDecimal18RW.
@Test
public void testDecimal18RW() {
MajorType type = MajorType.newBuilder().setMinorType(MinorType.DECIMAL18).setScale(3).setPrecision(9).setMode(DataMode.REQUIRED).build();
BatchSchema batchSchema = new SchemaBuilder().add("col", type).build();
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(batchSchema).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 axbaretto.
the class TestScalarAccessors method nullableIntTester.
private void nullableIntTester(MinorType type) {
BatchSchema batchSchema = new SchemaBuilder().addNullable("col", type).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(10).addSingleCol(null).addRow(30).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(10, colReader.getInt());
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.getInt());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by axbaretto.
the class TestScalarAccessors method testDecimal9RW.
@Test
public void testDecimal9RW() {
MajorType type = MajorType.newBuilder().setMinorType(MinorType.DECIMAL9).setScale(3).setPrecision(9).setMode(DataMode.REQUIRED).build();
BatchSchema batchSchema = new SchemaBuilder().add("col", type).build();
BigDecimal v1 = BigDecimal.ZERO;
BigDecimal v2 = BigDecimal.valueOf(123_456_789, 3);
BigDecimal v3 = BigDecimal.valueOf(999_999_999, 3);
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).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 axbaretto.
the class RowSetTest method testMapStructure.
/**
* Test a simple map structure at the top level of a row.
*
* @throws VectorOverflowException should never occur
*/
@Test
public void testMapStructure() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").addArray("b", MinorType.INT).resumeSchema().buildSchema();
ExtendableRowSet rowSet = fixture.rowSet(schema);
RowSetWriter writer = rowSet.writer();
// Map and Int
// Test Invariants
assertEquals(ObjectType.SCALAR, writer.column("a").type());
assertEquals(ObjectType.SCALAR, writer.column(0).type());
assertEquals(ObjectType.TUPLE, writer.column("m").type());
assertEquals(ObjectType.TUPLE, writer.column(1).type());
assertSame(writer.column(1).tuple(), writer.tuple(1));
TupleWriter mapWriter = writer.column(1).tuple();
assertEquals(ObjectType.SCALAR, mapWriter.column("b").array().entry().type());
assertEquals(ObjectType.SCALAR, mapWriter.column("b").array().entryType());
ScalarWriter aWriter = writer.column("a").scalar();
ScalarWriter bWriter = writer.column("m").tuple().column("b").array().entry().scalar();
assertSame(bWriter, writer.tuple(1).array(0).scalar());
assertEquals(ValueType.INTEGER, bWriter.valueType());
try {
writer.column(1).scalar();
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
try {
writer.column(1).array();
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
// Write data
aWriter.setInt(10);
bWriter.setInt(11);
bWriter.setInt(12);
writer.save();
aWriter.setInt(20);
bWriter.setInt(21);
bWriter.setInt(22);
writer.save();
aWriter.setInt(30);
bWriter.setInt(31);
bWriter.setInt(32);
writer.save();
// Finish the row set and get a reader.
SingleRowSet actual = writer.done();
RowSetReader reader = actual.reader();
assertEquals(ObjectType.SCALAR, reader.column("a").type());
assertEquals(ObjectType.SCALAR, reader.column(0).type());
assertEquals(ObjectType.TUPLE, reader.column("m").type());
assertEquals(ObjectType.TUPLE, reader.column(1).type());
assertSame(reader.column(1).tuple(), reader.tuple(1));
ScalarReader aReader = reader.column(0).scalar();
TupleReader mReader = reader.column(1).tuple();
assertEquals(ObjectType.SCALAR, mReader.column("b").array().entryType());
ScalarElementReader bReader = mReader.column(0).elements();
assertEquals(ValueType.INTEGER, bReader.valueType());
assertTrue(reader.next());
assertEquals(10, aReader.getInt());
assertEquals(11, bReader.getInt(0));
assertEquals(12, bReader.getInt(1));
assertTrue(reader.next());
assertEquals(20, aReader.getInt());
assertEquals(21, bReader.getInt(0));
assertEquals(22, bReader.getInt(1));
assertTrue(reader.next());
assertEquals(30, aReader.getInt());
assertEquals(31, bReader.getInt(0));
assertEquals(32, bReader.getInt(1));
assertFalse(reader.next());
// Verify that the map accessor's value count was set.
@SuppressWarnings("resource") MapVector mapVector = (MapVector) actual.container().getValueVector(1).getValueVector();
assertEquals(actual.rowCount(), mapVector.getAccessor().getValueCount());
SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray(intArray(11, 12))).addRow(20, objArray(intArray(21, 22))).addRow(30, objArray(intArray(31, 32))).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
}
Aggregations