Search in sources :

Example 1 with QueryType

use of com.facebook.presto.spi.resourceGroups.QueryType in project presto by prestodb.

the class PrestoSparkQueryPlanner method createQueryPlan.

public PlanAndMore createQueryPlan(Session session, PreparedQuery preparedQuery, WarningCollector warningCollector) {
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(queryExplainer), preparedQuery.getParameters(), warningCollector);
    LogicalPlanner logicalPlanner = new LogicalPlanner(false, session, optimizers.getPlanningTimeOptimizers(), idAllocator, metadata, sqlParser, statsCalculator, costCalculator, warningCollector, planChecker);
    Analysis analysis = analyzer.analyze(preparedQuery.getStatement());
    Plan plan = logicalPlanner.plan(analysis, OPTIMIZED_AND_VALIDATED);
    List<Input> inputs = new InputExtractor(metadata, session).extractInputs(plan.getRoot());
    Optional<Output> output = new OutputExtractor().extractOutput(plan.getRoot());
    Optional<QueryType> queryType = getQueryType(preparedQuery.getStatement().getClass());
    List<String> columnNames = ((OutputNode) plan.getRoot()).getColumnNames();
    return new PlanAndMore(plan, Optional.ofNullable(analysis.getUpdateType()), columnNames, ImmutableSet.copyOf(inputs), output, queryType);
}
Also used : OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) InputExtractor(com.facebook.presto.sql.planner.InputExtractor) Analyzer(com.facebook.presto.sql.analyzer.Analyzer) Plan(com.facebook.presto.sql.planner.Plan) Input(com.facebook.presto.execution.Input) OutputExtractor(com.facebook.presto.sql.planner.OutputExtractor) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) Analysis(com.facebook.presto.sql.analyzer.Analysis) Output(com.facebook.presto.execution.Output) StatementUtils.getQueryType(com.facebook.presto.util.StatementUtils.getQueryType) QueryType(com.facebook.presto.spi.resourceGroups.QueryType)

Example 2 with QueryType

use of com.facebook.presto.spi.resourceGroups.QueryType 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)

Example 3 with QueryType

use of com.facebook.presto.spi.resourceGroups.QueryType in project presto by prestodb.

the class QueryPreparer method prepareQuery.

public PreparedQuery prepareQuery(Session session, Statement wrappedStatement, WarningCollector warningCollector) throws ParsingException, PrestoException, SemanticException {
    Statement statement = wrappedStatement;
    Optional<String> prepareSql = Optional.empty();
    if (statement instanceof Execute) {
        prepareSql = Optional.of(session.getPreparedStatementFromExecute((Execute) statement));
        statement = sqlParser.createStatement(prepareSql.get(), createParsingOptions(session, warningCollector));
    }
    if (statement instanceof Explain && ((Explain) statement).isAnalyze()) {
        Statement innerStatement = ((Explain) statement).getStatement();
        Optional<QueryType> innerQueryType = StatementUtils.getQueryType(innerStatement.getClass());
        if (!innerQueryType.isPresent() || innerQueryType.get() == QueryType.DATA_DEFINITION) {
            throw new PrestoException(NOT_SUPPORTED, "EXPLAIN ANALYZE doesn't support statement type: " + innerStatement.getClass().getSimpleName());
        }
    }
    List<Expression> parameters = ImmutableList.of();
    if (wrappedStatement instanceof Execute) {
        parameters = ((Execute) wrappedStatement).getParameters();
    }
    validateParameters(statement, parameters);
    Optional<String> formattedQuery = Optional.empty();
    if (isLogFormattedQueryEnabled(session)) {
        formattedQuery = Optional.of(getFormattedQuery(statement, parameters));
    }
    return new PreparedQuery(statement, parameters, formattedQuery, prepareSql);
}
Also used : Execute(com.facebook.presto.sql.tree.Execute) Expression(com.facebook.presto.sql.tree.Expression) Statement(com.facebook.presto.sql.tree.Statement) Explain(com.facebook.presto.sql.tree.Explain) PrestoException(com.facebook.presto.spi.PrestoException) QueryType(com.facebook.presto.spi.resourceGroups.QueryType)

Example 4 with QueryType

use of com.facebook.presto.spi.resourceGroups.QueryType in project presto by prestodb.

the class DispatchManager method createQueryInternal.

