Search in sources :

Example 46 with ScanOperatorExec

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

the class TestScanLateSchema method testLateSchemaLifecycleNoFile.

/**
 * Test a late-schema source that has no file information.
 * (Like a Hive or JDBC data source.)
 */
@Test
public void testLateSchemaLifecycleNoFile() {
    // 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 = false;
        return reader;
    };
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    // First batch: build schema. The reader helps: it returns an
    // empty first batch.
    assertTrue(scan.buildSchema());
    assertEquals(0, scan.batchAccessor().rowCount());
    // Create the expected result.
    SingleRowSet expected = makeExpected(20);
    RowSetComparison verifier = new RowSetComparison(expected);
    assertEquals(expected.batchSchema(), scan.batchAccessor().schema());
    // Next call, return with data.
    assertTrue(scan.next());
    verifier.verifyAndClearAll(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) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 47 with ScanOperatorExec

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

the class TestScanLateSchema method testNonEmptyFirstBatch.

/**
 * Test the case where the reader does not play the "first batch contains
 * only schema" game, and instead returns data. The Scan operator will
 * split the first batch into two: one with schema only, another with
 * data.
 */
@Test
public void testNonEmptyFirstBatch() {
    ReaderCreator creator = negotiator -> {
        MockLateSchemaReader reader = new MockLateSchemaReader(negotiator);
        reader.batchLimit = 2;
        reader.returnDataOnFirst = true;
        return reader;
    };
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    // First batch. The reader returns a non-empty batch. The scan
    // operator strips off the schema and returns just that.
    assertTrue(scan.buildSchema());
    SingleRowSet expected = makeExpected();
    assertEquals(expected.batchSchema(), scan.batchAccessor().schema());
    assertEquals(0, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    // Second batch. Returns the "look-ahead" batch returned by
    // the reader earlier.
    assertTrue(scan.next());
    RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    // Third batch, normal case.
    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) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 48 with ScanOperatorExec

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

the class TestScanLateSchema method testLateSchemaEarlyReaderClose.

/**
 * Test the case that a late schema reader is closed after discovering
 * schema, before any calls to next().
 */
@Test
public void testLateSchemaEarlyReaderClose() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    ObservableCreator creator = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockLateSchemaReader reader = new MockLateSchemaReader(negotiator);
            reader.batchLimit = 2;
            reader.returnDataOnFirst = false;
            return reader;
        }
    };
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    // Get the schema as above.
    assertTrue(scan.buildSchema());
    // No lookahead batch created.
    scanFixture.close();
    MockLateSchemaReader reader = creator.reader();
    assertEquals(1, reader.batchCount);
    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 49 with ScanOperatorExec

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

the class MockScanBatchCreator method extendedMockScan.

private CloseableRecordBatch extendedMockScan(FragmentContext context, MockSubScanPOP config, List<MockScanEntry> entries) {
    List<SchemaPath> projList = new LinkedList<>();
    projList.add(SchemaPath.STAR_COLUMN);
    // Create batch readers up front. Handy when we know there are
    // only one or two; else use an iterator and create them on the fly.
    final List<ManagedReader<SchemaNegotiator>> readers = new LinkedList<>();
    for (final MockTableDef.MockScanEntry e : entries) {
        readers.add(new ExtendedMockBatchReader(e));
    }
    // Limit the batch size to 10 MB, or whatever the operator definition
    // specified.
    int batchSizeBytes = 10 * 1024 * 1024;
    MockTableDef.MockScanEntry first = entries.get(0);
    if (first.getBatchSize() > 0) {
        batchSizeBytes = first.getBatchSize();
    }
    // Set the scan to allow the maximum row count, allowing
    // each reader to adjust the batch size smaller if desired.
    ScanFrameworkBuilder builder = new ScanFrameworkBuilder();
    builder.batchByteLimit(batchSizeBytes);
    builder.projection(projList);
    builder.setReaderFactory(new BasicScanFactory(readers.iterator()));
    ManagedScanFramework framework = new ManagedScanFramework(builder);
    return new OperatorRecordBatch(context, config, new ScanOperatorExec(framework, false), false);
}
Also used : ScanFrameworkBuilder(org.apache.drill.exec.physical.impl.scan.framework.ManagedScanFramework.ScanFrameworkBuilder) MockScanEntry(org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry) ManagedReader(org.apache.drill.exec.physical.impl.scan.framework.ManagedReader) LinkedList(java.util.LinkedList) BasicScanFactory(org.apache.drill.exec.physical.impl.scan.framework.BasicScanFactory) ManagedScanFramework(org.apache.drill.exec.physical.impl.scan.framework.ManagedScanFramework) SchemaPath(org.apache.drill.common.expression.SchemaPath) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) OperatorRecordBatch(org.apache.drill.exec.physical.impl.protocol.OperatorRecordBatch)

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