Search in sources :

Example 1 with FailureInfo

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);
    }
}
Also used : TaskStats(com.facebook.presto.operator.TaskStats) QueryContext(com.facebook.presto.spi.eventlistener.QueryContext) NodeInfo(io.airlift.node.NodeInfo) TaskState(com.facebook.presto.execution.TaskState) NodeVersion(com.facebook.presto.client.NodeVersion) TableFinishInfo(com.facebook.presto.operator.TableFinishInfo) EventListenerManager(com.facebook.presto.eventlistener.EventListenerManager) QueryStatistics(com.facebook.presto.spi.eventlistener.QueryStatistics) OperatorStats(com.facebook.presto.operator.OperatorStats) StageInfo(com.facebook.presto.execution.StageInfo) Instant.ofEpochMilli(java.time.Instant.ofEpochMilli) Duration(java.time.Duration) Map(java.util.Map) QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) TransactionId(com.facebook.presto.transaction.TransactionId) SplitStatistics(com.facebook.presto.spi.eventlistener.SplitStatistics) Column(com.facebook.presto.execution.Column) ImmutableMap(com.google.common.collect.ImmutableMap) SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) Collectors(java.util.stream.Collectors) List(java.util.List) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) Input(com.facebook.presto.execution.Input) QueryInfo(com.facebook.presto.execution.QueryInfo) Optional(java.util.Optional) Math.max(java.lang.Math.max) ConnectorId(com.facebook.presto.connector.ConnectorId) Duration.ofMillis(java.time.Duration.ofMillis) QueryFailureInfo(com.facebook.presto.spi.eventlistener.QueryFailureInfo) JsonCodec(io.airlift.json.JsonCodec) DriverStats(com.facebook.presto.operator.DriverStats) QueryIOMetadata(com.facebook.presto.spi.eventlistener.QueryIOMetadata) Logger(io.airlift.log.Logger) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) FailureInfo(com.facebook.presto.client.FailureInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) Math.toIntExact(java.lang.Math.toIntExact) Nullable(javax.annotation.Nullable) QueryOutputMetadata(com.facebook.presto.spi.eventlistener.QueryOutputMetadata) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) Throwables(com.google.common.base.Throwables) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) QueryInputMetadata(com.facebook.presto.spi.eventlistener.QueryInputMetadata) QueryStats(com.facebook.presto.execution.QueryStats) SplitFailureInfo(com.facebook.presto.spi.eventlistener.SplitFailureInfo) TaskId(com.facebook.presto.execution.TaskId) QueryCreatedEvent(com.facebook.presto.spi.eventlistener.QueryCreatedEvent) TaskInfo(com.facebook.presto.execution.TaskInfo) TableFinishInfo(com.facebook.presto.operator.TableFinishInfo) QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) ImmutableList(com.google.common.collect.ImmutableList) QueryOutputMetadata(com.facebook.presto.spi.eventlistener.QueryOutputMetadata) QueryContext(com.facebook.presto.spi.eventlistener.QueryContext) QueryInputMetadata(com.facebook.presto.spi.eventlistener.QueryInputMetadata) QueryFailureInfo(com.facebook.presto.spi.eventlistener.QueryFailureInfo) TaskInfo(com.facebook.presto.execution.TaskInfo) Input(com.facebook.presto.execution.Input) QueryStats(com.facebook.presto.execution.QueryStats) QueryStatistics(com.facebook.presto.spi.eventlistener.QueryStatistics) QueryFailureInfo(com.facebook.presto.spi.eventlistener.QueryFailureInfo) FailureInfo(com.facebook.presto.client.FailureInfo) SplitFailureInfo(com.facebook.presto.spi.eventlistener.SplitFailureInfo) QueryIOMetadata(com.facebook.presto.spi.eventlistener.QueryIOMetadata) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with FailureInfo

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());
}
Also used : Cast(com.facebook.presto.sql.tree.Cast) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) FailureInfo(com.facebook.presto.client.FailureInfo) PrestoException(com.facebook.presto.spi.PrestoException) FunctionCall(com.facebook.presto.sql.tree.FunctionCall)

Example 3 with FailureInfo

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));
    }
}
Also used : FailureInfo(com.facebook.presto.client.FailureInfo) QueryError(com.facebook.presto.client.QueryError) JobUpdateEvent(com.airbnb.airpal.api.event.JobUpdateEvent)

Example 4 with FailureInfo

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());
    }
}
Also used : FailureInfo(com.facebook.presto.client.FailureInfo) PrestoException(com.facebook.presto.spi.PrestoException)

Example 5 with FailureInfo

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);
}
Also used : FailureInfo(com.facebook.presto.client.FailureInfo) QueryState(com.facebook.presto.execution.QueryState) ErrorCode(com.facebook.presto.spi.ErrorCode) QueryError(com.facebook.presto.client.QueryError)

Aggregations

FailureInfo (com.facebook.presto.client.FailureInfo)5 QueryError (com.facebook.presto.client.QueryError)2 PrestoException (com.facebook.presto.spi.PrestoException)2 JobUpdateEvent (com.airbnb.airpal.api.event.JobUpdateEvent)1 NodeVersion (com.facebook.presto.client.NodeVersion)1 ConnectorId (com.facebook.presto.connector.ConnectorId)1 EventListenerManager (com.facebook.presto.eventlistener.EventListenerManager)1 Column (com.facebook.presto.execution.Column)1 Input (com.facebook.presto.execution.Input)1 QueryInfo (com.facebook.presto.execution.QueryInfo)1 QueryState (com.facebook.presto.execution.QueryState)1 QueryStats (com.facebook.presto.execution.QueryStats)1 StageInfo (com.facebook.presto.execution.StageInfo)1 TaskId (com.facebook.presto.execution.TaskId)1 TaskInfo (com.facebook.presto.execution.TaskInfo)1 TaskState (com.facebook.presto.execution.TaskState)1 DriverStats (com.facebook.presto.operator.DriverStats)1 OperatorStats (com.facebook.presto.operator.OperatorStats)1 TableFinishInfo (com.facebook.presto.operator.TableFinishInfo)1 TaskStats (com.facebook.presto.operator.TaskStats)1