use of org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator 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();
}
use of org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator 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();
}
use of org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator 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();
}
use of org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator 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();
}
use of org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator 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();
}
Aggregations