Search in sources :

Example 36 with RowBatchReader

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

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

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

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

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

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