Search in sources :

Example 1 with SubPlan

use of io.prestosql.sql.planner.SubPlan in project hetu-core by openlookeng.

the class TestCostCalculator method calculateCostFragmentedPlan.

private PlanCostEstimate calculateCostFragmentedPlan(PlanNode node, StatsCalculator statsCalculator, Map<String, Type> types) {
    TypeProvider typeProvider = TypeProvider.copyOf(types.entrySet().stream().collect(ImmutableMap.toImmutableMap(entry -> new Symbol(entry.getKey()), Map.Entry::getValue)));
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, typeProvider);
    CostProvider costProvider = new CachingCostProvider(costCalculatorUsingExchanges, statsProvider, Optional.empty(), session, typeProvider);
    SubPlan subPlan = fragment(new Plan(node, typeProvider, StatsAndCosts.create(node, statsProvider, costProvider)));
    return subPlan.getFragment().getStatsAndCosts().getCosts().getOrDefault(node.getId(), PlanCostEstimate.unknown());
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) TypeProvider(io.prestosql.sql.planner.TypeProvider) SubPlan(io.prestosql.sql.planner.SubPlan) Plan(io.prestosql.sql.planner.Plan) SubPlan(io.prestosql.sql.planner.SubPlan)

Example 2 with SubPlan

use of io.prestosql.sql.planner.SubPlan in project hetu-core by openlookeng.

the class SqlQueryExecution method doAnalyzeQuery.

private PlanRoot doAnalyzeQuery() {
    // time analysis phase
    stateMachine.beginAnalysis();
    stateMachine.beginLogicalPlan();
    // plan query
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    Plan plan = createPlan(analysis, stateMachine.getSession(), planOptimizers, idAllocator, metadata, new TypeAnalyzer(sqlParser, metadata), statsCalculator, costCalculator, stateMachine.getWarningCollector());
    queryPlan.set(plan);
    // extract inputs
    List<Input> inputs = new InputExtractor(metadata, stateMachine.getSession()).extractInputs(plan.getRoot());
    stateMachine.setInputs(inputs);
    // extract output
    stateMachine.setOutput(analysis.getTarget());
    stateMachine.endLogicalPlan();
    // fragment the plan
    SubPlan fragmentedPlan = planFragmenter.createSubPlans(stateMachine.getSession(), plan, false, stateMachine.getWarningCollector());
    // record analysis time
    stateMachine.endAnalysis();
    boolean explainAnalyze = analysis.getStatement() instanceof Explain && ((Explain) analysis.getStatement()).isAnalyze();
    if (SystemSessionProperties.isSnapshotEnabled(getSession())) {
        checkSnapshotSupport(getSession());
    }
    return new PlanRoot(fragmentedPlan, !explainAnalyze, extractConnectors(analysis));
}
Also used : PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) Explain(io.prestosql.sql.tree.Explain) InputExtractor(io.prestosql.sql.planner.InputExtractor) SubPlan(io.prestosql.sql.planner.SubPlan) Plan(io.prestosql.sql.planner.Plan) StageExecutionPlan(io.prestosql.sql.planner.StageExecutionPlan) CachedSqlQueryExecutionPlan(io.prestosql.query.CachedSqlQueryExecutionPlan) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) SubPlan(io.prestosql.sql.planner.SubPlan)

Example 3 with SubPlan

use of io.prestosql.sql.planner.SubPlan in project hetu-core by openlookeng.

the class TestCostCalculator method assertCostFragmentedPlan.

private CostAssertionBuilder assertCostFragmentedPlan(PlanNode node, Map<String, PlanCostEstimate> costs, Map<String, PlanNodeStatsEstimate> stats, Map<String, Type> types) {
    TypeProvider typeProvider = TypeProvider.copyOf(types.entrySet().stream().collect(ImmutableMap.toImmutableMap(entry -> new Symbol(entry.getKey()), Map.Entry::getValue)));
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator(stats), session, typeProvider);
    CostProvider costProvider = new TestingCostProvider(costs, costCalculatorUsingExchanges, statsProvider, session, typeProvider);
    PlanNode plan = translateExpression(node, statsCalculator(stats), typeProvider);
    SubPlan subPlan = fragment(new Plan(plan, typeProvider, StatsAndCosts.create(plan, statsProvider, costProvider)));
    return new CostAssertionBuilder(subPlan.getFragment().getStatsAndCosts().getCosts().getOrDefault(plan.getId(), PlanCostEstimate.unknown()));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) TypeProvider(io.prestosql.sql.planner.TypeProvider) SubPlan(io.prestosql.sql.planner.SubPlan) Plan(io.prestosql.sql.planner.Plan) SubPlan(io.prestosql.sql.planner.SubPlan)

