Search in sources :

Example 6 with ScanLifecycle

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

the class TestScanLifecycleTwoReaders method testExpandingSchemaAllowingSchemaChange.

/**
 * SELECT * FROM two readers, one (a, b), the other (a, b, c).
 * With schema change enabled, the third column shows up only
 * in the second batch, forcing a schema change downstream.
 */
@Test
public void testExpandingSchemaAllowingSchemaChange() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.allowSchemaChange(true);
    builder.readerFactory(new TwoReaderFactory() {

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

        @Override
        public ManagedReader secondReader(SchemaNegotiator negotiator) {
            return new MockThreeColReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyStandardReader(scan, 0);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    RowSet expected = fixture.rowSetBuilder(MockThreeColReader.READER_SCHEMA).addRow(101, "wilma", 1001).addRow(102, "betty", 1002).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 7 with ScanLifecycle

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

the class TestScanLifecycleTwoReaders method doTestShrinkingSchema.

private void doTestShrinkingSchema(boolean allowSchemaChange) {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.allowSchemaChange(allowSchemaChange);
    builder.readerFactory(new TwoReaderFactory() {

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

        @Override
        public ManagedReader secondReader(SchemaNegotiator negotiator) {
            return new MockSingleColReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyStandardReader(scan, 0);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    RowSet expected = fixture.rowSetBuilder(SCHEMA).addRow(101, null).addRow(102, null).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)

Example 8 with ScanLifecycle

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

the class TestScanLifecycleTwoReaders method testNullThenValidReader.

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

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

        @Override
        public ManagedReader secondReader(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyEmptyReader(scan);
    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 9 with ScanLifecycle

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

the class TestScanLifecycleBasics method testLateSchemaWithCustomType.

/**
 * Test SELECT * from an early-schema table of () (that is,
 * a schema that consists of zero columns.
 */
@Test
public void testLateSchemaWithCustomType() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.projection(RowSetTestUtils.projectList("a", "c"));
    builder.nullType(Types.optional(MinorType.VARCHAR));
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    // Late schema: so output schema is available after next()
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("c", MinorType.VARCHAR).build();
    assertEquals(expectedSchema, scan.outputSchema());
    RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, null).addRow(20, null).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) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) 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 10 with ScanLifecycle

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

the class TestScanLifecycleSchema method testProvidedSchemaSimple.

/**
 * Simplest provided schema case: the defined schema agrees
 * with the the schema the reader will produce. The provided schema
 * is separate from the project list.
 */
@Test
public void testProvidedSchemaSimple() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.providedSchema(SCHEMA);
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockEarlySchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    assertSame(ProjectionType.ALL, scan.schemaTracker().projectionType());
    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)

Aggregations

EvfTest (org.apache.drill.categories.EvfTest)48 ManagedReader (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader)48 Test (org.junit.Test)48 ScanLifecycleBuilder (org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)44 RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)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