use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestFileScan method testEmptyProject.
@Test
public void testEmptyProject() {
ReaderCreator creator = negotiator -> {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
reader.batchLimit = 1;
return reader;
};
// Select no columns
FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
builder.setProjection();
builder.addReader(creator);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Expect data and implicit columns
TupleMetadata expectedSchema = new SchemaBuilder().build();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow().addRow().build();
// Schema should include implicit columns.
assertTrue(scan.buildSchema());
assertEquals(expected.container().getSchema(), scan.batchAccessor().schema());
scan.batchAccessor().release();
// Read one batch, should contain implicit columns
assertTrue(scan.next());
RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
// EOF
assertFalse(scan.next());
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanOuputSchema method testProvidedSchema.
/**
* Test an output schema.
* <ul>
* <li>Column a has an input type of VARCHAR, and output type of INT,
* and the framework will insert an implicit conversion.</li>
* <li>Column b has an output type of BIGINT, is projected, but is
* not provided by the reader. It will use the default value of 20L.</li>
* <li>Column c is not in the output schema, is not provided by the
* reader, but is projected, so it will use the default null type
* of VARCHAR, with a null value.</li>
* </ul>
*/
@Test
public void testProvidedSchema() {
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");
BaseScanFixtureBuilder builder = new BaseScanFixtureBuilder(fixture);
builder.setProjection(new String[] { "a", "b", "d", "f" });
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("b", MinorType.VARCHAR).add("d", MinorType.BIGINT).addNullable("f", MinorType.VARCHAR).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, "foo", 20L, null).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 TestScanEarlySchema method testEOFOnFirstBatch.
@Test
public void testEOFOnFirstBatch() {
ReaderCreator creator = negotiator -> {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
reader.batchLimit = 0;
return reader;
};
ScanFixture scanFixture = simpleFixture(creator);
ScanOperatorExec scan = scanFixture.scanOp;
assertTrue(scan.buildSchema());
// EOF. Returns a single empty batch with early schema
// in order to provide an empty result set.
assertTrue(scan.next());
assertEquals(0, scan.batchAccessor().rowCount());
RowSetUtilities.verify(RowSetBuilder.emptyBatch(fixture.allocator(), expectedSchema()), 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 TestScanLimit method testLimit0.
/**
* LIMIT 0, to obtain only the schema.
*/
@Test
public void testLimit0() {
TestFixture fixture = new TestFixture(0);
ScanOperatorExec scan = fixture.scan;
assertTrue(scan.buildSchema());
BatchAccessor batch = scan.batchAccessor();
assertEquals(0, batch.rowCount());
assertEquals(1, batch.schema().getFieldCount());
batch.release();
// No second batch or second reader
assertFalse(scan.next());
fixture.close();
// Only the first of the two readers were created.
assertEquals(1, fixture.createCount());
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanLimit method testLimitOnEOF.
/**
* LIMIT 100, at EOF of the first reader.
*/
@Test
public void testLimitOnEOF() {
TestFixture fixture = new TestFixture(100);
ScanOperatorExec scan = fixture.scan;
assertTrue(scan.buildSchema());
assertTrue(scan.next());
BatchAccessor batch = scan.batchAccessor();
assertEquals(50, batch.rowCount());
batch.release();
assertTrue(scan.next());
batch = scan.batchAccessor();
assertEquals(50, batch.rowCount());
batch.release();
// No second reader
assertFalse(scan.next());
fixture.close();
scan.close();
// Only the first of the two readers were created.
assertEquals(1, fixture.createCount());
}
Aggregations