Search in sources :

Example 41 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestScanOperExecLateSchema method testLateSchemaLifecycleNoSchemaBatch.

@Test
public void testLateSchemaLifecycleNoSchemaBatch() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    MockLateSchemaReader reader = new MockLateSchemaReader();
    reader.batchLimit = 2;
    reader.returnDataOnFirst = true;
    // Create the scan operator
    BaseScanFixtureBuilder builder = simpleBuilder(reader);
    builder.enableSchemaBatch = false;
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Standard startup
    assertFalse(reader.openCalled);
    // Create the expected result.
    // First batch with data.
    assertTrue(scan.next());
    RowSetUtilities.verify(makeExpected(0), fixture.wrap(scan.batchAccessor().container()));
    // Second batch.
    assertTrue(scan.next());
    RowSetUtilities.verify(makeExpected(20), fixture.wrap(scan.batchAccessor().container()));
    // EOF
    assertFalse(scan.next());
    assertTrue(reader.closeCalled);
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) Test(org.junit.Test)

Example 42 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestScanOperExecLateSchema method testNonEmptyFirstBatch.

/**
 * Test the case where the reader does not play the "first batch contains
 * only schema" game, and instead returns data. The Scan operator will
 * split the first batch into two: one with schema only, another with
 * data.
 */
@Test
public void testNonEmptyFirstBatch() {
    SingleRowSet expected = makeExpected();
    MockLateSchemaReader reader = new MockLateSchemaReader();
    reader.batchLimit = 2;
    reader.returnDataOnFirst = true;
    ScanFixture scanFixture = simpleFixture(reader);
    ScanOperatorExec scan = scanFixture.scanOp;
    // First batch. The reader returns a non-empty batch. The scan
    // operator strips off the schema and returns just that.
    assertTrue(scan.buildSchema());
    assertEquals(1, reader.batchCount);
    assertEquals(expected.batchSchema(), scan.batchAccessor().schema());
    assertEquals(0, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    // Second batch. Returns the "look-ahead" batch returned by
    // the reader earlier.
    assertTrue(scan.next());
    assertEquals(1, reader.batchCount);
    RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    // Third batch, normal case.
    assertTrue(scan.next());
    assertEquals(2, reader.batchCount);
    RowSetUtilities.verify(makeExpected(20), fixture.wrap(scan.batchAccessor().container()));
    // EOF
    assertFalse(scan.next());
    assertTrue(reader.closeCalled);
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) Test(org.junit.Test)

Example 43 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestScanOperExecLateSchema method testLateSchemaNoData.

@Test
public void testLateSchemaNoData() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    MockLateSchemaReader reader = new MockLateSchemaReader();
    reader.batchLimit = 0;
    reader.returnDataOnFirst = false;
    // Create the scan operator
    ScanFixture scanFixture = simpleFixture(reader);
    ScanOperatorExec scan = scanFixture.scanOp;
    // Standard startup
    assertFalse(reader.openCalled);
    // First batch: EOF.
    assertFalse(scan.buildSchema());
    assertTrue(reader.openCalled);
    assertTrue(reader.closeCalled);
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) Test(org.junit.Test)

Example 44 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestScanOperExecLateSchema method testLateSchemaEarlyClose.

/**
 * Test the case that a late scan operator is closed before
 * the first reader is opened.
 */
@Test
public void testLateSchemaEarlyClose() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    MockLateSchemaReader reader = new MockLateSchemaReader();
    reader.batchLimit = 2;
    reader.returnDataOnFirst = false;
    // Create the scan operator
    ScanFixture scanFixture = simpleFixture(reader);
    // Reader never opened.
    scanFixture.close();
    assertFalse(reader.openCalled);
    assertEquals(0, reader.batchCount);
    assertFalse(reader.closeCalled);
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) Test(org.junit.Test)

Example 45 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestScanOperExecEarlySchema method testEarlySchemaLifecycle.

@Test
public void testEarlySchemaLifecycle() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    MockEarlySchemaReader reader = new MockEarlySchemaReader();
    reader.batchLimit = 1;
    // Create the scan operator
    ScanFixture scanFixture = simpleFixture(reader);
    ScanOperatorExec scan = scanFixture.scanOp;
    SingleRowSet expected = makeExpected();
    RowSetComparison verifier = new RowSetComparison(expected);
    // First batch: return schema.
    assertTrue(scan.buildSchema());
    assertEquals(0, reader.batchCount);
    assertEquals(expected.batchSchema(), scan.batchAccessor().schema());
    assertEquals(0, scan.batchAccessor().rowCount());
    // Next call, return with data.
    assertTrue(scan.next());
    verifier.verifyAndClearAll(fixture.wrap(scan.batchAccessor().container()));
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    // Next again: no-op
    assertFalse(scan.next());
    scanFixture.close();
    // Close again: no-op
    scan.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) Test(org.junit.Test)

Aggregations

ScanFixture (org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)52 Test (org.junit.Test)51 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)17 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)15 SubOperatorTest (org.apache.drill.test.SubOperatorTest)13 UserException (org.apache.drill.common.exceptions.UserException)9 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)8 BatchAccessor (org.apache.drill.exec.physical.impl.protocol.BatchAccessor)7 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator)7 BatchSchema (org.apache.drill.exec.record.BatchSchema)7 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)6 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)5 ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)5 ManagedReader (org.apache.drill.exec.physical.impl.scan.framework.ManagedReader)5 BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)5 HashMap (java.util.HashMap)1 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)1 VectorContainer (org.apache.drill.exec.record.VectorContainer)1