use of io.trino.client.FailureInfo in project trino by trinodb.
the class TestQueryStateMachine method assertState.
private static void assertState(QueryStateMachine stateMachine, QueryState expectedState, Exception expectedException) {
assertEquals(stateMachine.getQueryId(), TEST_SESSION.getQueryId());
assertEqualSessionsWithoutTransactionId(stateMachine.getSession(), TEST_SESSION);
assertEquals(stateMachine.getSetSessionProperties(), SET_SESSION_PROPERTIES);
assertEquals(stateMachine.getResetSessionProperties(), RESET_SESSION_PROPERTIES);
QueryInfo queryInfo = stateMachine.getQueryInfo(Optional.empty());
assertEquals(queryInfo.getQueryId(), TEST_SESSION.getQueryId());
assertEquals(queryInfo.getSelf(), LOCATION);
assertFalse(queryInfo.getOutputStage().isPresent());
assertEquals(queryInfo.getQuery(), QUERY);
assertEquals(queryInfo.getInputs(), INPUTS);
assertEquals(queryInfo.getOutput(), OUTPUT);
assertEquals(queryInfo.getFieldNames(), OUTPUT_FIELD_NAMES);
assertEquals(queryInfo.getUpdateType(), UPDATE_TYPE);
assertTrue(queryInfo.getQueryType().isPresent());
assertEquals(queryInfo.getQueryType().get(), QUERY_TYPE.get());
QueryStats queryStats = queryInfo.getQueryStats();
assertNotNull(queryStats.getElapsedTime());
assertNotNull(queryStats.getQueuedTime());
assertNotNull(queryStats.getResourceWaitingTime());
assertNotNull(queryStats.getDispatchingTime());
assertNotNull(queryStats.getExecutionTime());
assertNotNull(queryStats.getPlanningTime());
assertNotNull(queryStats.getFinishingTime());
assertNotNull(queryStats.getCreateTime());
if (queryInfo.getState() == QUEUED || queryInfo.getState() == WAITING_FOR_RESOURCES || queryInfo.getState() == DISPATCHING) {
assertNull(queryStats.getExecutionStartTime());
} else {
assertNotNull(queryStats.getExecutionStartTime());
}
if (queryInfo.getState().isDone()) {
assertNotNull(queryStats.getEndTime());
} else {
assertNull(queryStats.getEndTime());
}
assertEquals(stateMachine.getQueryState(), expectedState);
assertEquals(queryInfo.getState(), expectedState);
assertEquals(stateMachine.isDone(), expectedState.isDone());
if (expectedState == FAILED) {
assertNotNull(queryInfo.getFailureInfo());
FailureInfo failure = queryInfo.getFailureInfo().toFailureInfo();
assertNotNull(failure);
assertEquals(failure.getType(), expectedException.getClass().getName());
if (expectedException instanceof TrinoException) {
assertEquals(queryInfo.getErrorCode(), ((TrinoException) expectedException).getErrorCode());
} else {
assertEquals(queryInfo.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
}
} else {
assertNull(queryInfo.getFailureInfo());
}
}
use of io.trino.client.FailureInfo in project trino by trinodb.
the class Query method toQueryError.
private static QueryError toQueryError(QueryInfo queryInfo, Optional<Throwable> exception) {
QueryState state = queryInfo.getState();
if (state != FAILED && exception.isEmpty()) {
return null;
}
ExecutionFailureInfo executionFailure;
if (queryInfo.getFailureInfo() != null) {
executionFailure = queryInfo.getFailureInfo();
} else if (exception.isPresent()) {
executionFailure = toFailure(exception.get());
} else {
log.warn("Query %s in state %s has no failure info", queryInfo.getQueryId(), state);
executionFailure = toFailure(new RuntimeException(format("Query is %s (reason unknown)", state)));
}
FailureInfo failure = executionFailure.toFailureInfo();
ErrorCode errorCode;
if (queryInfo.getErrorCode() != null) {
errorCode = queryInfo.getErrorCode();
} else if (exception.isPresent()) {
errorCode = SERIALIZATION_ERROR.toErrorCode();
} 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(), failure.getErrorLocation(), failure);
}
Aggregations