Search in sources :

Example 6 with ManagedReader

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

the class TestMockRowReader method testBatchSize.

/**
 * Verify limit on individual batch size (limiting row count per batch).
 */
@Test
public void testBatchSize() {
    int rowCount = 20;
    int batchSize = 10;
    MockTableDef.MockColumn[] cols = new MockTableDef.MockColumn[] { new MockTableDef.MockColumn("a", MinorType.INT, DataMode.REQUIRED, null, null, null, null, null, null), new MockTableDef.MockColumn("b", MinorType.VARCHAR, DataMode.REQUIRED, 10, null, null, null, null, null) };
    MockTableDef.MockScanEntry entry = new MockTableDef.MockScanEntry(rowCount, true, batchSize, null, cols);
    MockSubScanPOP config = new MockSubScanPOP("dummy", true, Collections.singletonList(entry));
    ManagedReader<SchemaNegotiator> reader = new ExtendedMockBatchReader(entry);
    List<ManagedReader<SchemaNegotiator>> readers = Collections.singletonList(reader);
    // Create options and the scan operator
    ScanFixture mockBatch = buildScan(config, readers);
    ScanOperatorExec scan = mockBatch.scanOp;
    // First batch: build schema. The reader helps: it returns an
    // empty first batch.
    assertTrue(scan.buildSchema());
    assertEquals(0, scan.batchAccessor().rowCount());
    // Next call, return with data, limited by batch size.
    assertTrue(scan.next());
    assertEquals(batchSize, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    assertTrue(scan.next());
    assertEquals(batchSize, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    // EOF
    assertFalse(scan.next());
    mockBatch.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) ManagedReader(org.apache.drill.exec.physical.impl.scan.framework.ManagedReader) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 7 with ManagedReader

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

ManagedReader (org.apache.drill.exec.physical.impl.scan.framework.ManagedReader)7 ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)6 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)5 ScanFixture (org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)5 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator)5 SubOperatorTest (org.apache.drill.test.SubOperatorTest)5 Test (org.junit.Test)5 BatchSchema (org.apache.drill.exec.record.BatchSchema)3 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)3 BasicScanFactory (org.apache.drill.exec.physical.impl.scan.framework.BasicScanFactory)2 ManagedScanFramework (org.apache.drill.exec.physical.impl.scan.framework.ManagedScanFramework)2 ScanFrameworkBuilder (org.apache.drill.exec.physical.impl.scan.framework.ManagedScanFramework.ScanFrameworkBuilder)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 BatchAccessor (org.apache.drill.exec.physical.impl.protocol.BatchAccessor)1 OperatorRecordBatch (org.apache.drill.exec.physical.impl.protocol.OperatorRecordBatch)1 MockScanEntry (org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry)1