use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.
the class TestScanOperExecSmoothing method testSchemaChange.
/**
* Multiple readers with a schema change between them.
*/
@Test
public void testSchemaChange() {
MockEarlySchemaReader reader1 = new MockEarlySchemaReader();
reader1.batchLimit = 2;
MockEarlySchemaReader reader2 = new MockEarlySchemaReader2();
reader2.batchLimit = 2;
ScanFixture scanFixture = simpleFixture(reader1, reader2);
ScanOperatorExec scan = scanFixture.scanOp;
// Build schema
assertTrue(scan.buildSchema());
assertEquals(1, scan.batchAccessor().schemaVersion());
scan.batchAccessor().release();
readSchemaChangeBatches(scanFixture, reader2);
}
use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.
the class TestScanOperExecBasics method testMultiEOFOnFirstBatch.
/**
* Test multiple readers, all EOF on first batch.
* The scan will return one empty batch to declare the
* early schema. Results in an empty (rather than null)
* result set.
*/
@Test
public void testMultiEOFOnFirstBatch() {
MockEarlySchemaReader reader1 = new MockEarlySchemaReader();
reader1.batchLimit = 0;
MockEarlySchemaReader reader2 = new MockEarlySchemaReader();
reader2.batchLimit = 0;
ScanFixture scanFixture = simpleFixture(reader1, reader2);
ScanOperatorExec scan = scanFixture.scanOp;
// EOF
assertTrue(scan.buildSchema());
assertTrue(scan.next());
VectorContainer container = scan.batchAccessor().container();
assertEquals(0, container.getRecordCount());
assertEquals(2, container.getNumberOfColumns());
assertTrue(reader1.closeCalled);
assertTrue(reader2.closeCalled);
assertEquals(0, scan.batchAccessor().rowCount());
assertFalse(scan.next());
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.
the class TestScanOperExecBasics method testExceptionOnSecondNext.
/**
* Test throwing an exception after the first batch, but while
* "reading" the second. Note that the first batch returns data
* and is spread over two next() calls, so the error is on the
* third call to the scan operator next().
*/
@Test
public void testExceptionOnSecondNext() {
MockEarlySchemaReader reader = new MockEarlySchemaReader() {
@Override
public boolean next() {
if (batchCount == 1) {
// Load some data
super.next();
throw new IllegalStateException(ERROR_MSG);
}
return super.next();
}
};
reader.batchLimit = 2;
ScanFixture scanFixture = simpleFixture(reader);
ScanOperatorExec scan = scanFixture.scanOp;
// Schema
assertTrue(scan.buildSchema());
// First batch
assertTrue(scan.next());
scan.batchAccessor().release();
try {
scan.next();
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains(ERROR_MSG));
assertTrue(e.getCause() instanceof IllegalStateException);
}
scanFixture.close();
assertTrue(reader.closeCalled);
}
use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.
the class TestScanOperExecBasics method testUserExceptionOnFirstNext.
@Test
public void testUserExceptionOnFirstNext() {
MockEarlySchemaReader reader = new MockEarlySchemaReader() {
@Override
public boolean next() {
// Load some data
super.next();
throw UserException.dataReadError().addContext(ERROR_MSG).build(logger);
}
};
reader.batchLimit = 2;
ScanFixture scanFixture = simpleFixture(reader);
ScanOperatorExec scan = scanFixture.scanOp;
assertTrue(scan.buildSchema());
try {
scan.next();
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains(ERROR_MSG));
assertNull(e.getCause());
}
assertTrue(reader.openCalled);
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
assertTrue(reader.closeCalled);
}
use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.
the class TestScanOperExecLateSchema method testLateSchemaLifecycleNoFile.
/**
* Test a late-schema source that has no file information.
* (Like a Hive or JDBC data source.)
*/
@Test
public void testLateSchemaLifecycleNoFile() {
// Create a mock reader, return two batches: one schema-only, another with data.
MockLateSchemaReader reader = new MockLateSchemaReader();
reader.batchLimit = 2;
reader.returnDataOnFirst = false;
// Create the scan operator
ScanFixture scanFixture = simpleFixture(reader);
ScanOperatorExec scan = scanFixture.scanOp;
// Standard startup
assertFalse(reader.openCalled);
// First batch: build schema. The reader helps: it returns an
// empty first batch.
assertTrue(scan.buildSchema());
assertTrue(reader.openCalled);
assertEquals(1, reader.batchCount);
assertEquals(0, scan.batchAccessor().rowCount());
// Create the expected result.
SingleRowSet expected = makeExpected(20);
RowSetComparison verifier = new RowSetComparison(expected);
assertEquals(expected.batchSchema(), scan.batchAccessor().schema());
// Next call, return with data.
assertTrue(scan.next());
verifier.verifyAndClearAll(fixture.wrap(scan.batchAccessor().container()));
// EOF
assertFalse(scan.next());
assertTrue(reader.closeCalled);
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
}
Aggregations