use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanOuputSchema method testStrictProvidedSchemaWithWildcard.
@Test
public void testStrictProvidedSchemaWithWildcard() {
TupleMetadata providedSchema = new SchemaBuilder().add("a", // Projected, in reader
MinorType.INT).add("d", // Projected, not in reader
MinorType.BIGINT).add("e", // Not projected, not in reader
MinorType.BIGINT).buildSchema();
providedSchema.metadata("d").setDefaultValue("20");
providedSchema.metadata("e").setDefaultValue("30");
providedSchema.setProperty(TupleMetadata.IS_STRICT_SCHEMA_PROP, Boolean.TRUE.toString());
BaseScanFixtureBuilder builder = new BaseScanFixtureBuilder(fixture);
// Project schema only
builder.setProjection(RowSetTestUtils.projectAll());
builder.addReader(negotiator -> new MockSimpleReader(negotiator));
builder.builder.providedSchema(providedSchema);
builder.builder.nullType(Types.optional(MinorType.VARCHAR));
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).add("d", MinorType.BIGINT).add("e", MinorType.BIGINT).buildSchema();
// Initial schema
assertTrue(scan.buildSchema());
{
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).build();
RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
}
// Batch with defaults and null types
assertTrue(scan.next());
{
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, 20L, 30L).build();
RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
}
assertFalse(scan.next());
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestFixedReceiver method testFixedReceiver.
/**
* Test the standard string-to-type conversion using an ad-hoc conversion
* from the input type (the type used by the row set builder) to the output
* (vector) type.
*/
@Test
public void testFixedReceiver() {
// Create the provided and output schemas
TupleMetadata outputSchema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).add("int", MinorType.INT).add("bi", MinorType.BIGINT).add("fl", MinorType.FLOAT4).add("db", MinorType.FLOAT8).buildSchema();
// Create the scan
BaseScanFixtureBuilder builder = simpleBuilder(negotiator -> new MockReader(negotiator));
builder.builder.providedSchema(outputSchema);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Load test data using converters
assertTrue(scan.next());
// Build the expected vector without a type converter.
final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(11, 12, 13, 14L, 15.5F, 16.25D).addRow(127, 32757, Integer.MAX_VALUE, Long.MAX_VALUE, 10E6F, 10E200D).build();
// Compare
VectorContainer container = scan.batchAccessor().container();
RowSetUtilities.verify(expected, fixture.wrap(container));
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanEarlySchema method testEarlySchemaDataWithEof.
@Test
public void testEarlySchemaDataWithEof() {
// Create a mock reader, return two batches: one schema-only, another with data.
ReaderCreator creator = negotiator -> {
MockEarlySchemaReader reader = new MockEarlySchemaReader3(negotiator);
reader.batchLimit = 1;
return reader;
};
// Create the scan operator
ScanFixture scanFixture = simpleFixture(creator);
ScanOperatorExec scan = scanFixture.scanOp;
SingleRowSet expected = makeExpected();
RowSetComparison verifier = new RowSetComparison(expected);
// First batch: return schema.
assertTrue(scan.buildSchema());
assertEquals(0, scan.batchAccessor().rowCount());
// Next call, return with data.
assertTrue(scan.next());
verifier.verifyAndClearAll(fixture.wrap(scan.batchAccessor().container()));
// EOF
assertFalse(scan.next());
assertEquals(0, scan.batchAccessor().rowCount());
// Next again: no-op
assertFalse(scan.next());
scanFixture.close();
// Close again: no-op
scan.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanEarlySchema method testEOFOnSchema.
/**
* Test EOF on the first batch. Is allowed, but will result in the scan operator
* passing a null batch to the parent.
*/
@Test
public void testEOFOnSchema() {
// Create a mock reader, return two batches: one schema-only, another with data.
ReaderCreator creator = negotiator -> new EofOnOpenReader(negotiator);
ScanFixture scanFixture = simpleFixture(creator);
ScanOperatorExec scan = scanFixture.scanOp;
// EOF
assertFalse(scan.buildSchema());
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanEarlySchema method testMultipleReaders.
/**
* Test normal case with multiple readers. These return
* the same schema, so no schema change.
*/
@Test
public void testMultipleReaders() {
ReaderCreator creator1 = negotiator -> new EofOnOpenReader(negotiator);
ReaderCreator creator2 = negotiator -> {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
reader.batchLimit = 2;
return reader;
};
ReaderCreator creator3 = negotiator -> {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
reader.batchLimit = 2;
reader.startIndex = 100;
return reader;
};
ScanFixture scanFixture = simpleFixture(creator1, creator2, creator3);
ScanOperatorExec scan = scanFixture.scanOp;
// First batch, schema only.
assertTrue(scan.buildSchema());
assertEquals(1, scan.batchAccessor().schemaVersion());
scan.batchAccessor().release();
// Second batch.
assertTrue(scan.next());
assertEquals(1, scan.batchAccessor().schemaVersion());
verifyBatch(0, scan.batchAccessor().container());
// Third batch.
assertTrue(scan.next());
assertEquals(1, scan.batchAccessor().schemaVersion());
verifyBatch(20, scan.batchAccessor().container());
// Second reader. First batch includes data, no special first-batch
// handling for the second reader.
assertTrue(scan.next());
assertEquals(1, scan.batchAccessor().schemaVersion());
verifyBatch(100, scan.batchAccessor().container());
// Second batch from second reader.
assertTrue(scan.next());
assertEquals(1, scan.batchAccessor().schemaVersion());
verifyBatch(120, scan.batchAccessor().container());
// EOF
assertFalse(scan.next());
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
}
Aggregations