use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanBasics method testNoReader.
/**
* Pathological case that a scan operator is provided no readers.
* It will throw a user exception because the downstream operators
* can't handle this case so we choose to stop the show early to
* avoid getting into a strange state.
*/
@Test
public void testNoReader() {
// Create the scan operator
ScanFixture scanFixture = simpleFixture();
ScanOperatorExec scan = scanFixture.scanOp;
try {
scan.buildSchema();
} catch (UserException e) {
// Expected
assertTrue(e.getCause() instanceof ExecutionSetupException);
}
// Must close the DAG (context and scan operator) even on failures
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanBasics method testExceptionOnFirstNext.
@Test
public void testExceptionOnFirstNext() {
ObservableCreator creator = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator) {
@Override
public boolean next() {
// Load some data
super.next();
throw new IllegalStateException(ERROR_MSG);
}
};
reader.batchLimit = 2;
return reader;
}
};
ScanFixture scanFixture = simpleFixture(creator);
ScanOperatorExec scan = scanFixture.scanOp;
assertTrue(scan.buildSchema());
try {
scan.next();
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains(ERROR_MSG));
assertTrue(e.getCause() instanceof IllegalStateException);
}
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
MockEarlySchemaReader reader = creator.reader();
assertTrue(reader.closeCalled);
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanBasics method testUserExceptionOnFirstNext.
@Test
public void testUserExceptionOnFirstNext() {
ObservableCreator creator = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator) {
@Override
public boolean next() {
// Load some data
super.next();
throw UserException.dataReadError().message(ERROR_MSG).build(logger);
}
};
reader.batchLimit = 2;
return reader;
}
};
ScanFixture scanFixture = simpleFixture(creator);
ScanOperatorExec scan = scanFixture.scanOp;
assertTrue(scan.buildSchema());
// EOF
try {
scan.next();
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains(ERROR_MSG));
assertNull(e.getCause());
}
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
MockEarlySchemaReader reader = creator.reader();
assertTrue(reader.closeCalled);
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanBasics 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() {
ObservableCreator creator1 = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
reader.batchLimit = 0;
return reader;
}
};
ObservableCreator creator2 = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
reader.batchLimit = 0;
return reader;
}
};
ScanFixture scanFixture = simpleFixture(creator1, creator2);
ScanOperatorExec scan = scanFixture.scanOp;
// EOF
assertTrue(scan.buildSchema());
assertTrue(scan.next());
VectorContainer container = scan.batchAccessor().container();
assertEquals(0, container.getRecordCount());
assertEquals(2, container.getNumberOfColumns());
assertEquals(0, scan.batchAccessor().rowCount());
scan.batchAccessor().release();
MockEarlySchemaReader reader1 = creator1.reader();
assertTrue(reader1.closeCalled);
MockEarlySchemaReader reader2 = creator2.reader();
assertTrue(reader2.closeCalled);
assertFalse(scan.next());
scanFixture.close();
}
use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec in project drill by apache.
the class TestScanBasics method testUserExceptionOnSecondNext.
@Test
public void testUserExceptionOnSecondNext() {
ObservableCreator creator = new ObservableCreator() {
@Override
public ManagedReader create(SchemaNegotiator negotiator) {
MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator) {
@Override
public boolean next() {
// Load some data
boolean result = super.next();
if (batchCount == 2) {
throw UserException.dataReadError().message(ERROR_MSG).build(logger);
}
return result;
}
};
reader.batchLimit = 2;
return reader;
}
};
ScanFixture scanFixture = simpleFixture(creator);
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));
assertNull(e.getCause());
}
scanFixture.close();
MockEarlySchemaReader reader = creator.reader();
assertTrue(reader.closeCalled);
}
Aggregations