/**
 *  Creates and registers a dispatch query with the query tracker.  This method will never fail to register a query with the query
 *  tracker.  If an error occurs while, creating a dispatch query a failed dispatch will be created and registered.
 */
private <C> void createQueryInternal(QueryId queryId, String slug, int retryCount, SessionContext sessionContext, String query, ResourceGroupManager<C> resourceGroupManager) {
    Session session = null;
    PreparedQuery preparedQuery;
    try {
        if (query.length() > maxQueryLength) {
            int queryLength = query.length();
            query = query.substring(0, maxQueryLength);
            throw new PrestoException(QUERY_TEXT_TOO_LARGE, format("Query text length (%s) exceeds the maximum length (%s)", queryLength, maxQueryLength));
        }
        // decode session
        session = sessionSupplier.createSession(queryId, sessionContext);
        // prepare query
        WarningCollector warningCollector = warningCollectorFactory.create(getWarningHandlingLevel(session));
        preparedQuery = queryPreparer.prepareQuery(session, query, warningCollector);
        query = preparedQuery.getFormattedQuery().orElse(query);
        // select resource group
        Optional<QueryType> queryType = getQueryType(preparedQuery.getStatement().getClass());
        SelectionContext<C> selectionContext = resourceGroupManager.selectGroup(new SelectionCriteria(sessionContext.getIdentity().getPrincipal().isPresent(), sessionContext.getIdentity().getUser(), Optional.ofNullable(sessionContext.getSource()), sessionContext.getClientTags(), sessionContext.getResourceEstimates(), queryType.map(Enum::name)));
        // apply system default session properties (does not override user set properties)
        session = sessionPropertyDefaults.newSessionWithDefaultProperties(session, queryType.map(Enum::name), Optional.of(selectionContext.getResourceGroupId()));
        // mark existing transaction as active
        transactionManager.activateTransaction(session, isTransactionControlStatement(preparedQuery.getStatement()), accessControl);
        DispatchQuery dispatchQuery = dispatchQueryFactory.createDispatchQuery(session, query, preparedQuery, slug, retryCount, selectionContext.getResourceGroupId(), queryType, warningCollector, (dq) -> resourceGroupManager.submit(preparedQuery.getStatement(), dq, selectionContext, queryExecutor));
        boolean queryAdded = queryCreated(dispatchQuery);
        if (queryAdded && !dispatchQuery.isDone()) {
            try {
                clusterStatusSender.registerQuery(dispatchQuery);
                dispatchQuery.startWaitingForPrerequisites();
            } catch (Throwable e) {
                // dispatch query has already been registered, so just fail it directly
                dispatchQuery.fail(e);
            }
        }
    } catch (Throwable throwable) {
        // creation must never fail, so register a failed query in this case
        if (session == null) {
            session = Session.builder(new SessionPropertyManager()).setQueryId(queryId).setIdentity(sessionContext.getIdentity()).setSource(sessionContext.getSource()).build();
        }
        DispatchQuery failedDispatchQuery = failedDispatchQueryFactory.createFailedDispatchQuery(session, query, Optional.empty(), throwable);
        queryCreated(failedDispatchQuery);
    }
}
Also used : PreparedQuery(com.facebook.presto.execution.QueryPreparer.PreparedQuery) PrestoException(com.facebook.presto.spi.PrestoException) SelectionCriteria(com.facebook.presto.spi.resourceGroups.SelectionCriteria) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) WarningCollector(com.facebook.presto.spi.WarningCollector) StatementUtils.getQueryType(com.facebook.presto.util.StatementUtils.getQueryType) QueryType(com.facebook.presto.spi.resourceGroups.QueryType) Session(com.facebook.presto.Session)

Example 5 with QueryType

use of com.facebook.presto.spi.resourceGroups.QueryType in project presto by prestodb.

the class CoordinatorModule method setup.

