Search in sources :

Example 26 with ScanLifecycleBuilder

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

the class TestScanLifecycleBasics method testEarlySchemaReorder.

/**
 * Test SELECT b, a FROM table(a, b)
 */
@Test
public void testEarlySchemaReorder() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.projection(RowSetTestUtils.projectList("b", "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().addNullable("b", MinorType.VARCHAR).add("a", MinorType.INT).build();
    assertEquals(expectedSchema, scan.outputSchema());
    assertTrue(reader.next());
    RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow("fred", 10).addRow("wilma", 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)

Example 27 with ScanLifecycleBuilder

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

the class TestScanLifecycleBasics method testLateSchemaTwoBatches.

@Test
public void testLateSchemaTwoBatches() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 2);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    assertSame(ProjectionType.ALL, scan.schemaTracker().projectionType());
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    // Late schema: so no output schema is available after open
    assertFalse(scan.hasOutputSchema());
    assertTrue(reader.next());
    // Late schema, output schema available after first batch
    assertEquals(SCHEMA, scan.outputSchema());
    RowSetUtilities.verify(simpleExpected(0), fixture.wrap(reader.output()));
    assertTrue(reader.next());
    RowSetUtilities.verify(simpleExpected(1), 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) 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 28 with ScanLifecycleBuilder

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

the class TestScanLifecycleBasics method testEarlySchemaEmptyWithProject.

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

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockEmptySchemaReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    // Early schema: so output schema is available after open
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("a", MinorType.INT).build();
    assertEquals(expectedSchema, scan.outputSchema());
    assertTrue(reader.next());
    RowSet expected = fixture.rowSetBuilder(expectedSchema).addSingleCol(null).addSingleCol(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 29 with ScanLifecycleBuilder

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

the class TestScanLifecycleBasics method testNoReaders.

/**
 * Simplest possible do-nothing, default config case.
 * Scan produces no valid schema.
 */
@Test
public void testNoReaders() {
    ScanLifecycle scan = buildScan(new ScanLifecycleBuilder());
    assertNull(scan.nextReader());
    assertFalse(scan.hasOutputSchema());
    scan.close();
}
Also used : ScanLifecycleBuilder(org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 30 with ScanLifecycleBuilder

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

the class TestScanLifecycleBasics method testNullReader.

/**
 * Single reader empty schema, EOF on first next().
 * Since both no schema and no rows, we assume this to be a
 * null (not empty) result set, so no output schema.
 */
@Test
public void testNullReader() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 0);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertFalse(reader.next());
    assertFalse(scan.hasOutputSchema());
    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) 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