use of com.facebook.presto.spi.ErrorCode in project presto by prestodb.
the class TestPrestoSparkExecutionExceptionFactory method assertFailure.
private static void assertFailure(Failure failure, Throwable expected) {
ErrorCode expectedErrorCode = expected instanceof PrestoException ? ((PrestoException) expected).getErrorCode() : GENERIC_INTERNAL_ERROR.toErrorCode();
assertEquals(failure.getErrorCode(), expectedErrorCode);
assertEquals(failure.getType(), expected.getClass().getName());
assertEquals(failure.getMessage(), expected.getMessage());
if (expected.getCause() != null) {
assertNotNull(failure.getCause());
assertFailure((Failure) failure.getCause(), expected.getCause());
}
if (expected.getSuppressed() != null) {
assertNotNull(failure.getSuppressed());
assertEquals(failure.getSuppressed().length, expected.getSuppressed().length);
for (int i = 0; i < expected.getSuppressed().length; i++) {
assertFailure((Failure) failure.getSuppressed()[i], expected.getSuppressed()[i]);
}
}
}
use of com.facebook.presto.spi.ErrorCode in project presto by prestodb.
the class QueryStateMachine method getQueryInfo.
public QueryInfo getQueryInfo(Optional<StageInfo> rootStage) {
// Query state must be captured first in order to provide a
// correct view of the query. For example, building this
// information, the query could finish, and the task states would
// never be visible.
QueryState state = queryState.get();
ExecutionFailureInfo failureCause = null;
ErrorCode errorCode = null;
if (state == QueryState.FAILED) {
failureCause = this.failureCause.get();
if (failureCause != null) {
errorCode = failureCause.getErrorCode();
}
}
boolean completeInfo = getAllStages(rootStage).stream().allMatch(StageInfo::isFinalStageInfo);
Optional<List<TaskId>> failedTasks;
// Traversing all tasks is expensive, thus only construct failedTasks list when query finished.
if (state.isDone()) {
failedTasks = Optional.of(getAllStages(rootStage).stream().flatMap(stageInfo -> Streams.concat(ImmutableList.of(stageInfo.getLatestAttemptExecutionInfo()).stream(), stageInfo.getPreviousAttemptsExecutionInfos().stream())).flatMap(execution -> execution.getTasks().stream()).filter(taskInfo -> taskInfo.getTaskStatus().getState() == TaskState.FAILED).map(TaskInfo::getTaskId).collect(toImmutableList()));
} else {
failedTasks = Optional.empty();
}
List<StageId> runtimeOptimizedStages = getAllStages(rootStage).stream().filter(StageInfo::isRuntimeOptimized).map(StageInfo::getStageId).collect(toImmutableList());
QueryStats queryStats = getQueryStats(rootStage);
return new QueryInfo(queryId, session.toSessionRepresentation(), state, memoryPool.get().getId(), queryStats.isScheduled(), self, outputManager.getQueryOutputInfo().map(QueryOutputInfo::getColumnNames).orElse(ImmutableList.of()), query, expandedQuery.get(), preparedQuery, queryStats, Optional.ofNullable(setCatalog.get()), Optional.ofNullable(setSchema.get()), setSessionProperties, resetSessionProperties, setRoles, addedPreparedStatements, deallocatedPreparedStatements, Optional.ofNullable(startedTransactionId.get()), clearTransactionId.get(), updateType.get(), rootStage, failureCause, errorCode, warningCollector.getWarnings(), inputs.get(), output.get(), completeInfo, Optional.of(resourceGroup), queryType, failedTasks, runtimeOptimizedStages.isEmpty() ? Optional.empty() : Optional.of(runtimeOptimizedStages), addedSessionFunctions, removedSessionFunctions);
}
use of com.facebook.presto.spi.ErrorCode in project presto-audit by yahoojapan.
the class TestHelper method createFailureEvent.
public QueryCompletedEvent createFailureEvent() {
setUp();
QueryMetadata metadata = new QueryMetadata("20170606_044544_00024_nfhe3", Optional.of("4c52973c-14c6-4534-837f-238e21d9b061"), "select 2a", "FAILED", uri, Optional.empty(), Optional.empty());
ErrorCode errorCode = new ErrorCode(1, "SYNTAX_ERROR", ErrorType.USER_ERROR);
QueryFailureInfo failureInfo = new QueryFailureInfo(errorCode, Optional.of("com.facebook.presto.sql.parser.ParsingException"), Optional.of("line 1:15: mismatched input '0' expecting ')'"), Optional.empty(), Optional.empty(), "{json-error}");
return new QueryCompletedEvent(metadata, statistics, context, ioMetadata, Optional.of(failureInfo), createTime, executionStartTime, endTime);
}
use of com.facebook.presto.spi.ErrorCode in project presto by prestodb.
the class Query method toQueryError.
private static QueryError toQueryError(QueryInfo queryInfo) {
QueryState state = queryInfo.getState();
if (state != FAILED) {
return null;
}
FailureInfo failure;
if (queryInfo.getFailureInfo() != null) {
failure = queryInfo.getFailureInfo().toFailureInfo();
} else {
log.warn("Query %s in state %s has no failure info", queryInfo.getQueryId(), state);
failure = toFailure(new RuntimeException(format("Query is %s (reason unknown)", state))).toFailureInfo();
}
ErrorCode errorCode;
if (queryInfo.getErrorCode() != null) {
errorCode = queryInfo.getErrorCode();
} else {
errorCode = GENERIC_INTERNAL_ERROR.toErrorCode();
log.warn("Failed query %s has no error code", queryInfo.getQueryId());
}
return new QueryError(firstNonNull(failure.getMessage(), "Internal error"), null, errorCode.getCode(), errorCode.getName(), errorCode.getType().toString(), errorCode.isRetriable(), failure.getErrorLocation(), failure);
}
use of com.facebook.presto.spi.ErrorCode in project presto by prestodb.
the class Failures method toFailure.
private static ExecutionFailureInfo toFailure(Throwable throwable, Set<Throwable> seenFailures) {
if (throwable == null) {
return null;
}
String type;
HostAddress remoteHost = null;
if (throwable instanceof Failure) {
type = ((Failure) throwable).getType();
} else {
Class<?> clazz = throwable.getClass();
type = firstNonNull(clazz.getCanonicalName(), clazz.getName());
}
if (throwable instanceof PrestoTransportException) {
remoteHost = ((PrestoTransportException) throwable).getRemoteHost();
}
if (seenFailures.contains(throwable)) {
return new ExecutionFailureInfo(type, "[cyclic] " + throwable.getMessage(), null, ImmutableList.of(), ImmutableList.of(), null, GENERIC_INTERNAL_ERROR.toErrorCode(), remoteHost);
}
seenFailures.add(throwable);
ExecutionFailureInfo cause = toFailure(throwable.getCause(), seenFailures);
ErrorCode errorCode = toErrorCode(throwable);
if (errorCode == null) {
if (cause == null) {
errorCode = GENERIC_INTERNAL_ERROR.toErrorCode();
} else {
errorCode = cause.getErrorCode();
}
}
return new ExecutionFailureInfo(type, throwable.getMessage(), cause, Arrays.stream(throwable.getSuppressed()).map(failure -> toFailure(failure, seenFailures)).collect(toImmutableList()), Lists.transform(asList(throwable.getStackTrace()), toStringFunction()), getErrorLocation(throwable), errorCode, remoteHost);
}
Aggregations