Search in sources :

Example 1 with QueryOutputInfo

use of com.facebook.presto.execution.QueryExecution.QueryOutputInfo 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);
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) EMPTY_STAGE_STATS(com.facebook.presto.execution.BasicStageExecutionStats.EMPTY_STAGE_STATS) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) TransactionId(com.facebook.presto.transaction.TransactionId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) StageInfo.getAllStages(com.facebook.presto.execution.StageInfo.getAllStages) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) DISPATCHING(com.facebook.presto.execution.QueryState.DISPATCHING) WAITING_FOR_RESOURCES(com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Failures.toFailure(com.facebook.presto.util.Failures.toFailure) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Ticker(com.google.common.base.Ticker) Streams(com.google.common.collect.Streams) GuardedBy(javax.annotation.concurrent.GuardedBy) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) List(java.util.List) USER_CANCELED(com.facebook.presto.spi.StandardErrorCode.USER_CANCELED) Optional(java.util.Optional) QueryOutputInfo(com.facebook.presto.execution.QueryExecution.QueryOutputInfo) WAITING_FOR_PREREQUISITES(com.facebook.presto.execution.QueryState.WAITING_FOR_PREREQUISITES) Logger(com.facebook.airlift.log.Logger) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ErrorCode(com.facebook.presto.spi.ErrorCode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) PrestoException(com.facebook.presto.spi.PrestoException) VersionedMemoryPoolId(com.facebook.presto.memory.VersionedMemoryPoolId) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) TERMINAL_QUERY_STATES(com.facebook.presto.execution.QueryState.TERMINAL_QUERY_STATES) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) Objects.requireNonNull(java.util.Objects.requireNonNull) TransactionManager(com.facebook.presto.transaction.TransactionManager) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) SelectedRole(com.facebook.presto.spi.security.SelectedRole) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) Executor(java.util.concurrent.Executor) Session(com.facebook.presto.Session) DateTime(org.joda.time.DateTime) FutureCallback(com.google.common.util.concurrent.FutureCallback) FINISHED(com.facebook.presto.execution.QueryState.FINISHED) TransactionInfo(com.facebook.presto.transaction.TransactionInfo) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) StateChangeListener(com.facebook.presto.execution.StateMachine.StateChangeListener) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) QueryType(com.facebook.presto.spi.resourceGroups.QueryType) QueryId(com.facebook.presto.spi.QueryId) STARTING(com.facebook.presto.execution.QueryState.STARTING) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) QueryOutputInfo(com.facebook.presto.execution.QueryExecution.QueryOutputInfo) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ErrorCode(com.facebook.presto.spi.ErrorCode)

Aggregations

Logger (com.facebook.airlift.log.Logger)1 Session (com.facebook.presto.Session)1 Type (com.facebook.presto.common.type.Type)1 EMPTY_STAGE_STATS (com.facebook.presto.execution.BasicStageExecutionStats.EMPTY_STAGE_STATS)1 QueryOutputInfo (com.facebook.presto.execution.QueryExecution.QueryOutputInfo)1 DISPATCHING (com.facebook.presto.execution.QueryState.DISPATCHING)1 FINISHED (com.facebook.presto.execution.QueryState.FINISHED)1 FINISHING (com.facebook.presto.execution.QueryState.FINISHING)1 PLANNING (com.facebook.presto.execution.QueryState.PLANNING)1 QUEUED (com.facebook.presto.execution.QueryState.QUEUED)1 RUNNING (com.facebook.presto.execution.QueryState.RUNNING)1 STARTING (com.facebook.presto.execution.QueryState.STARTING)1 TERMINAL_QUERY_STATES (com.facebook.presto.execution.QueryState.TERMINAL_QUERY_STATES)1 WAITING_FOR_PREREQUISITES (com.facebook.presto.execution.QueryState.WAITING_FOR_PREREQUISITES)1 WAITING_FOR_RESOURCES (com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES)1 StageInfo.getAllStages (com.facebook.presto.execution.StageInfo.getAllStages)1 StateChangeListener (com.facebook.presto.execution.StateMachine.StateChangeListener)1 GENERAL_POOL (com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL)1 VersionedMemoryPoolId (com.facebook.presto.memory.VersionedMemoryPoolId)1 Metadata (com.facebook.presto.metadata.Metadata)1