Search in sources :

Example 6 with ResultSetCopier

use of org.apache.drill.exec.physical.resultSet.ResultSetCopier in project drill by apache.

the class TestResultSetCopier method testMerge.

/**
 * Test merging multiple batches from the same input
 * source; all batches share the same vectors, hence
 * implicitly the same schema.
 * <p>
 * This copier does not support merging from multiple
 * streams.
 */
@Test
public void testMerge() {
    ResultSetCopier copier = newCopier(new DataGen(3, 5));
    copier.startOutputBatch();
    for (int i = 0; i < 5; i++) {
        assertTrue(copier.nextInputBatch());
        assertFalse(copier.isOutputFull());
        copier.copyAllRows();
        assertFalse(copier.isOutputFull());
        assertFalse(copier.isCopyPending());
    }
    assertFalse(copier.nextInputBatch());
    RowSet result = fixture.wrap(copier.harvest());
    // Verify with single batch with all rows
    DataGen dataGen = new DataGen(15, 1);
    dataGen.next();
    RowSet expected = RowSets.wrap(dataGen.batch());
    RowSetUtilities.verify(expected, result);
    copier.close();
}
Also used : ResultSetCopier(org.apache.drill.exec.physical.resultSet.ResultSetCopier) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 7 with ResultSetCopier

use of org.apache.drill.exec.physical.resultSet.ResultSetCopier in project drill by apache.

the class TestResultSetCopier method testCopyRecord.

@Test
public void testCopyRecord() {
    ResultSetCopier copier = newCopier(new DataGen(3, 2));
    copier.startOutputBatch();
    copier.nextInputBatch();
    copier.copyRow(2);
    copier.copyRow(0);
    copier.copyRow(1);
    copier.nextInputBatch();
    copier.copyRow(1);
    copier.copyRow(0);
    copier.copyRow(2);
    assertFalse(copier.nextInputBatch());
    RowSet expected = new RowSetBuilder(fixture.allocator(), TEST_SCHEMA).addRow(3, "Row 3").addRow(1, "Row 1").addRow(2, "Row 2").addRow(5, "Row 5").addRow(4, "Row 4").addRow(6, "Row 6").build();
    RowSetUtilities.verify(expected, fixture.wrap(copier.harvest()));
    copier.close();
}
Also used : ResultSetCopier(org.apache.drill.exec.physical.resultSet.ResultSetCopier) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 8 with ResultSetCopier

use of org.apache.drill.exec.physical.resultSet.ResultSetCopier in project drill by apache.

the class TestResultSetCopier method testSV2.

// TODO: Test with two consecutive schema changes in
// same input batch: once with rows pending, another without.
@Test
public void testSV2() {
    ResultSetCopier copier = newCopier(new FilteredGen());
    copier.startOutputBatch();
    assertTrue(copier.nextInputBatch());
    copier.copyAllRows();
    RowSet expected = new RowSetBuilder(fixture.allocator(), TEST_SCHEMA).addRow(10, "Row 10").addRow(8, "Row 8").addRow(6, "Row 6").addRow(4, "Row 4").addRow(2, "Row 2").build();
    RowSet result = fixture.wrap(copier.harvest());
    RowSetUtilities.verify(expected, result);
    copier.close();
}
Also used : ResultSetCopier(org.apache.drill.exec.physical.resultSet.ResultSetCopier) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 9 with ResultSetCopier

use of org.apache.drill.exec.physical.resultSet.ResultSetCopier in project drill by apache.

the class TestResultSetCopier method testNullable.

@Test
public void testNullable() {
    ResultSetCopier copier = newCopier(new NullableGen());
    copier.startOutputBatch();
    copier.nextInputBatch();
    copier.copyAllRows();
    RowSet result = fixture.wrap(copier.harvest());
    NullableGen verifierGen = new NullableGen();
    verifierGen.next();
    RowSet expected = RowSets.wrap(verifierGen.batch());
    RowSetUtilities.verify(expected, result);
    copier.close();
}
Also used : ResultSetCopier(org.apache.drill.exec.physical.resultSet.ResultSetCopier) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 10 with ResultSetCopier

use of org.apache.drill.exec.physical.resultSet.ResultSetCopier in project drill by apache.

the class TestResultSetCopier method testBasics.

@Test
public void testBasics() {
    DataGen dataGen = new DataGen();
    ResultSetCopier copier = newCopier(dataGen);
    // Nothing should work yet
    try {
        copier.copyAllRows();
        fail();
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        copier.harvest();
        fail();
    } catch (IllegalStateException e) {
    // Expected
    }
    // Predicates should work
    assertFalse(copier.isCopyPending());
    assertFalse(copier.hasOutputRows());
    assertFalse(copier.isOutputFull());
    // Define a schema and start an output batch.
    copier.startOutputBatch();
    assertFalse(copier.isCopyPending());
    assertFalse(copier.hasOutputRows());
    assertFalse(copier.isOutputFull());
    // Provide an input batch
    assertTrue(copier.nextInputBatch());
    assertFalse(copier.isCopyPending());
    assertFalse(copier.hasOutputRows());
    assertFalse(copier.isOutputFull());
    // Now can do some actual copying
    while (copier.copyNextRow()) {
    // empty
    }
    assertFalse(copier.isCopyPending());
    assertTrue(copier.hasOutputRows());
    assertFalse(copier.isOutputFull());
    // Get and verify the output batch
    // (Does not free the input batch, we reuse it
    // in the verify step below.)
    RowSet result = fixture.wrap(copier.harvest());
    new RowSetComparison(fixture.wrap(dataGen.batch())).verifyAndClear(result);
    // No more input
    copier.startOutputBatch();
    assertFalse(copier.nextInputBatch());
    // OK to try multiple times
    assertFalse(copier.nextInputBatch());
    // Copier will release the input batch
    copier.close();
}
Also used : ResultSetCopier(org.apache.drill.exec.physical.resultSet.ResultSetCopier) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ResultSetCopier (org.apache.drill.exec.physical.resultSet.ResultSetCopier)12 SubOperatorTest (org.apache.drill.test.SubOperatorTest)12 Test (org.junit.Test)12 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)9 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)2 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)1