Search in sources :

Example 41 with ManagedReader

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

the class TestScanLifecycleTwoReaders method testColumnReorderingAB.

/**
 * {@code SELECT * FROM} (a, b) then (b,a). The order of the first
 * table drives the order of the results.
 */
@Test
public void testColumnReorderingAB() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.readerFactory(new TwoReaderFactory() {

        @Override
        public ManagedReader firstReader(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 1);
        }

        @Override
        public ManagedReader secondReader(SchemaNegotiator negotiator) {
            return new MockReorderedReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyStandardReader(scan, 0);
    RowBatchReader reader = scan.nextReader();
    reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    RowSet expected = fixture.rowSetBuilder(SCHEMA).addRow(30, "barney").addRow(40, "betty").build();
    RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
    assertFalse(reader.next());
    reader.close();
    scan.close();
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator) ScanLifecycleBuilder(org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 42 with ManagedReader

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

the class TestReaderErrors method testCloseError.

@Test
public void testCloseError() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.errorContext(b -> b.addContext("Scan context"));
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new FailingReader(negotiator, "close");
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertFalse(reader.next());
    try {
        reader.close();
        fail();
    } catch (UserException e) {
    // Expected
    }
    scan.close();
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator) UserException(org.apache.drill.common.exceptions.UserException) ScanLifecycleBuilder(org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder) EvfTest(org.apache.drill.categories.EvfTest) Test(org.junit.Test)

Example 43 with ManagedReader

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

the class TestScanLifecycleLimit method setupScan.

private Pair<TwoReaderFactory, ScanLifecycle> setupScan(long limit) {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.projection(RowSetTestUtils.projectList("a"));
    TwoReaderFactory factory = new TwoReaderFactory() {

        @Override
        public ManagedReader firstReader(SchemaNegotiator negotiator) {
            return new Mock50RowReader(negotiator);
        }

        @Override
        public ManagedReader secondReader(SchemaNegotiator negotiator) {
            return new Mock50RowReader(negotiator);
        }
    };
    builder.readerFactory(factory);
    builder.limit(limit);
    return Pair.of(factory, buildScan(builder));
}
Also used : SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator) ScanLifecycleBuilder(org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)

Example 44 with ManagedReader

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

the class TestScanLifecycleTwoReaders method testTwoValidReaders.

@Test
public void testTwoValidReaders() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.readerFactory(new TwoReaderFactory() {

        @Override
        public ManagedReader firstReader(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 1);
        }

        @Override
        public ManagedReader secondReader(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyStandardReader(scan, 0);
    verifyStandardReader(scan, 0);
    scan.close();
}
Also used : ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator) ScanLifecycleBuilder(org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 45 with ManagedReader

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

the class TestScanLifecycleTwoReaders method testShrinkingSchemaWithConflict.

/**
 * Shrinking schema, as above. Explicit projection:<pre><code>
 * SELECT a, b FROM (a) then (a,b)
 * </code></pre><p>
 * But choose a missing column type (the default
 * Nullable INT) in the first reader that will conflict with the actual column type
 * (VARCHAR) in the second.
 */
@Test
public void testShrinkingSchemaWithConflict() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.projection(RowSetTestUtils.projectList("a", "b"));
    builder.readerFactory(new TwoReaderFactory() {

        @Override
        public ManagedReader firstReader(SchemaNegotiator negotiator) {
            return new MockSingleColReader(negotiator);
        }

        @Override
        public ManagedReader secondReader(SchemaNegotiator negotiator) {
            return new MockEarlySchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    reader.output().clear();
    assertFalse(reader.next());
    reader.close();
    reader = scan.nextReader();
    try {
        reader.open();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("conflict"));
    }
    reader.close();
    scan.close();
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator) UserException(org.apache.drill.common.exceptions.UserException) ScanLifecycleBuilder(org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Aggregations

ManagedReader (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader)48 EvfTest (org.apache.drill.categories.EvfTest)47 Test (org.junit.Test)47 RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)43 ScanLifecycleBuilder (org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)43 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator)43 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)22 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)13 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)13 UserException (org.apache.drill.common.exceptions.UserException)12 DummyFileWork (org.apache.drill.exec.physical.impl.scan.v3.file.BaseFileScanTest.DummyFileWork)6 BaseTestScanLifecycle (org.apache.drill.exec.physical.impl.scan.v3.lifecycle.BaseTestScanLifecycle)6 ScanLifecycle (org.apache.drill.exec.physical.impl.scan.v3.lifecycle.ScanLifecycle)6 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 EarlyEofException (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader.EarlyEofException)1 VectorContainer (org.apache.drill.exec.record.VectorContainer)1 Path (org.apache.hadoop.fs.Path)1