use of org.apache.drill.common.exceptions.UserException in project drill by axbaretto.
the class DrillOptiqTest method testUnsupportedRexNode.
/* Method checks if we raise the appropriate error while dealing with RexNode that cannot be converted to
* equivalent Drill expressions
*/
@Test
public void testUnsupportedRexNode() {
try {
// Create the data type factory.
RelDataTypeFactory relFactory = new SqlTypeFactoryImpl(DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM);
// Create the rex builder
RexBuilder rex = new RexBuilder(relFactory);
RelDataType anyType = relFactory.createSqlType(SqlTypeName.ANY);
List<RexNode> emptyList = new LinkedList<>();
ImmutableList<RexFieldCollation> e = ImmutableList.copyOf(new RexFieldCollation[0]);
// create a dummy RexOver object.
RexNode window = rex.makeOver(anyType, SqlStdOperatorTable.AVG, emptyList, emptyList, e, null, null, true, false, false, false);
DrillOptiq.toDrill(null, (RelNode) null, window);
} catch (UserException e) {
if (e.getMessage().contains(DrillOptiq.UNSUPPORTED_REX_NODE_ERROR)) {
// got expected error return
return;
}
Assert.fail("Hit exception with unexpected error message");
}
Assert.fail("Failed to raise the expected exception");
}
use of org.apache.drill.common.exceptions.UserException in project drill by axbaretto.
the class JSONRecordReader method handleAndRaise.
protected void handleAndRaise(String suffix, Exception e) throws UserException {
String message = e.getMessage();
int columnNr = -1;
if (e instanceof JsonParseException) {
final JsonParseException ex = (JsonParseException) e;
message = ex.getOriginalMessage();
columnNr = ex.getLocation().getColumnNr();
}
UserException.Builder exceptionBuilder = UserException.dataReadError(e).message("%s - %s", suffix, message);
if (columnNr > 0) {
exceptionBuilder.pushContext("Column ", columnNr);
}
if (hadoopPath != null) {
exceptionBuilder.pushContext("Record ", currentRecordNumberInFile()).pushContext("File ", hadoopPath.toUri().getPath());
}
throw exceptionBuilder.build(logger);
}
use of org.apache.drill.common.exceptions.UserException in project drill by axbaretto.
the class DrillCursor method nextRowInternally.
/**
* ...
* <p>
* Is to be called (once) from {@link #loadInitialSchema} for
* {@link DrillResultSetImpl#execute()}, and then (repeatedly) from
* {@link #next()} for {@link AvaticaResultSet#next()}.
* </p>
*
* @return whether cursor is positioned at a row (false when after end of
* results)
*/
private boolean nextRowInternally() throws SQLException {
if (currentRecordNumber + 1 < currentBatchHolder.getRecordCount()) {
// Have next row in current batch--just advance index and report "at a row."
currentRecordNumber++;
return true;
} else {
try {
QueryDataBatch qrb = resultsListener.getNext();
// the (initial) schema but no rows)).
if (afterFirstBatch) {
while (qrb != null && (qrb.getHeader().getRowCount() == 0 || qrb.getData() == null)) {
// Empty message--dispose of and try to get another.
logger.warn("Spurious batch read: {}", qrb);
qrb.release();
qrb = resultsListener.getNext();
}
}
afterFirstBatch = true;
if (qrb == null) {
// End of batches--clean up, set state to done, report after last row.
// (We load it so we clear it.)
currentBatchHolder.clear();
afterLastRow = true;
return false;
} else {
// Got next (or first) batch--reset record offset to beginning;
// assimilate schema if changed; set up return value for first call
// to next().
currentRecordNumber = 0;
final boolean schemaChanged;
try {
schemaChanged = currentBatchHolder.load(qrb.getHeader().getDef(), qrb.getData());
} finally {
qrb.release();
}
schema = currentBatchHolder.getSchema();
if (schemaChanged) {
updateColumns();
}
if (returnTrueForNextCallToNext && currentBatchHolder.getRecordCount() == 0) {
returnTrueForNextCallToNext = false;
}
return true;
}
} catch (UserException e) {
// error type is accessible, of course. :-( )
throw new SQLException(e.getMessage(), e);
} catch (InterruptedException e) {
// but JDBC client certainly could.
throw new SQLException("Interrupted.", e);
} catch (SchemaChangeException e) {
// throws SchemaChangeException, so check/clean catch clause.
throw new SQLException("Unexpected SchemaChangeException from RecordBatchLoader.load(...)");
} catch (RuntimeException e) {
throw new SQLException("Unexpected RuntimeException: " + e.toString(), e);
}
}
}
use of org.apache.drill.common.exceptions.UserException in project drill by axbaretto.
the class FragmentExecutor method sendFinalState.
private void sendFinalState() {
final FragmentState outcome = fragmentState.get();
if (outcome == FragmentState.FAILED) {
final FragmentHandle handle = getContext().getHandle();
final UserException uex = UserException.systemError(deferredException.getAndClear()).addIdentity(getContext().getEndpoint()).addContext("Fragment", handle.getMajorFragmentId() + ":" + handle.getMinorFragmentId()).build(logger);
statusReporter.fail(uex);
} else {
statusReporter.stateChanged(outcome);
}
statusReporter.close();
}
use of org.apache.drill.common.exceptions.UserException in project drill by axbaretto.
the class TestTimedRunnable method withTasksExceedingTimeout.
@Test
public void withTasksExceedingTimeout() throws Exception {
UserException ex = null;
try {
List<TimedRunnable<TestTask>> tasks = Lists.newArrayList();
for (int i = 0; i < 100; i++) {
if ((i & (i + 1)) == 0) {
tasks.add(new TestTask(2000));
} else {
tasks.add(new TestTask(20000));
}
}
TimedRunnable.run("Execution with some tasks triggering timeout", logger, tasks, 16);
} catch (UserException e) {
ex = e;
}
assertNotNull("Expected a UserException", ex);
assertThat(ex.getMessage(), containsString("Waited for 93750ms, but tasks for 'Execution with some tasks triggering timeout' are not " + "complete. Total runnable size 100, parallelism 16."));
}
Aggregations