use of org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator in project drill by apache.
the class TestScanLifecycleTwoReaders method testExpandingSchemaAllowingSchemaChange.
/**
* SELECT * FROM two readers, one (a, b), the other (a, b, c).
* With schema change enabled, the third column shows up only
* in the second batch, forcing a schema change downstream.
*/
@Test
public void testExpandingSchemaAllowingSchemaChange() {
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 MockThreeColReader(negotiator);
}
});
ScanLifecycle scan = buildScan(builder);
verifyStandardReader(scan, 0);
RowBatchReader reader = scan.nextReader();
assertTrue(reader.open());
assertTrue(reader.next());
RowSet expected = fixture.rowSetBuilder(MockThreeColReader.READER_SCHEMA).addRow(101, "wilma", 1001).addRow(102, "betty", 1002).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 TestScanLifecycleTwoReaders method doTestShrinkingSchema.
private void doTestShrinkingSchema(boolean allowSchemaChange) {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.allowSchemaChange(allowSchemaChange);
builder.readerFactory(new TwoReaderFactory() {
@Override
public ManagedReader firstReader(SchemaNegotiator negotiator) {
return new MockLateSchemaReader(negotiator, 1);
}
@Override
public ManagedReader secondReader(SchemaNegotiator negotiator) {
return new MockSingleColReader(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, null).addRow(102, 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 TestScanLifecycleTwoReaders method testNullThenValidReader.
@Test
public void testNullThenValidReader() {
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, 1);
}
});
ScanLifecycle scan = buildScan(builder);
verifyEmptyReader(scan);
verifyStandardReader(scan, 0);
scan.close();
}
use of org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator in project drill by apache.
the class TestScanLifecycleBasics method testLateSchemaWithCustomType.
/**
* Test SELECT * from an early-schema table of () (that is,
* a schema that consists of zero columns.
*/
@Test
public void testLateSchemaWithCustomType() {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.projection(RowSetTestUtils.projectList("a", "c"));
builder.nullType(Types.optional(MinorType.VARCHAR));
builder.readerFactory(new SingleReaderFactory() {
@Override
public ManagedReader next(SchemaNegotiator negotiator) {
return new MockLateSchemaReader(negotiator, 1);
}
});
ScanLifecycle scan = buildScan(builder);
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.VARCHAR).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();
}
use of org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator in project drill by apache.
the class TestScanLifecycleSchema method testProvidedSchemaSimple.
/**
* Simplest provided schema case: the defined schema agrees
* with the the schema the reader will produce. The provided schema
* is separate from the project list.
*/
@Test
public void testProvidedSchemaSimple() {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.providedSchema(SCHEMA);
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());
verifyStandardReader(scan, 0);
scan.close();
}
Aggregations