Search in sources :

Example 51 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestResultSetCopier method testSchemaChange.

@Test
public void testSchemaChange() {
    ResultSetCopier copier = newCopier(new SchemaChangeGen(3, 4, 2));
    // Copy first batch with first schema
    copier.startOutputBatch();
    assertTrue(copier.nextInputBatch());
    copier.copyAllRows();
    assertFalse(copier.isOutputFull());
    // Second, same schema
    assertTrue(copier.nextInputBatch());
    copier.copyAllRows();
    assertFalse(copier.isOutputFull());
    // Plenty of room. But, change the schema.
    assertTrue(copier.nextInputBatch());
    assertTrue(copier.isOutputFull());
    // Must harvest partial output
    RowSet result = fixture.wrap(copier.harvest());
    SchemaChangeGen verifierGen = new SchemaChangeGen(6, 2, 1);
    verifierGen.next();
    RowSet expected = RowSets.wrap(verifierGen.batch());
    RowSetUtilities.verify(expected, result);
    // Start a new batch, implicitly complete pending copy
    copier.startOutputBatch();
    copier.copyAllRows();
    // Add one more of second schema
    assertTrue(copier.nextInputBatch());
    copier.copyAllRows();
    assertFalse(copier.isOutputFull());
    result = fixture.wrap(copier.harvest());
    verifierGen.next();
    expected = RowSets.wrap(verifierGen.batch());
    RowSetUtilities.verify(expected, result);
    assertFalse(copier.isCopyPending());
    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 52 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet 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 53 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet 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 54 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestSortEmitOutcome method testSortEmptyBatchFollowedByNonEmptyBatchEmitOutcome.

/**
 * Verifies ExternalSortBatch behavior when it receives first incoming batch post buildSchema phase as empty batch
 * with EMIT outcome followed by non-empty batch with EMIT outcome. Expectation is sort will handle the EMIT
 * boundary correctly and produce 2 empty output batch for first EMIT outcome and 1 non-empty output batch for second
 * EMIT outcome.
 */
@Test
public void testSortEmptyBatchFollowedByNonEmptyBatchEmitOutcome() {
    final RowSet.SingleRowSet nonEmptyInputRowSet2 = operatorFixture.rowSetBuilder(inputSchema).addRow(2, 20, "item2").addRow(13, 130, "item13").addRow(4, 40, "item4").build();
    final RowSet.SingleRowSet expectedRowSet = operatorFixture.rowSetBuilder(inputSchema).addRow(2, 20, "item2").addRow(4, 40, "item4").addRow(13, 130, "item13").build();
    inputContainer.add(emptyInputRowSet.container());
    inputContainer.add(emptyInputRowSet.container());
    inputContainer.add(nonEmptyInputRowSet2.container());
    inputOutcomes.add(OK_NEW_SCHEMA);
    inputOutcomes.add(EMIT);
    inputOutcomes.add(EMIT);
    final MockRecordBatch mockInputBatch = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, inputContainer, inputOutcomes, emptyInputRowSet.container().getSchema());
    sortBatch = new ExternalSortBatch(sortPopConfig, operatorFixture.getFragmentContext(), mockInputBatch);
    // BuildSchema phase
    assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
    outputRecordCount += sortBatch.getRecordCount();
    assertEquals(0, outputRecordCount);
    // Output for first empty EMIT batch
    assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
    assertTrue(sortBatch.next() == EMIT);
    outputRecordCount += sortBatch.getRecordCount();
    assertEquals(0, outputRecordCount);
    // Output for second non-empty EMIT batch
    assertTrue(sortBatch.next() == EMIT);
    outputRecordCount += sortBatch.getRecordCount();
    assertEquals(3, outputRecordCount);
    // verify results
    RowSet actualRowSet = HyperRowSetImpl.fromContainer(sortBatch.getContainer(), sortBatch.getSelectionVector4());
    new RowSetComparison(expectedRowSet).verify(actualRowSet);
    // Release memory for row sets
    nonEmptyInputRowSet2.clear();
    expectedRowSet.clear();
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 55 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestSortEmitOutcome method testSort_NonEmptyFirst_EmptyOKEmitOutcome.

/**
 * Verifies ExternalSortBatch behavior when it receives incoming batches with different IterOutcomes like
 * OK_NEW_SCHEMA / OK / EMIT / NONE
 */
@Test
public void testSort_NonEmptyFirst_EmptyOKEmitOutcome() {
    final RowSet.SingleRowSet expectedRowSet = operatorFixture.rowSetBuilder(inputSchema).addRow(1, 10, "item1").build();
    inputContainer.add(nonEmptyInputRowSet.container());
    inputContainer.add(emptyInputRowSet.container());
    inputContainer.add(emptyInputRowSet.container());
    inputContainer.add(emptyInputRowSet.container());
    inputOutcomes.add(OK_NEW_SCHEMA);
    inputOutcomes.add(OK);
    inputOutcomes.add(EMIT);
    inputOutcomes.add(NONE);
    final MockRecordBatch mockInputBatch = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, inputContainer, inputOutcomes, emptyInputRowSet.container().getSchema());
    sortBatch = new ExternalSortBatch(sortPopConfig, operatorFixture.getFragmentContext(), mockInputBatch);
    // BuildSchema phase output
    assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
    assertEquals(0, sortBatch.getRecordCount());
    // Output batch 1 for first 3 input batches with OK_NEW_SCHEMA/OK/EMIT outcome
    assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
    assertEquals(1, sortBatch.getRecordCount());
    // verify results
    RowSet actualRowSet = HyperRowSetImpl.fromContainer(sortBatch.getContainer(), sortBatch.getSelectionVector4());
    new RowSetComparison(expectedRowSet).verify(actualRowSet);
    // Output batch 2 for first 3 input batches with OK_NEW_SCHEMA/OK/EMIT outcome
    assertTrue(sortBatch.next() == EMIT);
    assertEquals(0, sortBatch.getRecordCount());
    // Output batch for NONE outcome
    assertTrue(sortBatch.next() == NONE);
    // Release memory for row set
    expectedRowSet.clear();
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Aggregations

RowSet (org.apache.drill.exec.physical.rowSet.RowSet)725 Test (org.junit.Test)690 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)583 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)574 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)297 ClusterTest (org.apache.drill.test.ClusterTest)253 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)233 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)137 SubOperatorTest (org.apache.drill.test.SubOperatorTest)128 JsonTest (org.apache.drill.categories.JsonTest)112 EvfTest (org.apache.drill.categories.EvfTest)107 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)97 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)63 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)61 QueryBuilder (org.apache.drill.test.QueryBuilder)61 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)60 OperatorTest (org.apache.drill.categories.OperatorTest)53 VectorContainer (org.apache.drill.exec.record.VectorContainer)31 RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)28 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)27