Search in sources :

Example 11 with ScanLifecycleBuilder

use of org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder 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)

Example 12 with ScanLifecycleBuilder

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

the class TestScanLifecycleSchema method testDefinedSchemaSupersset.

/**
 * The defined schema is a superset of the reader's schema; the
 * defined schema defines the missing column type.
 */
@Test
public void testDefinedSchemaSupersset() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.definedSchema(SCHEMA);
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockSingleColReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertEquals(SCHEMA, scan.outputSchema());
    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) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 13 with ScanLifecycleBuilder

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

the class TestScanLifecycleSchema method testDefinedSchemaConflict.

/**
 * Reader produces a schema which conflicts with the defined schema.
 * The defined schema should be something the reader can implement; so
 * it is an error if the reader does not do so.
 */
@Test
public void testDefinedSchemaConflict() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.definedSchema(SCHEMA);
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockEarlySchemaTypeConflictReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader 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)

Example 14 with ScanLifecycleBuilder

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

the class TestScanLifecycleSchema method testDefinedSchemaSimple.

/**
 * Simplest defined schema case: the defined schema agrees
 * with the the schema the reader will produce. The defined schema
 * implies the project list, which is not visible here.
 */
@Test
public void testDefinedSchemaSimple() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.definedSchema(SCHEMA);
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockEarlySchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    // Projection defaults to SELECT *, but defined schema
    // overrides that setting.
    assertSame(ProjectionType.SOME, 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)

Example 15 with ScanLifecycleBuilder

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

the class TestScanLifecycleBasics method testEarlySchemaSubset.

/**
 * Test SELECT a FROM table(a, b)
 */
@Test
public void testEarlySchemaSubset() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.projection(RowSetTestUtils.projectList("a"));
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockEarlySchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    assertSame(ProjectionType.SOME, scan.schemaTracker().projectionType());
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    // Early schema: so output schema is available after open
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).build();
    assertEquals(expectedSchema, scan.outputSchema());
    assertTrue(reader.next());
    RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10).addRow(20).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)

Aggregations

ScanLifecycleBuilder (org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)45 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator)43 EvfTest (org.apache.drill.categories.EvfTest)42 ManagedReader (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader)42 Test (org.junit.Test)42 RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)37 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)18 UserException (org.apache.drill.common.exceptions.UserException)11 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)9 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)9 EarlyEofException (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader.EarlyEofException)1 ResultSetLoaderImpl (org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl)1 ResultSetOptionBuilder (org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder)1 VectorContainer (org.apache.drill.exec.record.VectorContainer)1