use of org.apache.drill.exec.physical.impl.scan.RowBatchReader 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.RowBatchReader in project drill by apache.
the class TestScanLifecycleSchema method testDefinedSchemaSupersset.
/**
* The defined schema is a superset of the reader's schema; the
* defined schema defines the missing column type.
*/
@Test
public void testDefinedSchemaSupersset() {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.definedSchema(SCHEMA);
builder.readerFactory(new SingleReaderFactory() {
@Override
public ManagedReader next(SchemaNegotiator negotiator) {
return new MockSingleColReader(negotiator);
}
});
ScanLifecycle scan = buildScan(builder);
RowBatchReader reader = scan.nextReader();
assertTrue(reader.open());
assertEquals(SCHEMA, scan.outputSchema());
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.RowBatchReader in project drill by apache.
the class TestScanLifecycleSchema method testDefinedSchemaConflict.
/**
* Reader produces a schema which conflicts with the defined schema.
* The defined schema should be something the reader can implement; so
* it is an error if the reader does not do so.
*/
@Test
public void testDefinedSchemaConflict() {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.definedSchema(SCHEMA);
builder.readerFactory(new SingleReaderFactory() {
@Override
public ManagedReader next(SchemaNegotiator negotiator) {
return new MockEarlySchemaTypeConflictReader(negotiator);
}
});
ScanLifecycle scan = buildScan(builder);
RowBatchReader reader = scan.nextReader();
try {
reader.open();
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains("conflict"));
}
reader.close();
scan.close();
}
use of org.apache.drill.exec.physical.impl.scan.RowBatchReader in project drill by apache.
the class BaseTestScanLifecycle method verifyStandardReader.
protected void verifyStandardReader(ScanLifecycle scan, int offset) {
RowBatchReader reader = scan.nextReader();
reader = scan.nextReader();
assertTrue(reader.open());
assertTrue(reader.next());
RowSetUtilities.verify(simpleExpected(0), fixture.wrap(reader.output()));
assertFalse(reader.next());
reader.close();
}
use of org.apache.drill.exec.physical.impl.scan.RowBatchReader in project drill by apache.
the class TestScanLifecycleBasics method testEarlySchemaSubset.
/**
* Test SELECT a FROM table(a, b)
*/
@Test
public void testEarlySchemaSubset() {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.projection(RowSetTestUtils.projectList("a"));
builder.readerFactory(new SingleReaderFactory() {
@Override
public ManagedReader next(SchemaNegotiator negotiator) {
return new MockEarlySchemaReader(negotiator, 1);
}
});
ScanLifecycle scan = buildScan(builder);
assertSame(ProjectionType.SOME, scan.schemaTracker().projectionType());
RowBatchReader reader = scan.nextReader();
assertTrue(reader.open());
// Early schema: so output schema is available after open
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).build();
assertEquals(expectedSchema, scan.outputSchema());
assertTrue(reader.next());
RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10).addRow(20).build();
RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
assertFalse(reader.next());
reader.close();
scan.close();
}
Aggregations