use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.
the class QueryBuilder method singletonLong.
/**
* Run the query that is expected to return (at least) one row
* with the only (or first) column returning a long value.
* The long value cannot be null.
*
* @return the value of the first column of the first row
* @throws RpcException if anything goes wrong
*/
public long singletonLong() throws RpcException {
RowSet rowSet = rowSet();
if (rowSet == null) {
throw new IllegalStateException("No rows returned");
}
RowSetReader reader = rowSet.reader();
reader.next();
long value = reader.scalar(0).getLong();
rowSet.clear();
return value;
}
use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.
the class QueryBuilder method singletonInt.
/**
* Run the query that is expected to return (at least) one row
* with the only (or first) column returning a int value.
* The int value cannot be null.
*
* @return the value of the first column of the first row
* @throws RpcException if anything goes wrong
*/
public int singletonInt() throws RpcException {
RowSet rowSet = rowSet();
if (rowSet == null) {
throw new IllegalStateException("No rows returned");
}
RowSetReader reader = rowSet.reader();
reader.next();
int value = reader.scalar(0).getInt();
rowSet.clear();
return value;
}
use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.
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.scalar(0).isNull()) {
value = null;
} else {
value = reader.scalar(0).getString();
}
rowSet.clear();
return value;
}
use of org.apache.drill.test.rowSet.RowSetReader 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.test.rowSet.RowSetReader 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();
}
Aggregations