Example 4 with SubPlan

use of io.prestosql.sql.planner.SubPlan in project hetu-core by openlookeng.

the class LocalQueryRunner method createDrivers.

private List<Driver> createDrivers(Session session, Plan plan, OutputFactory outputFactory, TaskContext taskContext) {
    if (printPlan) {
        System.out.println(PlanPrinter.textLogicalPlan(plan.getRoot(), plan.getTypes(), metadata, plan.getStatsAndCosts(), session, 0, false));
    }
    SubPlan subplan = planFragmenter.createSubPlans(session, plan, true, WarningCollector.NOOP);
    if (!subplan.getChildren().isEmpty()) {
        throw new AssertionError("Expected subplan to have no children");
    }
    NodeInfo nodeInfo = new NodeInfo("test");
    FileSystemClientManager fileSystemClientManager = new FileSystemClientManager();
    SeedStoreManager seedStoreManager = new SeedStoreManager(fileSystemClientManager);
    StateStoreProvider stateStoreProvider = new LocalStateStoreProvider(seedStoreManager);
    LocalExecutionPlanner executionPlanner = new LocalExecutionPlanner(metadata, new TypeAnalyzer(sqlParser, metadata), Optional.empty(), pageSourceManager, indexManager, nodePartitioningManager, pageSinkManager, null, expressionCompiler, pageFunctionCompiler, joinFilterFunctionCompiler, new IndexJoinLookupStats(), this.taskManagerConfig, spillerFactory, singleStreamSpillerFactory, partitioningSpillerFactory, new PagesIndex.TestingFactory(false), joinCompiler, new LookupJoinOperators(), new OrderingCompiler(), nodeInfo, stateStoreProvider, new StateStoreListenerManager(stateStoreProvider), new DynamicFilterCacheManager(), heuristicIndexerManager, cubeManager);
    // plan query
    StageExecutionDescriptor stageExecutionDescriptor = subplan.getFragment().getStageExecutionDescriptor();
    LocalExecutionPlan localExecutionPlan = executionPlanner.plan(taskContext, stageExecutionDescriptor, subplan.getFragment().getRoot(), subplan.getFragment().getPartitioningScheme().getOutputLayout(), plan.getTypes(), subplan.getFragment().getPartitionedSources(), null, outputFactory, Optional.empty(), Optional.empty(), null);
    // generate sources
    List<TaskSource> sources = new ArrayList<>();
    long sequenceId = 0;
    for (TableScanNode tableScan : findTableScanNodes(subplan.getFragment().getRoot())) {
        TableHandle table = tableScan.getTable();
        SplitSource splitSource = splitManager.getSplits(session, table, stageExecutionDescriptor.isScanGroupedExecution(tableScan.getId()) ? GROUPED_SCHEDULING : UNGROUPED_SCHEDULING, null, Optional.empty(), Collections.emptyMap(), ImmutableSet.of(), tableScan.getStrategy() != ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, tableScan.getId());
        ImmutableSet.Builder<ScheduledSplit> scheduledSplits = ImmutableSet.builder();
        while (!splitSource.isFinished()) {
            for (Split split : getNextBatch(splitSource)) {
                scheduledSplits.add(new ScheduledSplit(sequenceId++, tableScan.getId(), split));
            }
        }
        sources.add(new TaskSource(tableScan.getId(), scheduledSplits.build(), true));
    }
    // create drivers
    List<Driver> drivers = new ArrayList<>();
    Map<PlanNodeId, DriverFactory> driverFactoriesBySource = new HashMap<>();
    for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
        for (int i = 0; i < driverFactory.getDriverInstances().orElse(1); i++) {
            if (driverFactory.getSourceId().isPresent()) {
                checkState(driverFactoriesBySource.put(driverFactory.getSourceId().get(), driverFactory) == null);
            } else {
                DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver(), false).addDriverContext();
                Driver driver = driverFactory.createDriver(driverContext);
                drivers.add(driver);
            }
        }
    }
    // add sources to the drivers
    ImmutableSet<PlanNodeId> partitionedSources = ImmutableSet.copyOf(subplan.getFragment().getPartitionedSources());
    for (TaskSource source : sources) {
        DriverFactory driverFactory = driverFactoriesBySource.get(source.getPlanNodeId());
        checkState(driverFactory != null);
        boolean partitioned = partitionedSources.contains(driverFactory.getSourceId().get());
        for (ScheduledSplit split : source.getSplits()) {
            DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver(), partitioned).addDriverContext();
            Driver driver = driverFactory.createDriver(driverContext);
            driver.updateSource(new TaskSource(split.getPlanNodeId(), ImmutableSet.of(split), true));
            drivers.add(driver);
        }
    }
    for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
        driverFactory.noMoreDrivers();
    }
    return ImmutableList.copyOf(drivers);
}
Also used : DriverContext(io.prestosql.operator.DriverContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StateStoreListenerManager(io.prestosql.statestore.listener.StateStoreListenerManager) Driver(io.prestosql.operator.Driver) PagesIndex(io.prestosql.operator.PagesIndex) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) ImmutableSet(com.google.common.collect.ImmutableSet) OrderingCompiler(io.prestosql.sql.gen.OrderingCompiler) DriverFactory(io.prestosql.operator.DriverFactory) LookupJoinOperators(io.prestosql.operator.LookupJoinOperators) DynamicFilterCacheManager(io.prestosql.dynamicfilter.DynamicFilterCacheManager) ScheduledSplit(io.prestosql.execution.ScheduledSplit) LocalExecutionPlanner(io.prestosql.sql.planner.LocalExecutionPlanner) IndexJoinLookupStats(io.prestosql.operator.index.IndexJoinLookupStats) StageExecutionDescriptor(io.prestosql.operator.StageExecutionDescriptor) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) LocalExecutionPlan(io.prestosql.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) TableScanNode(io.prestosql.spi.plan.TableScanNode) NodeInfo(io.airlift.node.NodeInfo) TableHandle(io.prestosql.spi.metadata.TableHandle) SplitSource(io.prestosql.split.SplitSource) Split(io.prestosql.metadata.Split) ScheduledSplit(io.prestosql.execution.ScheduledSplit) SubPlan(io.prestosql.sql.planner.SubPlan) TaskSource(io.prestosql.execution.TaskSource)

