Search in sources :

Example 16 with SchemaNegotiator

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

the class TestScanLifecycleBasics method testEarlyEOF.

/**
 * Single reader, late schema, early EOF.
 * The scan never has a valid schema in this case.
 */
@Test
public void testEarlyEOF() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) throws EarlyEofException {
            return new NoDataReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertFalse(reader.open());
    reader.close();
    assertFalse(scan.hasOutputSchema());
    scan.close();
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) EarlyEofException(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader.EarlyEofException) 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 17 with SchemaNegotiator

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

the class TestScanLifecycleBasics method testEarlySchemaWithProjectNone.

@Test
public void testEarlySchemaWithProjectNone() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.projection(RowSetTestUtils.projectNone());
    builder.readerFactory(new SingleReaderFactory() {

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

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

the class TestScanLifecycleBasics method testNullReaderWithSchema.

/**
 * Single reader early schema, EOF on first next().
 * Since this is an early-schema reader, there is an output
 * schema even without any rows.
 */
@Test
public void testNullReaderWithSchema() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockEarlySchemaReader(negotiator, 0);
        }
    });
    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
    assertTrue(scan.hasOutputSchema());
    assertEquals(SCHEMA, scan.outputSchema());
    assertTrue(reader.next());
    VectorContainer result = reader.output();
    assertEquals(0, result.getRecordCount());
    result.zeroVectors();
    // Early schema with no additional columns discovered
    assertEquals(SCHEMA, scan.outputSchema());
    // But, no second batch.
    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) VectorContainer(org.apache.drill.exec.record.VectorContainer) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 19 with SchemaNegotiator

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

the class TestScanLifecycleTwoReaders method testTwoNullReaders.

/**
 * Two null readers: neither provides a valid scan schema.
 */
@Test
public void testTwoNullReaders() {
    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, 0);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyEmptyReader(scan);
    verifyEmptyReader(scan);
    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 20 with SchemaNegotiator

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

the class TestScanLifecycleTwoReaders method testColumnReorderingBA.

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

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

        @Override
        public ManagedReader secondReader(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    RowSet expected = fixture.rowSetBuilder(MockReorderedReader.READER_SCHEMA).addRow("barney", 30).addRow("betty", 40).build();
    RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
    assertFalse(reader.next());
    reader.close();
    reader = scan.nextReader();
    reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    expected = fixture.rowSetBuilder(MockReorderedReader.READER_SCHEMA).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) 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)

Aggregations

ScanLifecycleBuilder (org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)43 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator)43 ManagedReader (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader)42 EvfTest (org.apache.drill.categories.EvfTest)41 Test (org.junit.Test)41 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 VectorContainer (org.apache.drill.exec.record.VectorContainer)1