use of org.apache.drill.common.exceptions.UserException in project drill by apache.
the class TestScanLifecycleSchema method testDefinedSchemaConflict.
/**
* Reader produces a schema which conflicts with the defined schema.
* The defined schema should be something the reader can implement; so
* it is an error if the reader does not do so.
*/
@Test
public void testDefinedSchemaConflict() {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.definedSchema(SCHEMA);
builder.readerFactory(new SingleReaderFactory() {
@Override
public ManagedReader next(SchemaNegotiator negotiator) {
return new MockEarlySchemaTypeConflictReader(negotiator);
}
});
ScanLifecycle scan = buildScan(builder);
RowBatchReader reader = scan.nextReader();
try {
reader.open();
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains("conflict"));
}
reader.close();
scan.close();
}
use of org.apache.drill.common.exceptions.UserException 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.common.exceptions.UserException 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.common.exceptions.UserException 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.common.exceptions.UserException 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