use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.
the class TestScalarAccessors method testVarcharRW.
@Test
public void testVarcharRW() {
TupleMetadata schema = new SchemaBuilder().add("col", MinorType.VARCHAR).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow("").addRow("fred").addRow("barney").build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.STRING, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals("", colReader.getString());
assertTrue(reader.next());
assertEquals("fred", colReader.getString());
assertEquals("fred", colReader.getObject());
assertEquals("\"fred\"", colReader.getAsString());
assertTrue(reader.next());
assertEquals("barney", colReader.getString());
assertEquals("barney", colReader.getObject());
assertEquals("\"barney\"", colReader.getAsString());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by axbaretto.
the class TestResultSetLoaderMapArray method testDoubleNestedArray.
/**
* Test a doubly-nested arrays of maps.
*/
@Test
public void testDoubleNestedArray() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m1").add("b", MinorType.INT).addMapArray("m2").add("c", MinorType.INT).addArray("d", MinorType.VARCHAR).resumeMap().resumeSchema().buildSchema();
ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
RowSetLoader rootWriter = rsLoader.writer();
rsLoader.startBatch();
ScalarWriter aWriter = rootWriter.scalar("a");
ArrayWriter a1Writer = rootWriter.array("m1");
TupleWriter m1Writer = a1Writer.tuple();
ScalarWriter bWriter = m1Writer.scalar("b");
ArrayWriter a2Writer = m1Writer.array("m2");
TupleWriter m2Writer = a2Writer.tuple();
ScalarWriter cWriter = m2Writer.scalar("c");
ScalarWriter dWriter = m2Writer.array("d").scalar();
for (int i = 0; i < 5; i++) {
rootWriter.start();
aWriter.setInt(i);
for (int j = 0; j < 4; j++) {
int a1Key = i + 10 + j;
bWriter.setInt(a1Key);
for (int k = 0; k < 3; k++) {
int a2Key = a1Key * 10 + k;
cWriter.setInt(a2Key);
for (int l = 0; l < 2; l++) {
dWriter.setString("d-" + (a2Key * 10 + l));
}
a2Writer.save();
}
a1Writer.save();
}
rootWriter.save();
}
RowSet results = fixture.wrap(rsLoader.harvest());
RowSetReader reader = results.reader();
ScalarReader aReader = reader.scalar("a");
ArrayReader a1Reader = reader.array("m1");
TupleReader m1Reader = a1Reader.tuple();
ScalarReader bReader = m1Reader.scalar("b");
ArrayReader a2Reader = m1Reader.array("m2");
TupleReader m2Reader = a2Reader.tuple();
ScalarReader cReader = m2Reader.scalar("c");
ScalarElementReader dReader = m2Reader.elements("d");
for (int i = 0; i < 5; i++) {
reader.next();
assertEquals(i, aReader.getInt());
for (int j = 0; j < 4; j++) {
a1Reader.setPosn(j);
int a1Key = i + 10 + j;
assertEquals(a1Key, bReader.getInt());
for (int k = 0; k < 3; k++) {
a2Reader.setPosn(k);
int a2Key = a1Key * 10 + k;
assertEquals(a2Key, cReader.getInt());
for (int l = 0; l < 2; l++) {
assertEquals("d-" + (a2Key * 10 + l), dReader.getString(l));
}
}
}
}
rsLoader.close();
}
use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by axbaretto.
the class TestScalarAccessors method testNullableString.
@Test
public void testNullableString() {
BatchSchema batchSchema = new SchemaBuilder().addNullable("col", MinorType.VARCHAR).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow("").addSingleCol(null).addRow("abcd").build();
assertEquals(3, rs.rowCount());
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 axbaretto.
the class TestScalarAccessors method longRWTester.
private void longRWTester(MinorType type) {
BatchSchema batchSchema = new SchemaBuilder().add("col", type).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(0L).addRow(Long.MAX_VALUE).addRow(Long.MIN_VALUE).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.LONG, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(0, colReader.getLong());
assertTrue(reader.next());
assertEquals(Long.MAX_VALUE, colReader.getLong());
assertEquals(Long.MAX_VALUE, colReader.getObject());
assertEquals(Long.toString(Long.MAX_VALUE), colReader.getAsString());
assertTrue(reader.next());
assertEquals(Long.MIN_VALUE, 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 testStringRW.
@Test
public void testStringRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.VARCHAR).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow("").addRow("abcd").build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.STRING, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals("", colReader.getString());
assertTrue(reader.next());
assertEquals("abcd", colReader.getString());
assertEquals("abcd", colReader.getObject());
assertEquals("\"abcd\"", colReader.getAsString());
assertFalse(reader.next());
rs.clear();
}
Aggregations