use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.
the class TestColumnsArrayFramework method testColumnsProjection.
/**
* Test projecting just the `columns` column.
*/
@Test
public void testColumnsProjection() {
// Create a mock reader, return two batches: one schema-only, another with data.
DummyColumnsReader reader = new DummyColumnsReader(new SchemaBuilder().addArray(ColumnsScanFramework.COLUMNS_COL, MinorType.VARCHAR).buildSchema());
// Create the scan operator
ColumnsScanFixtureBuilder builder = new ColumnsScanFixtureBuilder();
builder.setProjection(RowSetTestUtils.projectList(ColumnsScanFramework.COLUMNS_COL));
builder.addReader(reader);
builder.builder.requireColumnsArray(true);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Start the one and only reader, and check the columns
// schema info.
assertTrue(scan.buildSchema());
assertNotNull(reader.negotiator);
assertTrue(reader.negotiator.columnsArrayProjected());
assertNull(reader.negotiator.projectedIndexes());
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.
the class TestFileScanFramework method testEmptyProject.
@Test
public void testEmptyProject() {
MockEarlySchemaReader reader = new MockEarlySchemaReader();
reader.batchLimit = 1;
// Select no columns
FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
builder.setProjection();
builder.addReader(reader);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Expect data and implicit columns
BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(new SchemaBuilder()).build();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow().addRow().build();
// Schema should include implicit columns.
assertTrue(scan.buildSchema());
assertEquals(expectedSchema, 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.ScanTestUtils.ScanFixture in project drill by apache.
the class TestFileScanFramework method testMapProject.
@Test
public void testMapProject() {
MockMapReader reader = new MockMapReader();
reader.batchLimit = 1;
// Select one of the two map columns
FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
builder.setProjection("m1.a");
builder.addReader(reader);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Expect data and implicit columns
SchemaBuilder schemaBuilder = new SchemaBuilder().addMap("m1").add("a", MinorType.INT).resumeSchema();
BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addSingleCol(new Object[] { 10 }).addSingleCol(new Object[] { 20 }).build();
assertTrue(scan.buildSchema());
assertEquals(expectedSchema, scan.batchAccessor().schema());
scan.batchAccessor().release();
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.ScanTestUtils.ScanFixture in project drill by apache.
the class TestFileScanFramework method testFullProject.
/**
* Exercise the major project operations: subset of table
* columns, implicit, partition, missing columns, and output
* order (and positions) different than table. These cases
* are more fully test on lower level components; here we verify
* that the components are wired up correctly.
*/
@Test
public void testFullProject() {
MockEarlySchemaReader reader = new MockEarlySchemaReader();
reader.batchLimit = 1;
// Select table and implicit columns.
FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
builder.setProjection("dir0", "b", "filename", "c", "suffix");
builder.addReader(reader);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Expect data and implicit columns
SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("dir0", MinorType.VARCHAR).addNullable("b", MinorType.VARCHAR, 10).add("filename", MinorType.VARCHAR).addNullable("c", MinorType.INT).add("suffix", MinorType.VARCHAR);
BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(MOCK_DIR0, "fred", MOCK_FILE_NAME, null, MOCK_SUFFIX).addRow(MOCK_DIR0, "wilma", MOCK_FILE_NAME, null, MOCK_SUFFIX).build();
// Schema should include implicit columns.
assertTrue(scan.buildSchema());
assertEquals(expectedSchema, 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.ScanTestUtils.ScanFixture in project drill by apache.
the class TestScanOperExecSmoothing method testSchemaSmoothing.
/**
* Test the ability of the scan operator to "smooth" out schema changes
* by reusing the type from a previous reader, if known. That is,
* given three readers:<br>
* (a, b)<br>
* (b)<br>
* (a, b)<br>
* Then the type of column a should be preserved for the second reader that
* does not include a. This works if a is nullable. If so, a's type will
* be used for the empty column, rather than the usual nullable int.
* <p>
* Full testing of smoothing is done in
* {#link TestScanProjector}. Here we just make sure that the
* smoothing logic is available via the scan operator.
*/
@Test
public void testSchemaSmoothing() {
// Reader returns (a, b)
MockEarlySchemaReader reader1 = new MockEarlySchemaReader();
reader1.batchLimit = 1;
// Reader returns (a)
MockOneColEarlySchemaReader reader2 = new MockOneColEarlySchemaReader();
reader2.batchLimit = 1;
reader2.startIndex = 100;
// Reader returns (a, b)
MockEarlySchemaReader reader3 = new MockEarlySchemaReader();
reader3.batchLimit = 1;
reader3.startIndex = 200;
BaseScanFixtureBuilder builder = new BaseScanFixtureBuilder();
builder.setProjection(new String[] { "a", "b" });
builder.addReader(reader1);
builder.addReader(reader2);
builder.addReader(reader3);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Schema based on (a, b)
assertTrue(scan.buildSchema());
assertEquals(1, scan.batchAccessor().schemaVersion());
scan.batchAccessor().release();
// Batch from (a, b) reader 1
assertTrue(scan.next());
assertEquals(1, scan.batchAccessor().schemaVersion());
verifyBatch(0, scan.batchAccessor().container());
// Batch from (a) reader 2
// Due to schema smoothing, b vector type is left unchanged,
// but is null filled.
assertTrue(scan.next());
assertEquals(1, scan.batchAccessor().schemaVersion());
SingleRowSet expected = fixture.rowSetBuilder(scan.batchAccessor().schema()).addRow(111, null).addRow(121, null).build();
RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
// Batch from (a, b) reader 3
// Recycles b again, back to being a table column.
assertTrue(scan.next());
assertEquals(1, scan.batchAccessor().schemaVersion());
verifyBatch(200, scan.batchAccessor().container());
assertFalse(scan.next());
scanFixture.close();
}
Aggregations