Search in sources :

Example 26 with RowBatchReader

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

the class TestScanLifecycleBasics method testLateSchemaWithProject.

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

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

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

the class TestScanLifecycleBasics method testEarlySchemaOneBatch.

/**
 * Test SELECT * from an early-schema table of (a, b)
 */
@Test
public void testEarlySchemaOneBatch() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    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());
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    // Early schema: so output schema is available after open
    assertEquals(SCHEMA, scan.outputSchema());
    assertTrue(reader.next());
    RowSetUtilities.verify(simpleExpected(0), 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 RowBatchReader

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

the class TestScanLifecycleBasics method testLateSchemaOneBatch.

/**
 * Single reader late schema, one batch.
 */
@Test
public void testLateSchemaOneBatch() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 1);
        }
    });
    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
    assertTrue(scan.hasOutputSchema());
    assertEquals(SCHEMA, scan.outputSchema());
    RowSetUtilities.verify(simpleExpected(0), 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 29 with RowBatchReader

use of org.apache.drill.exec.physical.impl.scan.RowBatchReader 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 30 with RowBatchReader

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

Aggregations

RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)51 Test (org.junit.Test)48 ManagedReader (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader)43 EvfTest (org.apache.drill.categories.EvfTest)42 ScanLifecycleBuilder (org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)37 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator)37 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)28 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