Search in sources :

Example 1 with ScanOperatorExec

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

the class TestScanBasics 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) 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 2 with ScanOperatorExec

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

the class TestScanBasics method testExceptionOnFirstNext.

@Test
public void testExceptionOnFirstNext() {
    ObservableCreator creator = new ObservableCreator() {

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

                @Override
                public boolean next() {
                    // Load some data
                    super.next();
                    throw new IllegalStateException(ERROR_MSG);
                }
            };
            reader.batchLimit = 2;
            return reader;
        }
    };
    ScanFixture scanFixture = simpleFixture(creator);
    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);
    }
    assertEquals(0, scan.batchAccessor().rowCount());
    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 3 with ScanOperatorExec

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

the class TestScanBasics method testUserExceptionOnFirstNext.

@Test
public void testUserExceptionOnFirstNext() {
    ObservableCreator creator = new ObservableCreator() {

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

                @Override
                public boolean next() {
                    // Load some data
                    super.next();
                    throw UserException.dataReadError().message(ERROR_MSG).build(logger);
                }
            };
            reader.batchLimit = 2;
            return reader;
        }
    };
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    // EOF
    try {
        scan.next();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertNull(e.getCause());
    }
    assertEquals(0, scan.batchAccessor().rowCount());
    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 4 with ScanOperatorExec

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

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

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
            reader.batchLimit = 0;
            return reader;
        }
    };
    ObservableCreator creator2 = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
            reader.batchLimit = 0;
            return reader;
        }
    };
    ScanFixture scanFixture = simpleFixture(creator1, creator2);
    ScanOperatorExec scan = scanFixture.scanOp;
    // EOF
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    VectorContainer container = scan.batchAccessor().container();
    assertEquals(0, container.getRecordCount());
    assertEquals(2, container.getNumberOfColumns());
    assertEquals(0, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    MockEarlySchemaReader reader1 = creator1.reader();
    assertTrue(reader1.closeCalled);
    MockEarlySchemaReader reader2 = creator2.reader();
    assertTrue(reader2.closeCalled);
    assertFalse(scan.next());
    scanFixture.close();
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) VectorContainer(org.apache.drill.exec.record.VectorContainer) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 5 with ScanOperatorExec

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

the class TestScanBasics method testUserExceptionOnSecondNext.

@Test
public void testUserExceptionOnSecondNext() {
    ObservableCreator creator = new ObservableCreator() {

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

                @Override
                public boolean next() {
                    // Load some data
                    boolean result = super.next();
                    if (batchCount == 2) {
                        throw UserException.dataReadError().message(ERROR_MSG).build(logger);
                    }
                    return result;
                }
            };
            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();
    try {
        scan.next();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertNull(e.getCause());
    }
    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)

Aggregations

ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)49 Test (org.junit.Test)47 EvfTest (org.apache.drill.categories.EvfTest)35 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)22 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)19 RowSetUtilities (org.apache.drill.test.rowSet.RowSetUtilities)16 Assert.assertEquals (org.junit.Assert.assertEquals)16 Assert.assertFalse (org.junit.Assert.assertFalse)16 Assert.assertTrue (org.junit.Assert.assertTrue)16 Category (org.junit.experimental.categories.Category)16 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)13 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)12 DataMode (org.apache.drill.common.types.TypeProtos.DataMode)11 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)11 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)11 MaterializedField (org.apache.drill.exec.record.MaterializedField)11 UserException (org.apache.drill.common.exceptions.UserException)9 BatchAccessor (org.apache.drill.exec.physical.impl.protocol.BatchAccessor)7 ManagedReader (org.apache.drill.exec.physical.impl.scan.framework.ManagedReader)6 ColumnBuilder (org.apache.drill.exec.record.metadata.ColumnBuilder)6