Search in sources :

Example 66 with UserException

use of org.apache.drill.common.exceptions.UserException in project drill by apache.

the class TestScanBasics method testExceptionOnOpen.

@Test
public void testExceptionOnOpen() {
    // Reader which fails on open with a known error message
    // using an exception other than UserException.
    ObservableCreator creator = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            return new GenericCrashReader(negotiator);
        }
    };
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    try {
        scan.buildSchema();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertTrue(e.getCause() instanceof IllegalStateException);
    }
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 67 with UserException

use of org.apache.drill.common.exceptions.UserException in project drill by apache.

the class TestScanBasics method testExceptionOnClose.

@Test
public void testExceptionOnClose() {
    ObservableCreator creator1 = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator) {

                @Override
                public void close() {
                    super.close();
                    throw new IllegalStateException(ERROR_MSG);
                }
            };
            reader.batchLimit = 2;
            return reader;
        }
    };
    ObservableCreator creator2 = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
            reader.batchLimit = 2;
            return reader;
        }
    };
    ScanFixture scanFixture = simpleFixture(creator1, creator2);
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    scan.batchAccessor().release();
    assertTrue(scan.next());
    scan.batchAccessor().release();
    // Fail on close of first reader
    try {
        scan.next();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertTrue(e.getCause() instanceof IllegalStateException);
    }
    assertNull(creator2.reader);
    scanFixture.close();
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 68 with UserException

use of org.apache.drill.common.exceptions.UserException in project drill by apache.

the class TestScanBasics 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() {
    ObservableCreator creator = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator) {

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

Example 69 with UserException

use of org.apache.drill.common.exceptions.UserException in project drill by apache.

the class TestScanBasics method testUserExceptionOnOpen.

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

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            return new UserExceptionCrashReader(negotiator);
        }
    };
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    try {
        scan.buildSchema();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertNull(e.getCause());
    }
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 70 with UserException

use of org.apache.drill.common.exceptions.UserException in project drill by apache.

the class TestScanBasics method testUserExceptionOnClose.

@Test
public void testUserExceptionOnClose() {
    ObservableCreator creator1 = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator) {

                @Override
                public void close() {
                    super.close();
                    throw UserException.dataReadError().message(ERROR_MSG).build(logger);
                }
            };
            reader.batchLimit = 2;
            return reader;
        }
    };
    ObservableCreator creator2 = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
            reader.batchLimit = 2;
            return reader;
        }
    };
    ScanFixture scanFixture = simpleFixture(creator1, creator2);
    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));
        assertNull(e.getCause());
    }
    assertNull(creator2.reader);
    scanFixture.close();
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Aggregations

UserException (org.apache.drill.common.exceptions.UserException)102 Test (org.junit.Test)76 EvfTest (org.apache.drill.categories.EvfTest)39 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)30 SubOperatorTest (org.apache.drill.test.SubOperatorTest)30 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)28 RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)12 ManagedReader (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader)12 ScanLifecycleBuilder (org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)11 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator)11 ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)9 ScanFixture (org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)9 SchemaPath (org.apache.drill.common.expression.SchemaPath)8 ResultSetOptions (org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions)8 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)8 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)6 ArrayList (java.util.ArrayList)5 OperatorTest (org.apache.drill.categories.OperatorTest)5 DrillException (org.apache.drill.common.exceptions.DrillException)5 BaseTest (org.apache.drill.test.BaseTest)5