Search in sources :

Example 31 with ScanLifecycleBuilder

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

the class TestScanLifecycleTwoReaders method testLateSchemaTypeConflict.

/**
 * SELECT * from two readers: both (a, b), but with a conflicting
 * type for the column b. The reader fail will with a type conflict.
 */
@Test
public void testLateSchemaTypeConflict() {
    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 MockLateSchemaTypeConflictReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyStandardReader(scan, 0);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    try {
        reader.next();
        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 32 with ScanLifecycleBuilder

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

the class TestScanLifecycleTwoReaders method testModeConflict.

/**
 * SELECT * from two readers: both (a, b), but with a conflicting
 * type for the column b. The reader fail will with a type conflict.
 * We could possibly try to handle a NULLABLE --> NON NULLABLE conflict,
 * but there does not yet appear to be a compelling case for doing so.
 */
@Test
public void testModeConflict() {
    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 MockModeConflictReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyStandardReader(scan, 0);
    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 33 with ScanLifecycleBuilder

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

the class TestScanLifecycleTwoReaders method testExpandingSchemaDisallowingSchemaChange.

/**
 * SELECT * FROM two readers, one (a, b), the other (a, b, c).
 * With schema change disabled, the third column is ignored in the
 * second reader: the first reader "fixes" projection to just (a, b)
 * even though projection started as wildcard.
 * <p>
 * We can argue if this behavior is correct. We know most operators,
 * and no ODBC or JDBC client can handle schema change. So, our other
 * options are do the schema change anyway (the above test), fail, or
 * this choice, which is to try to muddle though. The correct solution
 * is to provide a schema (tested elsewhere.)
 */
@Test
public void testExpandingSchemaDisallowingSchemaChange() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.allowSchemaChange(false);
    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(SCHEMA).addRow(101, "wilma").addRow(102, "betty").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 34 with ScanLifecycleBuilder

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

the class TestScanLifecycleTwoReaders method testValidThenNullReader.

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

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

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

Example 35 with ScanLifecycleBuilder

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

the class TestScanLifecycleTwoReaders method testEarlySchemaTypeConflict.

/**
 * SELECT * from two readers: both (a, b), but with a conflicting
 * type for the column b. The reader fail will with a type conflict.
 */
@Test
public void testEarlySchemaTypeConflict() {
    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 MockEarlySchemaTypeConflictReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyStandardReader(scan, 0);
    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)

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