Search in sources :

Example 56 with RowSet

use of org.apache.drill.test.rowSet.RowSet in project drill by axbaretto.

the class TestExternalSort method testNumericAndStringTypes.

private void testNumericAndStringTypes(boolean testLegacy) throws Exception {
    final int record_count = 10000;
    final String tableDirName = "numericAndStringTypes";
    {
        final BatchSchema schema = new SchemaBuilder().add("a", Types.required(TypeProtos.MinorType.INT)).build();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 0; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "a.json");
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
    }
    {
        final BatchSchema schema = new SchemaBuilder().add("a", Types.required(TypeProtos.MinorType.INT)).build();
        final RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, schema);
        for (int i = 1; i <= record_count; i += 2) {
            rowSetBuilder.addRow(i);
        }
        final RowSet rowSet = rowSetBuilder.build();
        final File tableFile = createTableFile(tableDirName, "b.json");
        new JsonFileBuilder(rowSet).setCustomFormatter("a", "\"%05d\"").build(tableFile);
        rowSet.clear();
    }
    TestBuilder builder = testBuilder().sqlQuery("select * from dfs.`%s` order by a desc", tableDirName).ordered().optionSettingQueriesForTestQuery(getOptions(testLegacy)).baselineColumns("a");
    // Strings come first because order by is desc
    for (int i = record_count; i >= 0; ) {
        i--;
        if (i >= 0) {
            builder.baselineValues(String.format("%05d", i--));
        }
    }
    for (int i = record_count; i >= 0; ) {
        builder.baselineValues((long) i--);
        i--;
    }
    builder.go();
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSet(org.apache.drill.test.rowSet.RowSet) JsonFileBuilder(org.apache.drill.test.rowSet.file.JsonFileBuilder) File(java.io.File) TestBuilder(org.apache.drill.test.TestBuilder)

Example 57 with RowSet

use of org.apache.drill.test.rowSet.RowSet in project drill by axbaretto.

the class AbstractGenericCopierTest method testAppendRecords.

@Test
public void testAppendRecords() throws SchemaChangeException {
    try (RootAllocator allocator = new RootAllocator(10_000_000)) {
        final BatchSchema batchSchema = createTestSchema(BatchSchema.SelectionVectorMode.NONE);
        final RowSet srcRowSet = createSrcRowSet(allocator);
        final RowSet destRowSet = new RowSetBuilder(allocator, batchSchema).build();
        final VectorContainer destContainer = destRowSet.container();
        final Copier copier = createCopier();
        final RowSet expectedRowSet = createExpectedRowset(allocator);
        copier.setup(new RowSetBatch(srcRowSet), destContainer);
        copier.appendRecord(0);
        copier.appendRecords(1, 2);
        try {
            new RowSetComparison(expectedRowSet).verify(destRowSet);
        } finally {
            srcRowSet.clear();
            if (srcRowSet instanceof RowSet.HyperRowSet) {
                ((RowSet.HyperRowSet) srcRowSet).getSv4().clear();
            }
            destRowSet.clear();
            expectedRowSet.clear();
        }
    }
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) RootAllocator(org.apache.drill.exec.memory.RootAllocator) RowSetBatch(org.apache.drill.test.rowSet.RowSetBatch) BatchSchema(org.apache.drill.exec.record.BatchSchema) RowSet(org.apache.drill.test.rowSet.RowSet) VectorContainer(org.apache.drill.exec.record.VectorContainer) Test(org.junit.Test)

Example 58 with RowSet

use of org.apache.drill.test.rowSet.RowSet 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 59 with RowSet

use of org.apache.drill.test.rowSet.RowSet 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 60 with RowSet

use of org.apache.drill.test.rowSet.RowSet 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)

Aggregations

RowSet (org.apache.drill.test.rowSet.RowSet)69 Test (org.junit.Test)54 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)52 SubOperatorTest (org.apache.drill.test.SubOperatorTest)44 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)40 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)35 ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)34 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)33 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)26 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)23 BatchSchema (org.apache.drill.exec.record.BatchSchema)18 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)16 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)13 ColumnSize (org.apache.drill.exec.record.RecordBatchSizer.ColumnSize)11 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)11 ValueVector (org.apache.drill.exec.vector.ValueVector)10 ResultSetOptions (org.apache.drill.exec.physical.rowSet.impl.ResultSetLoaderImpl.ResultSetOptions)9 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)9 DirectRowSet (org.apache.drill.test.rowSet.DirectRowSet)8 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)7