@Override
protected void setup(Binder binder) {
    httpServerBinder(binder).bindResource("/ui", "webapp").withWelcomeFile("index.html");
    httpServerBinder(binder).bindResource("/tableau", "webapp/tableau");
    // discovery server
    install(installModuleIf(EmbeddedDiscoveryConfig.class, EmbeddedDiscoveryConfig::isEnabled, new EmbeddedDiscoveryModule()));
    // presto coordinator announcement
    discoveryBinder(binder).bindHttpAnnouncement("presto-coordinator");
    // statement resource
    jsonCodecBinder(binder).bindJsonCodec(QueryInfo.class);
    jsonCodecBinder(binder).bindJsonCodec(TaskInfo.class);
    jsonCodecBinder(binder).bindJsonCodec(QueryResults.class);
    jsonCodecBinder(binder).bindJsonCodec(SelectedRole.class);
    jaxrsBinder(binder).bind(QueuedStatementResource.class);
    jaxrsBinder(binder).bind(ExecutingStatementResource.class);
    binder.bind(StatementHttpExecutionMBean.class).in(Scopes.SINGLETON);
    newExporter(binder).export(StatementHttpExecutionMBean.class).withGeneratedName();
    // resource for serving static content
    jaxrsBinder(binder).bind(WebUiResource.class);
    // failure detector
    binder.install(new FailureDetectorModule());
    jaxrsBinder(binder).bind(NodeResource.class);
    jaxrsBinder(binder).bind(WorkerResource.class);
    httpClientBinder(binder).bindHttpClient("workerInfo", ForWorkerInfo.class);
    // query monitor
    jsonCodecBinder(binder).bindJsonCodec(OperatorInfo.class);
    configBinder(binder).bindConfig(QueryMonitorConfig.class);
    binder.bind(QueryMonitor.class).in(Scopes.SINGLETON);
    // query manager
    jaxrsBinder(binder).bind(QueryResource.class);
    jaxrsBinder(binder).bind(StageResource.class);
    jaxrsBinder(binder).bind(QueryStateInfoResource.class);
    jaxrsBinder(binder).bind(ResourceGroupStateInfoResource.class);
    binder.bind(QueryIdGenerator.class).in(Scopes.SINGLETON);
    binder.bind(QueryManager.class).to(SqlQueryManager.class).in(Scopes.SINGLETON);
    newExporter(binder).export(QueryManager.class).withGeneratedName();
    binder.bind(QueryPreparer.class).in(Scopes.SINGLETON);
    binder.bind(SessionSupplier.class).to(QuerySessionSupplier.class).in(Scopes.SINGLETON);
    binder.bind(InternalResourceGroupManager.class).in(Scopes.SINGLETON);
    newExporter(binder).export(InternalResourceGroupManager.class).withGeneratedName();
    binder.bind(ResourceGroupManager.class).to(InternalResourceGroupManager.class);
    binder.bind(LegacyResourceGroupConfigurationManager.class).in(Scopes.SINGLETON);
    binder.bind(RetryCircuitBreaker.class).in(Scopes.SINGLETON);
    newExporter(binder).export(RetryCircuitBreaker.class).withGeneratedName();
    binder.bind(LocalQueryProvider.class).in(Scopes.SINGLETON);
    jaxrsBinder(binder).bind(TaskInfoResource.class);
    // dispatcher
    binder.bind(DispatchManager.class).in(Scopes.SINGLETON);
    binder.bind(FailedDispatchQueryFactory.class).in(Scopes.SINGLETON);
    binder.bind(DispatchExecutor.class).in(Scopes.SINGLETON);
    // local dispatcher
    binder.bind(DispatchQueryFactory.class).to(LocalDispatchQueryFactory.class);
    // cluster memory manager
    binder.bind(ClusterMemoryManager.class).in(Scopes.SINGLETON);
    binder.bind(ClusterMemoryPoolManager.class).to(ClusterMemoryManager.class).in(Scopes.SINGLETON);
    httpClientBinder(binder).bindHttpClient("memoryManager", ForMemoryManager.class).withTracing().withConfigDefaults(config -> {
        config.setRequestTimeout(new Duration(10, SECONDS));
    });
    bindLowMemoryKiller(LowMemoryKillerPolicy.NONE, NoneLowMemoryKiller.class);
    bindLowMemoryKiller(LowMemoryKillerPolicy.TOTAL_RESERVATION, TotalReservationLowMemoryKiller.class);
    bindLowMemoryKiller(LowMemoryKillerPolicy.TOTAL_RESERVATION_ON_BLOCKED_NODES, TotalReservationOnBlockedNodesLowMemoryKiller.class);
    newExporter(binder).export(ClusterMemoryManager.class).withGeneratedName();
    // node monitor
    binder.bind(ClusterSizeMonitor.class).in(Scopes.SINGLETON);
    // statistics calculator
    binder.install(new StatsCalculatorModule());
    // cost calculator
    binder.bind(TaskCountEstimator.class).in(Scopes.SINGLETON);
    binder.bind(CostCalculator.class).to(CostCalculatorUsingExchanges.class).in(Scopes.SINGLETON);
    binder.bind(CostCalculator.class).annotatedWith(EstimatedExchanges.class).to(CostCalculatorWithEstimatedExchanges.class).in(Scopes.SINGLETON);
    binder.bind(CostComparator.class).in(Scopes.SINGLETON);
    // cluster statistics
    jaxrsBinder(binder).bind(ClusterStatsResource.class);
    // planner
    binder.bind(PlanFragmenter.class).in(Scopes.SINGLETON);
    binder.bind(PlanOptimizers.class).in(Scopes.SINGLETON);
    // query explainer
    binder.bind(QueryExplainer.class).in(Scopes.SINGLETON);
    // explain analyze
    binder.bind(ExplainAnalyzeContext.class).in(Scopes.SINGLETON);
    // execution scheduler
    binder.bind(RemoteTaskFactory.class).to(HttpRemoteTaskFactory.class).in(Scopes.SINGLETON);
    newExporter(binder).export(RemoteTaskFactory.class).withGeneratedName();
    binder.bind(RemoteTaskStats.class).in(Scopes.SINGLETON);
    newExporter(binder).export(RemoteTaskStats.class).withGeneratedName();
    httpClientBinder(binder).bindHttpClient("scheduler", ForScheduler.class).withTracing().withFilter(GenerateTraceTokenRequestFilter.class).withConfigDefaults(config -> {
        config.setRequestTimeout(new Duration(10, SECONDS));
        config.setMaxConnectionsPerServer(250);
    });
    binder.bind(ScheduledExecutorService.class).annotatedWith(ForScheduler.class).toInstance(newSingleThreadScheduledExecutor(threadsNamed("stage-scheduler")));
    // query execution
    binder.bind(ExecutorService.class).annotatedWith(ForQueryExecution.class).toInstance(newCachedThreadPool(threadsNamed("query-execution-%s")));
    binder.bind(QueryExecutionMBean.class).in(Scopes.SINGLETON);
    newExporter(binder).export(QueryExecutionMBean.class).as(generatedNameOf(QueryExecution.class));
    MapBinder<Class<? extends Statement>, QueryExecutionFactory<?>> executionBinder = newMapBinder(binder, new TypeLiteral<Class<? extends Statement>>() {
    }, new TypeLiteral<QueryExecution.QueryExecutionFactory<?>>() {
    });
    binder.bind(SplitSchedulerStats.class).in(Scopes.SINGLETON);
    newExporter(binder).export(SplitSchedulerStats.class).withGeneratedName();
    binder.bind(SqlQueryExecutionFactory.class).in(Scopes.SINGLETON);
    binder.bind(SectionExecutionFactory.class).in(Scopes.SINGLETON);
    Set<Map.Entry<Class<? extends Statement>, QueryType>> queryTypes = getAllQueryTypes().entrySet();
    // bind sql query statements to SqlQueryExecutionFactory
    queryTypes.stream().filter(entry -> entry.getValue() != QueryType.DATA_DEFINITION).forEach(entry -> executionBinder.addBinding(entry.getKey()).to(SqlQueryExecutionFactory.class).in(Scopes.SINGLETON));
    binder.bind(PartialResultQueryManager.class).in(Scopes.SINGLETON);
    // bind data definition statements to DataDefinitionExecutionFactory
    queryTypes.stream().filter(entry -> entry.getValue() == QueryType.DATA_DEFINITION && !isSessionTransactionControlStatement(entry.getKey())).forEach(entry -> executionBinder.addBinding(entry.getKey()).to(DDLDefinitionExecutionFactory.class).in(Scopes.SINGLETON));
    binder.bind(DDLDefinitionExecutionFactory.class).in(Scopes.SINGLETON);
    // bind session Control statements to SessionTransactionExecutionFactory
    queryTypes.stream().filter(entry -> (entry.getValue() == QueryType.DATA_DEFINITION && isSessionTransactionControlStatement(entry.getKey()))).forEach(entry -> executionBinder.addBinding(entry.getKey()).to(SessionDefinitionExecutionFactory.class).in(Scopes.SINGLETON));
    binder.bind(SessionDefinitionExecutionFactory.class).in(Scopes.SINGLETON);
    // helper class binding data definition tasks and statements
    PrestoDataDefBindingHelper.bindDDLDefinitionTasks(binder);
    PrestoDataDefBindingHelper.bindTransactionControlDefinitionTasks(binder);
    MapBinder<String, ExecutionPolicy> executionPolicyBinder = newMapBinder(binder, String.class, ExecutionPolicy.class);
    executionPolicyBinder.addBinding("all-at-once").to(AllAtOnceExecutionPolicy.class);
    executionPolicyBinder.addBinding("phased").to(PhasedExecutionPolicy.class);
    configBinder(binder).bindConfig(NodeResourceStatusConfig.class);
    binder.bind(NodeResourceStatusProvider.class).to(NodeResourceStatus.class).in(Scopes.SINGLETON);
    newOptionalBinder(binder, ResourceManagerProxy.class);
    install(installModuleIf(ServerConfig.class, ServerConfig::isResourceManagerEnabled, rmBinder -> {
        httpClientBinder(rmBinder).bindHttpClient("resourceManager", ForResourceManager.class);
        rmBinder.bind(ResourceManagerProxy.class).in(Scopes.SINGLETON);
    }));
    // cleanup
    binder.bind(ExecutorCleanup.class).in(Scopes.SINGLETON);
}
Also used : JaxrsBinder.jaxrsBinder(com.facebook.airlift.jaxrs.JaxrsBinder.jaxrsBinder) QueryExplainer(com.facebook.presto.sql.analyzer.QueryExplainer) QueryPerformanceFetcher(com.facebook.presto.execution.QueryPerformanceFetcher) QueryExecutionFactory(com.facebook.presto.execution.QueryExecution.QueryExecutionFactory) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Map(java.util.Map) SqlQueryExecutionFactory(com.facebook.presto.execution.SqlQueryExecution.SqlQueryExecutionFactory) TaskCountEstimator(com.facebook.presto.cost.TaskCountEstimator) RemoteTaskFactory(com.facebook.presto.execution.RemoteTaskFactory) PhasedExecutionPolicy(com.facebook.presto.execution.scheduler.PhasedExecutionPolicy) Set(java.util.Set) QueryIdGenerator(com.facebook.presto.execution.QueryIdGenerator) ForMemoryManager(com.facebook.presto.memory.ForMemoryManager) RetryCircuitBreaker(com.facebook.presto.server.protocol.RetryCircuitBreaker) QueryExecution(com.facebook.presto.execution.QueryExecution) QueryInfo(com.facebook.presto.execution.QueryInfo) QueryPreparer(com.facebook.presto.execution.QueryPreparer) NodeResourceStatusConfig(com.facebook.presto.execution.NodeResourceStatusConfig) InternalResourceGroupManager(com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager) TypeLiteral(com.google.inject.TypeLiteral) DispatchExecutor(com.facebook.presto.dispatcher.DispatchExecutor) EmbeddedDiscoveryModule(com.facebook.airlift.discovery.server.EmbeddedDiscoveryModule) Binder(com.google.inject.Binder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LocalDispatchQueryFactory(com.facebook.presto.dispatcher.LocalDispatchQueryFactory) NoneLowMemoryKiller(com.facebook.presto.memory.NoneLowMemoryKiller) ExecutingStatementResource(com.facebook.presto.server.protocol.ExecutingStatementResource) RemoteTaskStats(com.facebook.presto.server.remotetask.RemoteTaskStats) TransactionManager(com.facebook.presto.transaction.TransactionManager) ResourceGroupManager(com.facebook.presto.execution.resourceGroups.ResourceGroupManager) DDLDefinitionExecutionFactory(com.facebook.presto.execution.DDLDefinitionExecution.DDLDefinitionExecutionFactory) LegacyResourceGroupConfigurationManager(com.facebook.presto.execution.resourceGroups.LegacyResourceGroupConfigurationManager) ClusterMemoryPoolManager(com.facebook.presto.spi.memory.ClusterMemoryPoolManager) Threads.threadsNamed(com.facebook.airlift.concurrent.Threads.threadsNamed) QueryExecutionMBean(com.facebook.presto.execution.QueryExecutionMBean) AllAtOnceExecutionPolicy(com.facebook.presto.execution.scheduler.AllAtOnceExecutionPolicy) QueryMonitor(com.facebook.presto.event.QueryMonitor) InMemoryTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager) ForQueryExecution(com.facebook.presto.execution.ForQueryExecution) ClusterSizeMonitor(com.facebook.presto.execution.ClusterSizeMonitor) TaskInfo(com.facebook.presto.execution.TaskInfo) CostCalculatorWithEstimatedExchanges(com.facebook.presto.cost.CostCalculatorWithEstimatedExchanges) ForScheduler(com.facebook.presto.operator.ForScheduler) EstimatedExchanges(com.facebook.presto.cost.CostCalculator.EstimatedExchanges) SectionExecutionFactory(com.facebook.presto.execution.scheduler.SectionExecutionFactory) TaskManagerConfig(com.facebook.presto.execution.TaskManagerConfig) Duration(io.airlift.units.Duration) PreDestroy(javax.annotation.PreDestroy) AbstractConfigurationAwareModule(com.facebook.airlift.configuration.AbstractConfigurationAwareModule) HttpClientBinder.httpClientBinder(com.facebook.airlift.http.client.HttpClientBinder.httpClientBinder) ExportBinder.newExporter(org.weakref.jmx.guice.ExportBinder.newExporter) OperatorInfo(com.facebook.presto.operator.OperatorInfo) MapBinder(com.google.inject.multibindings.MapBinder) ExecutionPolicy(com.facebook.presto.execution.scheduler.ExecutionPolicy) OptionalBinder.newOptionalBinder(com.google.inject.multibindings.OptionalBinder.newOptionalBinder) ForResourceManager(com.facebook.presto.resourcemanager.ForResourceManager) ResourceManagerProxy(com.facebook.presto.resourcemanager.ResourceManagerProxy) StatementUtils.isSessionTransactionControlStatement(com.facebook.presto.util.StatementUtils.isSessionTransactionControlStatement) SplitSchedulerStats(com.facebook.presto.execution.scheduler.SplitSchedulerStats) ConditionalModule.installModuleIf(com.facebook.airlift.configuration.ConditionalModule.installModuleIf) CostCalculatorUsingExchanges(com.facebook.presto.cost.CostCalculatorUsingExchanges) CostCalculator(com.facebook.presto.cost.CostCalculator) LowMemoryKiller(com.facebook.presto.memory.LowMemoryKiller) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) List(java.util.List) StatementUtils.getAllQueryTypes(com.facebook.presto.util.StatementUtils.getAllQueryTypes) TransactionManagerConfig(com.facebook.presto.transaction.TransactionManagerConfig) PrestoDataDefBindingHelper(com.facebook.presto.util.PrestoDataDefBindingHelper) DispatchQueryFactory(com.facebook.presto.dispatcher.DispatchQueryFactory) HttpRemoteTaskFactory(com.facebook.presto.server.remotetask.HttpRemoteTaskFactory) TotalReservationLowMemoryKiller(com.facebook.presto.memory.TotalReservationLowMemoryKiller) QueryResults(com.facebook.presto.client.QueryResults) ForTransactionManager(com.facebook.presto.transaction.ForTransactionManager) QueryManager(com.facebook.presto.execution.QueryManager) Singleton(javax.inject.Singleton) JsonCodecBinder.jsonCodecBinder(com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder) StatsCalculatorModule(com.facebook.presto.cost.StatsCalculatorModule) PlanOptimizers(com.facebook.presto.sql.planner.PlanOptimizers) Inject(javax.inject.Inject) BoundedExecutor(com.facebook.airlift.concurrent.BoundedExecutor) ImmutableList(com.google.common.collect.ImmutableList) ExplainAnalyzeContext(com.facebook.presto.execution.ExplainAnalyzeContext) MemoryManagerConfig(com.facebook.presto.memory.MemoryManagerConfig) PlanFragmenter(com.facebook.presto.sql.planner.PlanFragmenter) ExecutorService(java.util.concurrent.ExecutorService) SelectedRole(com.facebook.presto.spi.security.SelectedRole) MapBinder.newMapBinder(com.google.inject.multibindings.MapBinder.newMapBinder) SessionDefinitionExecutionFactory(com.facebook.presto.execution.SessionDefinitionExecution.SessionDefinitionExecutionFactory) ObjectNames.generatedNameOf(org.weakref.jmx.ObjectNames.generatedNameOf) ClusterMemoryManager(com.facebook.presto.memory.ClusterMemoryManager) LocalQueryProvider(com.facebook.presto.server.protocol.LocalQueryProvider) DispatchManager(com.facebook.presto.dispatcher.DispatchManager) LowMemoryKillerPolicy(com.facebook.presto.memory.MemoryManagerConfig.LowMemoryKillerPolicy) Scopes(com.google.inject.Scopes) CatalogManager(com.facebook.presto.metadata.CatalogManager) TotalReservationOnBlockedNodesLowMemoryKiller(com.facebook.presto.memory.TotalReservationOnBlockedNodesLowMemoryKiller) FailureDetectorModule(com.facebook.presto.failureDetector.FailureDetectorModule) Provides(com.google.inject.Provides) QueryMonitorConfig(com.facebook.presto.event.QueryMonitorConfig) QueuedStatementResource(com.facebook.presto.server.protocol.QueuedStatementResource) QueryType(com.facebook.presto.spi.resourceGroups.QueryType) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) HttpServerBinder.httpServerBinder(com.facebook.airlift.http.server.HttpServerBinder.httpServerBinder) CostComparator(com.facebook.presto.cost.CostComparator) FailedDispatchQueryFactory(com.facebook.presto.dispatcher.FailedDispatchQueryFactory) SqlQueryManager(com.facebook.presto.execution.SqlQueryManager) ConfigBinder.configBinder(com.facebook.airlift.configuration.ConfigBinder.configBinder) DiscoveryBinder.discoveryBinder(com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder) SECONDS(java.util.concurrent.TimeUnit.SECONDS) PartialResultQueryManager(com.facebook.presto.execution.PartialResultQueryManager) Statement(com.facebook.presto.sql.tree.Statement) QueryIdGenerator(com.facebook.presto.execution.QueryIdGenerator) DispatchManager(com.facebook.presto.dispatcher.DispatchManager) FailureDetectorModule(com.facebook.presto.failureDetector.FailureDetectorModule) RetryCircuitBreaker(com.facebook.presto.server.protocol.RetryCircuitBreaker) QueryPreparer(com.facebook.presto.execution.QueryPreparer) RemoteTaskStats(com.facebook.presto.server.remotetask.RemoteTaskStats) QueryMonitor(com.facebook.presto.event.QueryMonitor) HttpRemoteTaskFactory(com.facebook.presto.server.remotetask.HttpRemoteTaskFactory) QueryExecutionMBean(com.facebook.presto.execution.QueryExecutionMBean) LegacyResourceGroupConfigurationManager(com.facebook.presto.execution.resourceGroups.LegacyResourceGroupConfigurationManager) RemoteTaskFactory(com.facebook.presto.execution.RemoteTaskFactory) HttpRemoteTaskFactory(com.facebook.presto.server.remotetask.HttpRemoteTaskFactory) DDLDefinitionExecutionFactory(com.facebook.presto.execution.DDLDefinitionExecution.DDLDefinitionExecutionFactory) QueryExplainer(com.facebook.presto.sql.analyzer.QueryExplainer) InternalResourceGroupManager(com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager) ResourceGroupManager(com.facebook.presto.execution.resourceGroups.ResourceGroupManager) Duration(io.airlift.units.Duration) PartialResultQueryManager(com.facebook.presto.execution.PartialResultQueryManager) LocalQueryProvider(com.facebook.presto.server.protocol.LocalQueryProvider) SplitSchedulerStats(com.facebook.presto.execution.scheduler.SplitSchedulerStats) QueryExecutionFactory(com.facebook.presto.execution.QueryExecution.QueryExecutionFactory) SqlQueryExecutionFactory(com.facebook.presto.execution.SqlQueryExecution.SqlQueryExecutionFactory) PlanOptimizers(com.facebook.presto.sql.planner.PlanOptimizers) CostCalculatorWithEstimatedExchanges(com.facebook.presto.cost.CostCalculatorWithEstimatedExchanges) ForQueryExecution(com.facebook.presto.execution.ForQueryExecution) SessionDefinitionExecutionFactory(com.facebook.presto.execution.SessionDefinitionExecution.SessionDefinitionExecutionFactory) PlanFragmenter(com.facebook.presto.sql.planner.PlanFragmenter) QueryExecution(com.facebook.presto.execution.QueryExecution) ForQueryExecution(com.facebook.presto.execution.ForQueryExecution) FailedDispatchQueryFactory(com.facebook.presto.dispatcher.FailedDispatchQueryFactory) SqlQueryExecutionFactory(com.facebook.presto.execution.SqlQueryExecution.SqlQueryExecutionFactory) InternalResourceGroupManager(com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager) CostCalculatorUsingExchanges(com.facebook.presto.cost.CostCalculatorUsingExchanges) ForScheduler(com.facebook.presto.operator.ForScheduler) ExplainAnalyzeContext(com.facebook.presto.execution.ExplainAnalyzeContext) ClusterSizeMonitor(com.facebook.presto.execution.ClusterSizeMonitor) StatsCalculatorModule(com.facebook.presto.cost.StatsCalculatorModule) TaskCountEstimator(com.facebook.presto.cost.TaskCountEstimator) CostComparator(com.facebook.presto.cost.CostComparator) ForResourceManager(com.facebook.presto.resourcemanager.ForResourceManager) StatementUtils.isSessionTransactionControlStatement(com.facebook.presto.util.StatementUtils.isSessionTransactionControlStatement) Statement(com.facebook.presto.sql.tree.Statement) EmbeddedDiscoveryModule(com.facebook.airlift.discovery.server.EmbeddedDiscoveryModule) CostCalculator(com.facebook.presto.cost.CostCalculator) LocalDispatchQueryFactory(com.facebook.presto.dispatcher.LocalDispatchQueryFactory) DispatchQueryFactory(com.facebook.presto.dispatcher.DispatchQueryFactory) FailedDispatchQueryFactory(com.facebook.presto.dispatcher.FailedDispatchQueryFactory) PhasedExecutionPolicy(com.facebook.presto.execution.scheduler.PhasedExecutionPolicy) AllAtOnceExecutionPolicy(com.facebook.presto.execution.scheduler.AllAtOnceExecutionPolicy) ExecutionPolicy(com.facebook.presto.execution.scheduler.ExecutionPolicy) ClusterMemoryManager(com.facebook.presto.memory.ClusterMemoryManager) QueryManager(com.facebook.presto.execution.QueryManager) SqlQueryManager(com.facebook.presto.execution.SqlQueryManager) PartialResultQueryManager(com.facebook.presto.execution.PartialResultQueryManager) DispatchExecutor(com.facebook.presto.dispatcher.DispatchExecutor) SectionExecutionFactory(com.facebook.presto.execution.scheduler.SectionExecutionFactory) SqlQueryManager(com.facebook.presto.execution.SqlQueryManager)

