use of io.prestosql.client.FailureInfo in project hetu-core by openlookeng.
the class ExpressionInterpreter method createFailureFunction.
private static Expression createFailureFunction(RuntimeException exception, Type type, Metadata metadata) {
requireNonNull(exception, "Exception is null");
String failureInfo = JsonCodec.jsonCodec(FailureInfo.class).toJson(Failures.toFailure(exception).toFailureInfo());
FunctionCall jsonParse = new FunctionCallBuilder(metadata).setName(QualifiedName.of("json_parse")).addArgument(VARCHAR, new StringLiteral(failureInfo)).build();
FunctionCall failureFunction = new FunctionCallBuilder(metadata).setName(QualifiedName.of("fail")).addArgument(JSON, jsonParse).build();
return new Cast(failureFunction, type.getTypeSignature().toString());
}
use of io.prestosql.client.FailureInfo in project hetu-core by openlookeng.
the class Execution method updateJobInfo.
protected void updateJobInfo(Set<Table> usedTables, List<Column> columns, QueryStats queryStats, JobState state, QueryError error) {
if ((usedTables != null) && (usedTables.size() > 0)) {
job.getTablesUsed().addAll(usedTables);
}
if ((columns != null) && (columns.size() > 0)) {
job.setColumns(columns);
}
if (queryStats != null) {
job.setQueryStats(queryStats);
}
if ((state != null) && (job.getState() != JobState.FINISHED) && (job.getState() != JobState.FAILED)) {
job.setState(state);
}
if (error != null) {
FailureInfo failureInfo = new FailureInfo(error.getFailureInfo().getType(), error.getFailureInfo().getMessage(), null, Collections.<FailureInfo>emptyList(), Collections.<String>emptyList(), error.getFailureInfo().getErrorLocation());
QueryError queryError = new QueryError(error.getMessage(), error.getSqlState(), error.getErrorCode(), error.getErrorName(), error.getSemanticErrorName(), error.getErrorType(), error.getErrorLocation(), failureInfo);
job.setError(queryError);
}
}
use of io.prestosql.client.FailureInfo in project hetu-core by openlookeng.
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);
assertSame(stateMachine.getMemoryPool(), MEMORY_POOL);
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);
assertEquals(queryInfo.getMemoryPool(), MEMORY_POOL.getId());
QueryStats queryStats = queryInfo.getQueryStats();
assertNotNull(queryStats.getElapsedTime());
assertNotNull(queryStats.getQueuedTime());
assertNotNull(queryStats.getResourceWaitingTime());
assertNotNull(queryStats.getDispatchingTime());
assertNotNull(queryStats.getExecutionTime());
assertNotNull(queryStats.getTotalPlanningTime());
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 PrestoException) {
assertEquals(queryInfo.getErrorCode(), ((PrestoException) expectedException).getErrorCode());
} else {
assertEquals(queryInfo.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
}
} else {
assertNull(queryInfo.getFailureInfo());
}
}
use of io.prestosql.client.FailureInfo in project hetu-core by openlookeng.
the class Query method toQueryError.
private static QueryError toQueryError(QueryInfo queryInfo) {
QueryState state = queryInfo.getState();
if (state != FAILED) {
return null;
}
ExecutionFailureInfo executionFailure;
if (queryInfo.getFailureInfo() != null) {
executionFailure = queryInfo.getFailureInfo();
} 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.toFailureInfoWithoutStack();
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(), executionFailure.getSemanticErrorCode().map(SemanticErrorCode::name), errorCode.getType().toString(), failure.getErrorLocation(), failure);
}
Aggregations