Search in sources :

Example 1 with LocalExecutionPlanner

use of com.facebook.presto.sql.planner.LocalExecutionPlanner in project presto by prestodb.

the class LocalQueryRunner method createDrivers.

public List<Driver> createDrivers(Session session, @Language("SQL") String sql, OutputFactory outputFactory, TaskContext taskContext) {
    Plan plan = createPlan(session, sql);
    if (printPlan) {
        System.out.println(PlanPrinter.textLogicalPlan(plan.getRoot(), plan.getTypes(), metadata, session));
    }
    SubPlan subplan = PlanFragmenter.createSubPlans(session, metadata, plan);
    if (!subplan.getChildren().isEmpty()) {
        throw new AssertionError("Expected subplan to have no children");
    }
    LocalExecutionPlanner executionPlanner = new LocalExecutionPlanner(metadata, sqlParser, Optional.empty(), pageSourceManager, indexManager, nodePartitioningManager, pageSinkManager, null, expressionCompiler, joinFilterFunctionCompiler, new IndexJoinLookupStats(), // make sure tests fail if compiler breaks
    new CompilerConfig().setInterpreterEnabled(false), new TaskManagerConfig().setTaskConcurrency(4), spillerFactory, blockEncodingSerde, new PagesIndex.TestingFactory(), new JoinCompiler(), new LookupJoinOperators(new JoinProbeCompiler()));
    // plan query
    LocalExecutionPlan localExecutionPlan = executionPlanner.plan(session, subplan.getFragment().getRoot(), subplan.getFragment().getPartitioningScheme().getOutputLayout(), plan.getTypes(), outputFactory);
    // generate sources
    List<TaskSource> sources = new ArrayList<>();
    long sequenceId = 0;
    for (TableScanNode tableScan : findTableScanNodes(subplan.getFragment().getRoot())) {
        TableLayoutHandle layout = tableScan.getLayout().get();
        SplitSource splitSource = splitManager.getSplits(session, layout);
        ImmutableSet.Builder<ScheduledSplit> scheduledSplits = ImmutableSet.builder();
        while (!splitSource.isFinished()) {
            for (Split split : getFutureValue(splitSource.getNextBatch(1000))) {
                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()).addDriverContext();
                Driver driver = driverFactory.createDriver(driverContext);
                drivers.add(driver);
            }
        }
    }
    // add sources to the drivers
    for (TaskSource source : sources) {
        DriverFactory driverFactory = driverFactoriesBySource.get(source.getPlanNodeId());
        checkState(driverFactory != null);
        for (ScheduledSplit split : source.getSplits()) {
            DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver()).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.close();
    }
    return ImmutableList.copyOf(drivers);
}
Also used : DriverContext(com.facebook.presto.operator.DriverContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Driver(com.facebook.presto.operator.Driver) TaskManagerConfig(com.facebook.presto.execution.TaskManagerConfig) PagesIndex(com.facebook.presto.operator.PagesIndex) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) JoinProbeCompiler(com.facebook.presto.sql.gen.JoinProbeCompiler) ImmutableSet(com.google.common.collect.ImmutableSet) DriverFactory(com.facebook.presto.operator.DriverFactory) LookupJoinOperators(com.facebook.presto.operator.LookupJoinOperators) JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) ScheduledSplit(com.facebook.presto.ScheduledSplit) LocalExecutionPlanner(com.facebook.presto.sql.planner.LocalExecutionPlanner) IndexJoinLookupStats(com.facebook.presto.operator.index.IndexJoinLookupStats) LocalExecutionPlan(com.facebook.presto.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) Plan(com.facebook.presto.sql.planner.Plan) SubPlan(com.facebook.presto.sql.planner.SubPlan) CompilerConfig(com.facebook.presto.sql.planner.CompilerConfig) TableLayoutHandle(com.facebook.presto.metadata.TableLayoutHandle) Constraint(com.facebook.presto.spi.Constraint) LocalExecutionPlan(com.facebook.presto.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode) SplitSource(com.facebook.presto.split.SplitSource) ScheduledSplit(com.facebook.presto.ScheduledSplit) Split(com.facebook.presto.metadata.Split) SubPlan(com.facebook.presto.sql.planner.SubPlan) TaskSource(com.facebook.presto.TaskSource)

Example 2 with LocalExecutionPlanner

use of com.facebook.presto.sql.planner.LocalExecutionPlanner in project presto by prestodb.

the class TaskTestUtils method createTestingPlanner.