Aggregations

QueryType (com.facebook.presto.spi.resourceGroups.QueryType)6 PrestoException (com.facebook.presto.spi.PrestoException)4 Session (com.facebook.presto.Session)3 WarningCollector (com.facebook.presto.spi.WarningCollector)3 QueryInfo (com.facebook.presto.execution.QueryInfo)2 PreparedQuery (com.facebook.presto.execution.QueryPreparer.PreparedQuery)2 Statement (com.facebook.presto.sql.tree.Statement)2 Duration (io.airlift.units.Duration)2 BoundedExecutor (com.facebook.airlift.concurrent.BoundedExecutor)1 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)1 Threads.threadsNamed (com.facebook.airlift.concurrent.Threads.threadsNamed)1 AbstractConfigurationAwareModule (com.facebook.airlift.configuration.AbstractConfigurationAwareModule)1 ConditionalModule.installModuleIf (com.facebook.airlift.configuration.ConditionalModule.installModuleIf)1 ConfigBinder.configBinder (com.facebook.airlift.configuration.ConfigBinder.configBinder)1 DiscoveryBinder.discoveryBinder (com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder)1 EmbeddedDiscoveryModule (com.facebook.airlift.discovery.server.EmbeddedDiscoveryModule)1 HttpClientBinder.httpClientBinder (com.facebook.airlift.http.client.HttpClientBinder.httpClientBinder)1 HttpServerBinder.httpServerBinder (com.facebook.airlift.http.server.HttpServerBinder.httpServerBinder)1 JaxrsBinder.jaxrsBinder (com.facebook.airlift.jaxrs.JaxrsBinder.jaxrsBinder)1 JsonCodecBinder.jsonCodecBinder (com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder)1