Search in sources :

Example 6 with ScanFixture

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

the class TestScanOperExecBasics method testUserExceptionOnSecondNext.

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

        @Override
        public boolean next() {
            if (batchCount == 1) {
                // Load some data
                super.next();
                throw UserException.dataReadError().addContext(ERROR_MSG).build(logger);
            }
            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));
        assertNull(e.getCause());
    }
    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 7 with ScanFixture

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

the class TestScanOperExecBasics method testNoReader.

/**
 * Pathological case that a scan operator is provided no readers.
 * It will throw a user exception because the downstream operators
 * can't handle this case so we choose to stop the show early to
 * avoid getting into a strange state.
 */
@Test
public void testNoReader() {
    // Create the scan operator
    ScanFixture scanFixture = simpleFixture();
    ScanOperatorExec scan = scanFixture.scanOp;
    try {
        scan.buildSchema();
    } catch (UserException e) {
        // Expected
        assertTrue(e.getCause() instanceof ExecutionSetupException);
    }
    // Must close the DAG (context and scan operator) even on failures
    scanFixture.close();
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test)

Example 8 with ScanFixture

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

the class TestScanOperExecBasics method testExceptionOnFirstNext.

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

        @Override
        public boolean next() {
            // Load some data
            super.next();
            throw new IllegalStateException(ERROR_MSG);
        }
    };
    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));
        assertTrue(e.getCause() instanceof IllegalStateException);
    }
    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 9 with ScanFixture

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

the class TestScanOperExecBasics method testExceptionOnClose.

@Test
public void testExceptionOnClose() {
    MockEarlySchemaReader reader1 = new MockEarlySchemaReader() {

        @Override
        public void close() {
            super.close();
            throw new IllegalStateException(ERROR_MSG);
        }
    };
    reader1.batchLimit = 2;
    MockEarlySchemaReader reader2 = new MockEarlySchemaReader();
    reader2.batchLimit = 2;
    ScanFixture scanFixture = simpleFixture(reader1, reader2);
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    scan.batchAccessor().release();
    assertTrue(scan.next());
    scan.batchAccessor().release();
    try {
        scan.next();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertTrue(e.getCause() instanceof IllegalStateException);
    }
    assertTrue(reader1.closeCalled);
    assertFalse(reader2.openCalled);
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test)

Example 10 with ScanFixture

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

the class TestScanOperExecBasics method testUserExceptionOnOpen.

@Test
public void testUserExceptionOnOpen() {
    // Reader which fails on open with a known error message
    // using a UserException.
    MockEarlySchemaReader reader = new MockEarlySchemaReader() {

        @Override
        public boolean open(SchemaNegotiator schemaNegotiator) {
            openCalled = true;
            throw UserException.dataReadError().addContext(ERROR_MSG).build(logger);
        }
    };
    reader.batchLimit = 2;
    ScanFixture scanFixture = simpleFixture(reader);
    ScanOperatorExec scan = scanFixture.scanOp;
    try {
        scan.buildSchema();
        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) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator) UserException(org.apache.drill.common.exceptions.UserException) 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