Example 5 with SubPlan

use of io.prestosql.sql.planner.SubPlan in project hetu-core by openlookeng.

the class GraphvizPrinter method printSubPlan.

private static void printSubPlan(SubPlan plan, Map<PlanFragmentId, PlanFragment> fragmentsById, PlanNodeIdGenerator idGenerator, StringBuilder output) {
    PlanFragment fragment = plan.getFragment();
    printFragmentNodes(output, fragment, idGenerator);
    fragment.getRoot().accept(new EdgePrinter(output, fragmentsById, idGenerator), null);
    for (SubPlan child : plan.getChildren()) {
        printSubPlan(child, fragmentsById, idGenerator, output);
    }
}
Also used : PlanFragment(io.prestosql.sql.planner.PlanFragment) SubPlan(io.prestosql.sql.planner.SubPlan)

Aggregations

SubPlan (io.prestosql.sql.planner.SubPlan)5 Plan (io.prestosql.sql.planner.Plan)3 Symbol (io.prestosql.spi.plan.Symbol)2 TypeAnalyzer (io.prestosql.sql.planner.TypeAnalyzer)2 TypeProvider (io.prestosql.sql.planner.TypeProvider)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 NodeInfo (io.airlift.node.NodeInfo)1 DynamicFilterCacheManager (io.prestosql.dynamicfilter.DynamicFilterCacheManager)1 ScheduledSplit (io.prestosql.execution.ScheduledSplit)1 TaskSource (io.prestosql.execution.TaskSource)1 FileSystemClientManager (io.prestosql.filesystem.FileSystemClientManager)1 Split (io.prestosql.metadata.Split)1 Driver (io.prestosql.operator.Driver)1 DriverContext (io.prestosql.operator.DriverContext)1 DriverFactory (io.prestosql.operator.DriverFactory)1 LookupJoinOperators (io.prestosql.operator.LookupJoinOperators)1 PagesIndex (io.prestosql.operator.PagesIndex)1 StageExecutionDescriptor (io.prestosql.operator.StageExecutionDescriptor)1 IndexJoinLookupStats (io.prestosql.operator.index.IndexJoinLookupStats)1 CachedSqlQueryExecutionPlan (io.prestosql.query.CachedSqlQueryExecutionPlan)1