Search in sources :

Example 36 with ScanFixture

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

the class TestScanOperExecSmoothing method testSchemaChange.

/**
 * Multiple readers with a schema change between them.
 */
@Test
public void testSchemaChange() {
    MockEarlySchemaReader reader1 = new MockEarlySchemaReader();
    reader1.batchLimit = 2;
    MockEarlySchemaReader reader2 = new MockEarlySchemaReader2();
    reader2.batchLimit = 2;
    ScanFixture scanFixture = simpleFixture(reader1, reader2);
    ScanOperatorExec scan = scanFixture.scanOp;
    // Build schema
    assertTrue(scan.buildSchema());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    scan.batchAccessor().release();
    readSchemaChangeBatches(scanFixture, reader2);
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) Test(org.junit.Test)

Example 37 with ScanFixture

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

the class TestScanOperExecBasics method testMultiEOFOnFirstBatch.

/**
 * Test multiple readers, all EOF on first batch.
 * The scan will return one empty batch to declare the
 * early schema. Results in an empty (rather than null)
 * result set.
 */
@Test
public void testMultiEOFOnFirstBatch() {
    MockEarlySchemaReader reader1 = new MockEarlySchemaReader();
    reader1.batchLimit = 0;
    MockEarlySchemaReader reader2 = new MockEarlySchemaReader();
    reader2.batchLimit = 0;
    ScanFixture scanFixture = simpleFixture(reader1, reader2);
    ScanOperatorExec scan = scanFixture.scanOp;
    // EOF
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    VectorContainer container = scan.batchAccessor().container();
    assertEquals(0, container.getRecordCount());
    assertEquals(2, container.getNumberOfColumns());
    assertTrue(reader1.closeCalled);
    assertTrue(reader2.closeCalled);
    assertEquals(0, scan.batchAccessor().rowCount());
    assertFalse(scan.next());
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) VectorContainer(org.apache.drill.exec.record.VectorContainer) Test(org.junit.Test)

Example 38 with ScanFixture

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

the class TestScanOperExecBasics method testExceptionOnSecondNext.

/**
 * Test throwing an exception after the first batch, but while
 * "reading" the second. Note that the first batch returns data
 * and is spread over two next() calls, so the error is on the
 * third call to the scan operator next().
 */
@Test
public void testExceptionOnSecondNext() {
    MockEarlySchemaReader reader = new MockEarlySchemaReader() {

        @Override
        public boolean next() {
            if (batchCount == 1) {
                // Load some data
                super.next();
                throw new IllegalStateException(ERROR_MSG);
            }
            return super.next();
        }
    };
    reader.batchLimit = 2;
    ScanFixture scanFixture = simpleFixture(reader);
    ScanOperatorExec scan = scanFixture.scanOp;
    // Schema
    assertTrue(scan.buildSchema());
    // First batch
    assertTrue(scan.next());
    scan.batchAccessor().release();
    try {
        scan.next();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertTrue(e.getCause() instanceof IllegalStateException);
    }
    scanFixture.close();
    assertTrue(reader.closeCalled);
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test)

Example 39 with ScanFixture

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

the class TestScanOperExecBasics method testUserExceptionOnFirstNext.

@Test
public void testUserExceptionOnFirstNext() {
    MockEarlySchemaReader reader = new MockEarlySchemaReader() {

        @Override
        public boolean next() {
            // Load some data
            super.next();
            throw UserException.dataReadError().addContext(ERROR_MSG).build(logger);
        }
    };
    reader.batchLimit = 2;
    ScanFixture scanFixture = simpleFixture(reader);
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    try {
        scan.next();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertNull(e.getCause());
    }
    assertTrue(reader.openCalled);
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
    assertTrue(reader.closeCalled);
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test)

Example 40 with ScanFixture

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

the class TestScanOperExecLateSchema method testLateSchemaLifecycleNoFile.

/**
 * Test a late-schema source that has no file information.
 * (Like a Hive or JDBC data source.)
 */
@Test
public void testLateSchemaLifecycleNoFile() {
    // 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);
    ScanOperatorExec scan = scanFixture.scanOp;
    // Standard startup
    assertFalse(reader.openCalled);
    // First batch: build schema. The reader helps: it returns an
    // empty first batch.
    assertTrue(scan.buildSchema());
    assertTrue(reader.openCalled);
    assertEquals(1, reader.batchCount);
    assertEquals(0, scan.batchAccessor().rowCount());
    // Create the expected result.
    SingleRowSet expected = makeExpected(20);
    RowSetComparison verifier = new RowSetComparison(expected);
    assertEquals(expected.batchSchema(), scan.batchAccessor().schema());
    // Next call, return with data.
    assertTrue(scan.next());
    verifier.verifyAndClearAll(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) 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