Search in sources :

Example 31 with RowSetReader

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;
}
Also used : DirectRowSet(org.apache.drill.test.rowSet.DirectRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) RowSetReader(org.apache.drill.test.rowSet.RowSetReader)

Example 32 with RowSetReader

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;
}
Also used : DirectRowSet(org.apache.drill.test.rowSet.DirectRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) RowSetReader(org.apache.drill.test.rowSet.RowSetReader)

Example 33 with RowSetReader

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;
}
Also used : DirectRowSet(org.apache.drill.test.rowSet.DirectRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) RowSetReader(org.apache.drill.test.rowSet.RowSetReader)

Example 34 with RowSetReader

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();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 35 with RowSetReader

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();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSetReader)

Aggregations

RowSetReader (org.apache.drill.test.rowSet.RowSetReader)55 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)50 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)46 SubOperatorTest (org.apache.drill.test.SubOperatorTest)39 Test (org.junit.Test)39 BatchSchema (org.apache.drill.exec.record.BatchSchema)34 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)27 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)17 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)17 RowSet (org.apache.drill.test.rowSet.RowSet)16 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)14 ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)12 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)12 Period (org.joda.time.Period)9 TupleReader (org.apache.drill.exec.vector.accessor.TupleReader)7 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)7 ExtendableRowSet (org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)7 RowSetWriter (org.apache.drill.test.rowSet.RowSetWriter)7 ResultSetOptions (org.apache.drill.exec.physical.rowSet.impl.ResultSetLoaderImpl.ResultSetOptions)5 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)5