use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestFileScan 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() {
ReaderCreator creator = negotiator -> {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
reader.batchLimit = 1;
return reader;
};
// Select table and implicit columns.
FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
builder.setProjection("dir0", "b", "filename", "c", "suffix");
builder.addReader(creator);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Expect data and implicit columns
TupleMetadata expectedSchema = new SchemaBuilder().addNullable("dir0", MinorType.VARCHAR).addNullable("b", MinorType.VARCHAR).add("filename", MinorType.VARCHAR).addNullable("c", MinorType.INT).add("suffix", MinorType.VARCHAR).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(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 TestFileScan method testMapProject.
@Test
public void testMapProject() {
ReaderCreator creator = negotiator -> {
MockMapReader reader = new MockMapReader(negotiator);
reader.batchLimit = 1;
return reader;
};
// Select one of the two map columns
FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
builder.setProjection("m1.a");
builder.addReader(creator);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Expect data and implicit columns
TupleMetadata expectedSchema = new SchemaBuilder().addMap("m1").add("a", MinorType.INT).resumeSchema().build();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addSingleCol(new Object[] { 10 }).addSingleCol(new Object[] { 20 }).build();
assertTrue(scan.buildSchema());
assertEquals(expected.container().getSchema(), 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.ScanOperatorExec in project drill by apache.
the class TestScanBasics method testExceptionOnOpen.
@Test
public void testExceptionOnOpen() {
// Reader which fails on open with a known error message
// using an exception other than UserException.
ObservableCreator creator = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) {
return new GenericCrashReader(negotiator);
}
};
ScanFixture scanFixture = simpleFixture(creator);
ScanOperatorExec scan = scanFixture.scanOp;
try {
scan.buildSchema();
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains(ERROR_MSG));
assertTrue(e.getCause() instanceof IllegalStateException);
}
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanBasics method testExceptionOnClose.
@Test
public void testExceptionOnClose() {
ObservableCreator creator1 = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator) {
@Override
public void close() {
super.close();
throw new IllegalStateException(ERROR_MSG);
}
};
reader.batchLimit = 2;
return reader;
}
};
ObservableCreator creator2 = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
reader.batchLimit = 2;
return reader;
}
};
ScanFixture scanFixture = simpleFixture(creator1, creator2);
ScanOperatorExec scan = scanFixture.scanOp;
assertTrue(scan.buildSchema());
assertTrue(scan.next());
scan.batchAccessor().release();
assertTrue(scan.next());
scan.batchAccessor().release();
// Fail on close of first reader
try {
scan.next();
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains(ERROR_MSG));
assertTrue(e.getCause() instanceof IllegalStateException);
}
assertNull(creator2.reader);
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanBasics method testEOFOnFirstOpen.
@Test
public void testEOFOnFirstOpen() {
ObservableCreator creator1 = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) throws EarlyEofException {
return new EofOnOpenReader(negotiator);
}
};
ObservableCreator creator2 = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
reader.batchLimit = 2;
return reader;
}
};
ScanFixture scanFixture = simpleFixture(creator1, creator2);
ScanOperatorExec scan = scanFixture.scanOp;
assertTrue(scan.buildSchema());
assertTrue(scan.next());
scan.batchAccessor().release();
assertTrue(scan.next());
scan.batchAccessor().release();
assertFalse(scan.next());
scanFixture.close();
}
Aggregations