Search in sources :

Example 1 with SortResults

use of org.apache.drill.exec.physical.impl.xsort.managed.SortImpl.SortResults in project drill by axbaretto.

the class TestSortImpl method runLargeSortTest.

/**
 * Run a full-blown sort test with multiple input batches. Because we want to
 * generate multiple inputs, we don't create them statically. Instead, we generate
 * them on the fly using a data generator. A matching data validator verifies the
 * output. Here, we are focusing on overall test flow. Separate, detailed, unit
 * tests have already probed the details of each sort component and data type,
 * so we don't need to repeat that whole exercise here; using integer keys is
 * sufficient.
 *
 * @param fixture the operator test fixture
 * @param dataGen input batch generator
 * @param validator validates output batches
 */
public void runLargeSortTest(OperatorFixture fixture, DataGenerator dataGen, DataValidator validator) {
    VectorContainer dest = new VectorContainer();
    SortImpl sort = makeSortImpl(fixture, Ordering.ORDER_ASC, Ordering.NULLS_UNSPECIFIED, dest);
    int batchCount = 0;
    RowSet input;
    while ((input = dataGen.nextRowSet()) != null) {
        batchCount++;
        if (batchCount == 1) {
            // Simulates a NEW_SCHEMA event
            sort.setSchema(input.container().getSchema());
        }
        // Simulates an OK event
        sort.addBatch(input.vectorAccessible());
    }
    // Simulate returning results
    SortResults results = sort.startMerge();
    if (results.getContainer() != dest) {
        dest.clear();
        dest = results.getContainer();
    }
    while (results.next()) {
        RowSet output = toRowSet(results, dest);
        validator.validate(output);
    }
    validator.validateDone();
    results.close();
    dest.clear();
    sort.close();
    sort.opContext().close();
}
Also used : DirectRowSet(org.apache.drill.test.rowSet.DirectRowSet) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) IndirectRowSet(org.apache.drill.test.rowSet.IndirectRowSet) SortResults(org.apache.drill.exec.physical.impl.xsort.managed.SortImpl.SortResults) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 2 with SortResults

use of org.apache.drill.exec.physical.impl.xsort.managed.SortImpl.SortResults in project drill by axbaretto.

the class TestSortImpl method runWideRowsTest.

/**
 * Run a test using wide rows. This stresses the "copier" portion of the sort
 * and allows us to test the original generated copier and the revised "generic"
 * copier.
 *
 * @param fixture operator test fixture
 * @param colCount number of data (non-key) columns
 * @param rowCount number of rows to generate
 */
public void runWideRowsTest(OperatorFixture fixture, int colCount, int rowCount) {
    SchemaBuilder builder = new SchemaBuilder().add("key", MinorType.INT);
    for (int i = 0; i < colCount; i++) {
        builder.add("col" + (i + 1), MinorType.INT);
    }
    BatchSchema schema = builder.build();
    ExtendableRowSet rowSet = fixture.rowSet(schema);
    RowSetWriter writer = rowSet.writer(rowCount);
    for (int i = 0; i < rowCount; i++) {
        writer.set(0, i);
        for (int j = 0; j < colCount; j++) {
            writer.set(j + 1, i * 100_000 + j);
        }
        writer.save();
    }
    writer.done();
    VectorContainer dest = new VectorContainer();
    SortImpl sort = makeSortImpl(fixture, Ordering.ORDER_ASC, Ordering.NULLS_UNSPECIFIED, dest);
    sort.setSchema(rowSet.container().getSchema());
    sort.addBatch(rowSet.vectorAccessible());
    SortResults results = sort.startMerge();
    if (results.getContainer() != dest) {
        dest.clear();
        dest = results.getContainer();
    }
    assertTrue(results.next());
    assertFalse(results.next());
    results.close();
    dest.clear();
    sort.close();
    sort.opContext().close();
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) SortResults(org.apache.drill.exec.physical.impl.xsort.managed.SortImpl.SortResults) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Aggregations

SortResults (org.apache.drill.exec.physical.impl.xsort.managed.SortImpl.SortResults)2 VectorContainer (org.apache.drill.exec.record.VectorContainer)2 ExtendableRowSet (org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)2 BatchSchema (org.apache.drill.exec.record.BatchSchema)1 DirectRowSet (org.apache.drill.test.rowSet.DirectRowSet)1 IndirectRowSet (org.apache.drill.test.rowSet.IndirectRowSet)1 RowSet (org.apache.drill.test.rowSet.RowSet)1 RowSetWriter (org.apache.drill.test.rowSet.RowSetWriter)1 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)1