Search in sources :

Example 41 with ScanOperatorExec

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

the class TestScanBasics method testEarlyScanClose.

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

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
            reader.batchLimit = 2;
            return reader;
        }
    };
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    scan.batchAccessor().release();
    scanFixture.close();
    MockEarlySchemaReader reader = creator.reader();
    assertTrue(reader.closeCalled);
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 42 with ScanOperatorExec

use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec 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 43 with ScanOperatorExec

use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec 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 44 with ScanOperatorExec

use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec 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)

Example 45 with ScanOperatorExec

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

the class TestScanLateSchema method testLateSchemaLifecycleNoSchemaBatch.

@Test
public void testLateSchemaLifecycleNoSchemaBatch() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    ReaderCreator creator = negotiator -> {
        MockLateSchemaReader reader = new MockLateSchemaReader(negotiator);
        reader.batchLimit = 2;
        reader.returnDataOnFirst = true;
        return reader;
    };
    BaseScanFixtureBuilder builder = simpleBuilder(creator);
    builder.enableSchemaBatch = false;
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // 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());
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : ColumnBuilder(org.apache.drill.exec.record.metadata.ColumnBuilder) RowSetUtilities(org.apache.drill.test.rowSet.RowSetUtilities) Assert.assertTrue(org.junit.Assert.assertTrue) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) MaterializedField(org.apache.drill.exec.record.MaterializedField) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) DataMode(org.apache.drill.common.types.TypeProtos.DataMode) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) EvfTest(org.apache.drill.categories.EvfTest) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) Assert.assertEquals(org.junit.Assert.assertEquals) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) 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