public static LocalExecutionPlanner createTestingPlanner() {
    MetadataManager metadata = MetadataManager.createTestMetadataManager();
    PageSourceManager pageSourceManager = new PageSourceManager();
    pageSourceManager.addConnectorPageSourceProvider(CONNECTOR_ID, new TestingPageSourceProvider());
    // we don't start the finalizer so nothing will be collected, which is ok for a test
    FinalizerService finalizerService = new FinalizerService();
    NodeScheduler nodeScheduler = new NodeScheduler(new LegacyNetworkTopology(), new InMemoryNodeManager(), new NodeSchedulerConfig().setIncludeCoordinator(true), new NodeTaskMap(finalizerService));
    NodePartitioningManager nodePartitioningManager = new NodePartitioningManager(nodeScheduler);
    return new LocalExecutionPlanner(metadata, new SqlParser(), Optional.empty(), pageSourceManager, new IndexManager(), nodePartitioningManager, new PageSinkManager(), new MockExchangeClientSupplier(), new ExpressionCompiler(metadata), new JoinFilterFunctionCompiler(metadata), new IndexJoinLookupStats(), new CompilerConfig(), new TaskManagerConfig(), new BinarySpillerFactory(new BlockEncodingManager(metadata.getTypeManager()), new FeaturesConfig()), new TestingBlockEncodingSerde(new TestingTypeManager()), new PagesIndex.TestingFactory(), new JoinCompiler(), new LookupJoinOperators(new JoinProbeCompiler()));
}
Also used : FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) PagesIndex(com.facebook.presto.operator.PagesIndex) PageSourceManager(com.facebook.presto.split.PageSourceManager) NodePartitioningManager(com.facebook.presto.sql.planner.NodePartitioningManager) JoinProbeCompiler(com.facebook.presto.sql.gen.JoinProbeCompiler) NodeScheduler(com.facebook.presto.execution.scheduler.NodeScheduler) TestingTypeManager(com.facebook.presto.spi.type.TestingTypeManager) PageSinkManager(com.facebook.presto.split.PageSinkManager) LookupJoinOperators(com.facebook.presto.operator.LookupJoinOperators) JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) LocalExecutionPlanner(com.facebook.presto.sql.planner.LocalExecutionPlanner) MockExchangeClientSupplier(com.facebook.presto.execution.TestSqlTaskManager.MockExchangeClientSupplier) IndexJoinLookupStats(com.facebook.presto.operator.index.IndexJoinLookupStats) TestingBlockEncodingSerde(com.facebook.presto.spi.block.TestingBlockEncodingSerde) JoinFilterFunctionCompiler(com.facebook.presto.sql.gen.JoinFilterFunctionCompiler) SqlParser(com.facebook.presto.sql.parser.SqlParser) CompilerConfig(com.facebook.presto.sql.planner.CompilerConfig) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) IndexManager(com.facebook.presto.index.IndexManager) MetadataManager(com.facebook.presto.metadata.MetadataManager) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FinalizerService(com.facebook.presto.util.FinalizerService) LegacyNetworkTopology(com.facebook.presto.execution.scheduler.LegacyNetworkTopology) BinarySpillerFactory(com.facebook.presto.spiller.BinarySpillerFactory) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler)

Aggregations

LookupJoinOperators (com.facebook.presto.operator.LookupJoinOperators)2 PagesIndex (com.facebook.presto.operator.PagesIndex)2 IndexJoinLookupStats (com.facebook.presto.operator.index.IndexJoinLookupStats)2 JoinCompiler (com.facebook.presto.sql.gen.JoinCompiler)2 JoinProbeCompiler (com.facebook.presto.sql.gen.JoinProbeCompiler)2 CompilerConfig (com.facebook.presto.sql.planner.CompilerConfig)2 LocalExecutionPlanner (com.facebook.presto.sql.planner.LocalExecutionPlanner)2 ScheduledSplit (com.facebook.presto.ScheduledSplit)1 TaskSource (com.facebook.presto.TaskSource)1 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)1 TaskManagerConfig (com.facebook.presto.execution.TaskManagerConfig)1 MockExchangeClientSupplier (com.facebook.presto.execution.TestSqlTaskManager.MockExchangeClientSupplier)1 LegacyNetworkTopology (com.facebook.presto.execution.scheduler.LegacyNetworkTopology)1 NodeScheduler (com.facebook.presto.execution.scheduler.NodeScheduler)1 NodeSchedulerConfig (com.facebook.presto.execution.scheduler.NodeSchedulerConfig)1 IndexManager (com.facebook.presto.index.IndexManager)1 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)1 MetadataManager (com.facebook.presto.metadata.MetadataManager)1 Split (com.facebook.presto.metadata.Split)1 TableLayoutHandle (com.facebook.presto.metadata.TableLayoutHandle)1