Search in sources :

Example 1 with OperatorFixture

use of org.apache.drill.test.OperatorFixture in project drill by axbaretto.

the class TestSortImpl method testSingleBatch.

/**
 * Degenerate case: two (unsorted) rows in single batch
 * @throws Exception
 */
@Test
public void testSingleBatch() throws Exception {
    try (OperatorFixture fixture = OperatorFixture.standardFixture()) {
        BatchSchema schema = SortTestUtilities.nonNullSchema();
        SortTestFixture sortTest = new SortTestFixture(fixture);
        sortTest.addInput(fixture.rowSetBuilder(schema).addRow(2, "second").addRow(1, "first").build());
        sortTest.addOutput(fixture.rowSetBuilder(schema).addRow(1, "first").addRow(2, "second").build());
        sortTest.run();
    }
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) OperatorFixture(org.apache.drill.test.OperatorFixture) DrillTest(org.apache.drill.test.DrillTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 2 with OperatorFixture

use of org.apache.drill.test.OperatorFixture in project drill by axbaretto.

the class TestSortImpl method testTwoBatches.

/**
 * Degenerate case, one row in each of two
 * (unsorted) batches.
 * @throws Exception
 */
@Test
public void testTwoBatches() throws Exception {
    try (OperatorFixture fixture = OperatorFixture.standardFixture()) {
        BatchSchema schema = SortTestUtilities.nonNullSchema();
        SortTestFixture sortTest = new SortTestFixture(fixture);
        sortTest.addInput(fixture.rowSetBuilder(schema).addRow(2, "second").build());
        sortTest.addInput(fixture.rowSetBuilder(schema).addRow(1, "first").build());
        sortTest.addOutput(fixture.rowSetBuilder(schema).addRow(1, "first").addRow(2, "second").build());
        sortTest.run();
    }
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) OperatorFixture(org.apache.drill.test.OperatorFixture) DrillTest(org.apache.drill.test.DrillTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 3 with OperatorFixture

use of org.apache.drill.test.OperatorFixture in project drill by axbaretto.

the class TestSortImpl method testSpill.

/**
 * Force the sorter to spill, and verify that the resulting data
 * is correct. Uses a specific property of the sort to set the
 * in-memory batch limit so that we don't have to fiddle with filling
 * up memory. The point here is not to test the code that decides when
 * to spill (that was already tested.) Nor to test the spilling
 * mechanism itself (that has also already been tested.) Rather it is
 * to ensure that, when those components are integrated into the
 * sort implementation, that the whole assembly does the right thing.
 *
 * @throws Exception
 */
@Test
public void testSpill() throws Exception {
    OperatorFixture.Builder builder = OperatorFixture.builder();
    builder.configBuilder().put(ExecConstants.EXTERNAL_SORT_BATCH_LIMIT, 2);
    try (OperatorFixture fixture = builder.build()) {
        BatchSchema schema = SortTestUtilities.nonNullSchema();
        SortTestFixture sortTest = new SortTestFixture(fixture) {

            @Override
            protected void validateSort(SortImpl sort) {
                assertEquals(1, sort.getMetrics().getSpillCount());
                assertEquals(0, sort.getMetrics().getMergeCount());
                assertEquals(2, sort.getMetrics().getPeakBatchCount());
            }

            @Override
            protected void validateFinalStats(SortImpl sort) {
                assertTrue(sort.getMetrics().getWriteBytes() > 0);
            }
        };
        sortTest.addInput(fixture.rowSetBuilder(schema).addRow(2, "second").build());
        sortTest.addInput(fixture.rowSetBuilder(schema).addRow(3, "third").build());
        sortTest.addInput(fixture.rowSetBuilder(schema).addRow(1, "first").build());
        sortTest.addOutput(fixture.rowSetBuilder(schema).addRow(1, "first").addRow(2, "second").addRow(3, "third").build());
        sortTest.run();
    }
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) OperatorFixture(org.apache.drill.test.OperatorFixture) DrillTest(org.apache.drill.test.DrillTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 4 with OperatorFixture

use of org.apache.drill.test.OperatorFixture in project drill by axbaretto.

the class TestSortImpl method testEmptyInput.

/**
 * Test for an input with a schema, but only an empty input batch.
 * @throws Exception
 */
@Test
public void testEmptyInput() throws Exception {
    try (OperatorFixture fixture = OperatorFixture.standardFixture()) {
        BatchSchema schema = SortTestUtilities.nonNullSchema();
        SortTestFixture sortTest = new SortTestFixture(fixture);
        sortTest.addInput(fixture.rowSetBuilder(schema).build());
        sortTest.run();
    }
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) OperatorFixture(org.apache.drill.test.OperatorFixture) DrillTest(org.apache.drill.test.DrillTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 5 with OperatorFixture

use of org.apache.drill.test.OperatorFixture in project drill by axbaretto.

the class TestSortImpl method testSingleRow.

/**
 * Degenerate case: single row in single batch.
 * @throws Exception
 */
@Test
public void testSingleRow() throws Exception {
    try (OperatorFixture fixture = OperatorFixture.standardFixture()) {
        BatchSchema schema = SortTestUtilities.nonNullSchema();
        SortTestFixture sortTest = new SortTestFixture(fixture);
        sortTest.addInput(fixture.rowSetBuilder(schema).addRow(1, "first").build());
        sortTest.addOutput(fixture.rowSetBuilder(schema).addRow(1, "first").build());
        sortTest.run();
    }
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) OperatorFixture(org.apache.drill.test.OperatorFixture) DrillTest(org.apache.drill.test.DrillTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Aggregations

OperatorFixture (org.apache.drill.test.OperatorFixture)39 Test (org.junit.Test)36 DrillTest (org.apache.drill.test.DrillTest)20 OperatorTest (org.apache.drill.categories.OperatorTest)14 OptionManager (org.apache.drill.exec.server.options.OptionManager)8 StoragePlugins (org.apache.drill.exec.planner.logical.StoragePlugins)7 BatchSchema (org.apache.drill.exec.record.BatchSchema)7 StoragePluginConfig (org.apache.drill.common.logical.StoragePluginConfig)6 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 FileSystemConfig (org.apache.drill.exec.store.dfs.FileSystemConfig)5 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)4 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)4 IOException (java.io.IOException)2 AbstractSecuredStoragePluginConfig (org.apache.drill.common.logical.AbstractSecuredStoragePluginConfig)2 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)2 OperatorContext (org.apache.drill.exec.ops.OperatorContext)2 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)2 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)2 VectorContainer (org.apache.drill.exec.record.VectorContainer)2 MockStorePOP (org.apache.drill.exec.store.mock.MockStorePOP)2