Search in sources :

Example 36 with ScanOperatorExec

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

the class TestFileScan method testFullProject.

/**
 * Exercise the major project operations: subset of table
 * columns, implicit, partition, missing columns, and output
 * order (and positions) different than table. These cases
 * are more fully test on lower level components; here we verify
 * that the components are wired up correctly.
 */
@Test
public void testFullProject() {
    ReaderCreator creator = negotiator -> {
        MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
        reader.batchLimit = 1;
        return reader;
    };
    // Select table and implicit columns.
    FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
    builder.setProjection("dir0", "b", "filename", "c", "suffix");
    builder.addReader(creator);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Expect data and implicit columns
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("dir0", MinorType.VARCHAR).addNullable("b", MinorType.VARCHAR).add("filename", MinorType.VARCHAR).addNullable("c", MinorType.INT).add("suffix", MinorType.VARCHAR).build();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(MOCK_DIR0, "fred", MOCK_FILE_NAME, null, MOCK_SUFFIX).addRow(MOCK_DIR0, "wilma", MOCK_FILE_NAME, null, MOCK_SUFFIX).build();
    // Schema should include implicit columns.
    assertTrue(scan.buildSchema());
    assertEquals(expected.container().getSchema(), scan.batchAccessor().schema());
    scan.batchAccessor().release();
    // Read one batch, should contain implicit columns
    assertTrue(scan.next());
    RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : RowSetUtilities(org.apache.drill.test.rowSet.RowSetUtilities) MetadataUtils(org.apache.drill.exec.record.metadata.MetadataUtils) Assert.assertTrue(org.junit.Assert.assertTrue) Types(org.apache.drill.common.types.Types) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) ScanFixture(org.apache.drill.exec.physical.impl.scan.v3.ScanFixture) Category(org.junit.experimental.categories.Category) MaterializedField(org.apache.drill.exec.record.MaterializedField) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) DataMode(org.apache.drill.common.types.TypeProtos.DataMode) 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) BaseMockBatchReader(org.apache.drill.exec.physical.impl.scan.v3.BaseMockBatchReader) ScanFixture(org.apache.drill.exec.physical.impl.scan.v3.ScanFixture) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 37 with ScanOperatorExec

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

the class TestFileScan method testMapProject.

@Test
public void testMapProject() {
    ReaderCreator creator = negotiator -> {
        MockMapReader reader = new MockMapReader(negotiator);
        reader.batchLimit = 1;
        return reader;
    };
    // Select one of the two map columns
    FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
    builder.setProjection("m1.a");
    builder.addReader(creator);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Expect data and implicit columns
    TupleMetadata expectedSchema = new SchemaBuilder().addMap("m1").add("a", MinorType.INT).resumeSchema().build();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addSingleCol(new Object[] { 10 }).addSingleCol(new Object[] { 20 }).build();
    assertTrue(scan.buildSchema());
    assertEquals(expected.container().getSchema(), scan.batchAccessor().schema());
    scan.batchAccessor().release();
    assertTrue(scan.next());
    RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : RowSetUtilities(org.apache.drill.test.rowSet.RowSetUtilities) MetadataUtils(org.apache.drill.exec.record.metadata.MetadataUtils) Assert.assertTrue(org.junit.Assert.assertTrue) Types(org.apache.drill.common.types.Types) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) ScanFixture(org.apache.drill.exec.physical.impl.scan.v3.ScanFixture) Category(org.junit.experimental.categories.Category) MaterializedField(org.apache.drill.exec.record.MaterializedField) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) DataMode(org.apache.drill.common.types.TypeProtos.DataMode) 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) BaseMockBatchReader(org.apache.drill.exec.physical.impl.scan.v3.BaseMockBatchReader) ScanFixture(org.apache.drill.exec.physical.impl.scan.v3.ScanFixture) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 38 with ScanOperatorExec

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

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

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

the class TestScanBasics method testEOFOnFirstOpen.

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

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) throws EarlyEofException {
            return new EofOnOpenReader(negotiator);
        }
    };
    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();
    assertFalse(scan.next());
    scanFixture.close();
}
Also used : 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