use of org.apache.drill.test.rowSet.RowSet.RowSetReader in project drill by apache.
the class QueryBuilder method singletonString.
/**
* Run the query that is expected to return (at least) one row
* with the only (or first) column returning a string value.
* The value may be null, in which case a null string is returned.
*
* @return the value of the first column of the first row
* @throws RpcException if anything goes wrong
*/
public String singletonString() throws RpcException {
RowSet rowSet = rowSet();
if (rowSet == null) {
throw new IllegalStateException("No rows returned");
}
RowSetReader reader = rowSet.reader();
reader.next();
String value;
if (reader.column(0).isNull()) {
value = null;
} else {
value = reader.column(0).getString();
}
rowSet.clear();
return value;
}
use of org.apache.drill.test.rowSet.RowSet.RowSetReader in project drill by apache.
the class RowSetTest method testIntRW.
private void testIntRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.INT).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0).add(Integer.MAX_VALUE).add(Integer.MIN_VALUE).build();
RowSetReader reader = rs.reader();
assertTrue(reader.next());
assertEquals(0, reader.column(0).getInt());
assertTrue(reader.next());
assertEquals(Integer.MAX_VALUE, reader.column(0).getInt());
assertTrue(reader.next());
assertEquals(Integer.MIN_VALUE, reader.column(0).getInt());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSet.RowSetReader in project drill by apache.
the class RowSetTest method TestTopScalarArray.
@Test
public void TestTopScalarArray() {
BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).addArray("a", MinorType.INT).build();
ExtendableRowSet rs1 = fixture.rowSet(batchSchema);
RowSetWriter writer = rs1.writer();
writer.column(0).setInt(10);
ArrayWriter array = writer.column(1).array();
array.setInt(100);
array.setInt(110);
writer.save();
writer.column(0).setInt(20);
array = writer.column(1).array();
array.setInt(200);
array.setInt(120);
array.setInt(220);
writer.save();
writer.column(0).setInt(30);
writer.save();
writer.done();
RowSetReader reader = rs1.reader();
assertTrue(reader.next());
assertEquals(10, reader.column(0).getInt());
ArrayReader arrayReader = reader.column(1).array();
assertEquals(2, arrayReader.size());
assertEquals(100, arrayReader.getInt(0));
assertEquals(110, arrayReader.getInt(1));
assertTrue(reader.next());
assertEquals(20, reader.column(0).getInt());
arrayReader = reader.column(1).array();
assertEquals(3, arrayReader.size());
assertEquals(200, arrayReader.getInt(0));
assertEquals(120, arrayReader.getInt(1));
assertEquals(220, arrayReader.getInt(2));
assertTrue(reader.next());
assertEquals(30, reader.column(0).getInt());
arrayReader = reader.column(1).array();
assertEquals(0, arrayReader.size());
assertFalse(reader.next());
SingleRowSet rs2 = fixture.rowSetBuilder(batchSchema).add(10, new int[] { 100, 110 }).add(20, new int[] { 200, 120, 220 }).add(30, null).build();
new RowSetComparison(rs1).verifyAndClear(rs2);
}
use of org.apache.drill.test.rowSet.RowSet.RowSetReader in project drill by apache.
the class RowSetTest method testDoubleRW.
private void testDoubleRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.FLOAT8).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0D).add(Double.MAX_VALUE).add(Double.MIN_VALUE).build();
RowSetReader reader = rs.reader();
assertTrue(reader.next());
assertEquals(0, reader.column(0).getDouble(), 0.000001);
assertTrue(reader.next());
assertEquals(Double.MAX_VALUE, reader.column(0).getDouble(), 0.000001);
assertTrue(reader.next());
assertEquals(Double.MIN_VALUE, reader.column(0).getDouble(), 0.000001);
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSet.RowSetReader in project drill by apache.
the class RowSetTest method testMap.
@Test
public void testMap() {
BatchSchema batchSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("b").add("c", MinorType.INT).add("d", MinorType.INT).buildMap().build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(10, 20, 30).add(40, 50, 60).build();
RowSetReader reader = rs.reader();
assertTrue(reader.next());
assertEquals(10, reader.column(0).getInt());
assertEquals(20, reader.column(1).getInt());
assertEquals(30, reader.column(2).getInt());
assertEquals(10, reader.column("a").getInt());
assertEquals(30, reader.column("b.d").getInt());
assertTrue(reader.next());
assertEquals(40, reader.column(0).getInt());
assertEquals(50, reader.column(1).getInt());
assertEquals(60, reader.column(2).getInt());
assertFalse(reader.next());
rs.clear();
}
Aggregations