use of com.facebook.presto.client.FailureInfo in project presto by prestodb.
the class QueryMonitor method queryCompletedEvent.
public void queryCompletedEvent(QueryInfo queryInfo) {
try {
Optional<QueryFailureInfo> queryFailureInfo = Optional.empty();
if (queryInfo.getFailureInfo() != null) {
FailureInfo failureInfo = queryInfo.getFailureInfo();
Optional<TaskInfo> failedTask = queryInfo.getOutputStage().flatMap(QueryMonitor::findFailedTask);
queryFailureInfo = Optional.of(new QueryFailureInfo(queryInfo.getErrorCode(), Optional.ofNullable(failureInfo.getType()), Optional.ofNullable(failureInfo.getMessage()), failedTask.map(task -> task.getTaskStatus().getTaskId().toString()), failedTask.map(task -> task.getTaskStatus().getSelf().getHost()), objectMapper.writeValueAsString(queryInfo.getFailureInfo())));
}
ImmutableList.Builder<QueryInputMetadata> inputs = ImmutableList.builder();
for (Input input : queryInfo.getInputs()) {
inputs.add(new QueryInputMetadata(input.getConnectorId().getCatalogName(), input.getSchema(), input.getTable(), input.getColumns().stream().map(Column::toString).collect(Collectors.toList()), input.getConnectorInfo()));
}
QueryStats queryStats = queryInfo.getQueryStats();
Optional<QueryOutputMetadata> output = Optional.empty();
if (queryInfo.getOutput().isPresent()) {
Optional<TableFinishInfo> tableFinishInfo = queryStats.getOperatorSummaries().stream().map(OperatorStats::getInfo).filter(TableFinishInfo.class::isInstance).map(TableFinishInfo.class::cast).findFirst();
output = Optional.of(new QueryOutputMetadata(queryInfo.getOutput().get().getConnectorId().getCatalogName(), queryInfo.getOutput().get().getSchema(), queryInfo.getOutput().get().getTable(), tableFinishInfo.map(TableFinishInfo::getConnectorOutputMetadata), tableFinishInfo.map(TableFinishInfo::isJsonLengthLimitExceeded)));
}
eventListenerManager.queryCompleted(new QueryCompletedEvent(new QueryMetadata(queryInfo.getQueryId().toString(), queryInfo.getSession().getTransactionId().map(TransactionId::toString), queryInfo.getQuery(), queryInfo.getState().toString(), queryInfo.getSelf(), queryInfo.getOutputStage().flatMap(stage -> stageInfoCodec.toJsonWithLengthLimit(stage, toIntExact(config.getMaxOutputStageJsonSize().toBytes())))), new QueryStatistics(ofMillis(queryStats.getTotalCpuTime().toMillis()), ofMillis(queryStats.getTotalScheduledTime().toMillis()), ofMillis(queryStats.getQueuedTime().toMillis()), Optional.ofNullable(queryStats.getAnalysisTime()).map(duration -> ofMillis(duration.toMillis())), Optional.ofNullable(queryStats.getDistributedPlanningTime()).map(duration -> ofMillis(duration.toMillis())), queryStats.getPeakMemoryReservation().toBytes(), queryStats.getRawInputDataSize().toBytes(), queryStats.getRawInputPositions(), queryStats.getCompletedDrivers(), queryInfo.isCompleteInfo(), objectMapper.writeValueAsString(queryInfo.getQueryStats().getOperatorSummaries())), new QueryContext(queryInfo.getSession().getUser(), queryInfo.getSession().getPrincipal(), queryInfo.getSession().getRemoteUserAddress(), queryInfo.getSession().getUserAgent(), queryInfo.getSession().getClientInfo(), queryInfo.getSession().getSource(), queryInfo.getSession().getCatalog(), queryInfo.getSession().getSchema(), mergeSessionAndCatalogProperties(queryInfo), serverAddress, serverVersion, environment), new QueryIOMetadata(inputs.build(), output), queryFailureInfo, ofEpochMilli(queryStats.getCreateTime().getMillis()), ofEpochMilli(queryStats.getExecutionStartTime().getMillis()), ofEpochMilli(queryStats.getEndTime().getMillis())));
logQueryTimeline(queryInfo);
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}
}
use of com.facebook.presto.client.FailureInfo in project presto by prestodb.
the class ExpressionInterpreter method createFailureFunction.
private Expression createFailureFunction(RuntimeException exception, Type type) {
requireNonNull(exception, "Exception is null");
String failureInfo = JsonCodec.jsonCodec(FailureInfo.class).toJson(Failures.toFailure(exception).toFailureInfo());
if (exception instanceof PrestoException) {
long errorCode = ((PrestoException) exception).getErrorCode().getCode();
FunctionCall jsonParse = new FunctionCall(QualifiedName.of("json_parse"), ImmutableList.of(new StringLiteral(failureInfo)));
FunctionCall failureFunction = new FunctionCall(QualifiedName.of("fail"), ImmutableList.of(literalEncoder.toExpression(errorCode, INTEGER), jsonParse));
return new Cast(failureFunction, type.getTypeSignature().toString());
}
FunctionCall jsonParse = new FunctionCall(QualifiedName.of("json_parse"), ImmutableList.of(new StringLiteral(failureInfo)));
FunctionCall failureFunction = new FunctionCall(QualifiedName.of("fail"), ImmutableList.of(jsonParse));
return new Cast(failureFunction, type.getTypeSignature().toString());
}
use of com.facebook.presto.client.FailureInfo in project airpal by airbnb.
the class Execution method updateJobInfo.
protected void updateJobInfo(Set<Table> usedTables, List<Column> columns, QueryStats queryStats, JobState state, QueryError error, List<List<Object>> outputPreview, boolean postUpdate) {
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.getErrorType(), error.getErrorLocation(), failureInfo);
job.setError(queryError);
}
if (postUpdate) {
eventBus.post(new JobUpdateEvent(job, outputPreview));
}
}
use of com.facebook.presto.client.FailureInfo in project presto by prestodb.
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());
assertEquals(queryInfo.getQueryType(), QUERY_TYPE);
QueryStats queryStats = queryInfo.getQueryStats();
assertNotNull(queryStats.getElapsedTime());
assertNotNull(queryStats.getQueuedTime());
assertNotNull(queryStats.getResourceWaitingTime());
assertNotNull(queryStats.getSemanticAnalyzingTime());
assertNotNull(queryStats.getColumnAccessPermissionCheckingTime());
assertNotNull(queryStats.getDispatchingTime());
assertNotNull(queryStats.getExecutionTime());
assertNotNull(queryStats.getTotalPlanningTime());
assertNotNull(queryStats.getFinishingTime());
assertNotNull(queryStats.getCreateTime());
if (queryInfo.getState() == WAITING_FOR_PREREQUISITES || 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 com.facebook.presto.client.FailureInfo 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);
}
Aggregations