Search in sources :

Example 6 with Driver

use of io.prestosql.operator.Driver in project hetu-core by openlookeng.

the class TestMemoryPools method assertDriversProgress.

private void assertDriversProgress(Predicate<OperatorContext> reason) {
    do {
        assertFalse(isOperatorBlocked(drivers, reason));
        boolean progress = false;
        for (Driver driver : drivers) {
            ListenableFuture<?> blocked = driver.process();
            progress = progress | blocked.isDone();
        }
        // query should not block
        assertTrue(progress);
    } while (!drivers.stream().allMatch(Driver::isFinished));
}
Also used : Driver(io.prestosql.operator.Driver)

Example 7 with Driver

use of io.prestosql.operator.Driver in project hetu-core by openlookeng.

the class TestSpatialJoinOperator method buildIndex.

private PagesSpatialIndexFactory buildIndex(DriverContext driverContext, SpatialPredicate spatialRelationshipTest, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel, Optional<String> kdbTreeJson, Optional<InternalJoinFilterFunction> filterFunction, RowPagesBuilder buildPages) {
    Optional<JoinFilterFunctionCompiler.JoinFilterFunctionFactory> filterFunctionFactory = filterFunction.map(function -> (session, addresses, pages) -> new StandardJoinFilterFunction(function, addresses, pages));
    ValuesOperator.ValuesOperatorFactory valuesOperatorFactory = new ValuesOperator.ValuesOperatorFactory(0, new PlanNodeId("test"), buildPages.build());
    SpatialIndexBuilderOperatorFactory buildOperatorFactory = new SpatialIndexBuilderOperatorFactory(1, new PlanNodeId("test"), buildPages.getTypes(), Ints.asList(1), 0, radiusChannel, partitionChannel, spatialRelationshipTest, kdbTreeJson, filterFunctionFactory, 10_000, new TestingFactory(false));
    Driver driver = Driver.createDriver(driverContext, valuesOperatorFactory.createOperator(driverContext), buildOperatorFactory.createOperator(driverContext));
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildOperatorFactory.getPagesSpatialIndexFactory();
    ListenableFuture<PagesSpatialIndex> pagesSpatialIndex = pagesSpatialIndexFactory.createPagesSpatialIndex();
    while (!pagesSpatialIndex.isDone()) {
        driver.process();
    }
    runDriverInThread(executor, driver);
    return pagesSpatialIndexFactory;
}
Also used : SpatialIndexBuilderOperatorFactory(io.prestosql.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) StandardJoinFilterFunction(io.prestosql.operator.StandardJoinFilterFunction) PagesSpatialIndex(io.prestosql.operator.PagesSpatialIndex) Driver(io.prestosql.operator.Driver) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) TestingFactory(io.prestosql.operator.PagesIndex.TestingFactory) ValuesOperator(io.prestosql.operator.ValuesOperator) PagesSpatialIndexFactory(io.prestosql.operator.PagesSpatialIndexFactory)

Example 8 with Driver

use of io.prestosql.operator.Driver in project hetu-core by openlookeng.

the class IndexLoader method streamIndexDataForSingleKey.

public IndexedData streamIndexDataForSingleKey(UpdateRequest updateRequest) {
    Page indexKeyTuple = updateRequest.getPage().getRegion(0, 1);
    PageBuffer pageBuffer = new PageBuffer(100);
    DriverFactory driverFactory = indexBuildDriverFactoryProvider.createStreaming(pageBuffer, indexKeyTuple);
    Driver driver = driverFactory.createDriver(pipelineContext.addDriverContext());
    PageRecordSet pageRecordSet = new PageRecordSet(keyTypes, indexKeyTuple);
    PlanNodeId planNodeId = driverFactory.getSourceId().get();
    ScheduledSplit split = new ScheduledSplit(0, planNodeId, new Split(INDEX_CONNECTOR_ID, new IndexSplit(pageRecordSet), Lifespan.taskWide()));
    driver.updateSource(new TaskSource(planNodeId, ImmutableSet.of(split), true));
    return new StreamingIndexedData(outputTypes, keyTypes, indexKeyTuple, pageBuffer, driver);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) ScheduledSplit(io.prestosql.execution.ScheduledSplit) DriverFactory(io.prestosql.operator.DriverFactory) Driver(io.prestosql.operator.Driver) Page(io.prestosql.spi.Page) Split(io.prestosql.metadata.Split) ScheduledSplit(io.prestosql.execution.ScheduledSplit) TaskSource(io.prestosql.execution.TaskSource)

Example 9 with Driver

use of io.prestosql.operator.Driver in project boostkit-bigdata by kunpengcompute.

the class OmniLocalQueryRunner 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 10 with Driver

use of io.prestosql.operator.Driver in project hetu-core by openlookeng.

the class SqlTaskExecution method addSources.

public void addSources(List<TaskSource> sources) {
    requireNonNull(sources, "sources is null");
    checkState(!Thread.holdsLock(this), "Can not add sources while holding a lock on the %s", getClass().getSimpleName());
    try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
        // update our record of sources and schedule drivers for new partitioned splits
        Map<PlanNodeId, TaskSource> updatedUnpartitionedSources = updateSources(sources);
        // the unpartitioned splits
        for (WeakReference<Driver> driverReference : drivers) {
            Driver driver = driverReference.get();
            // the driver can be GCed due to a failure or a limit
            if (driver == null) {
                // remove the weak reference from the list to avoid a memory leak
                // NOTE: this is a concurrent safe operation on a CopyOnWriteArrayList
                drivers.remove(driverReference);
                continue;
            }
            Optional<PlanNodeId> sourceId = driver.getSourceId();
            if (!sourceId.isPresent()) {
                continue;
            }
            TaskSource sourceUpdate = updatedUnpartitionedSources.get(sourceId.get());
            if (sourceUpdate == null) {
                continue;
            }
            driver.updateSource(sourceUpdate);
        }
        // we may have transitioned to no more splits, so check for completion
        checkTaskCompletion();
    }
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) SetThreadName(io.airlift.concurrent.SetThreadName) Driver(io.prestosql.operator.Driver)

Aggregations

Driver (io.prestosql.operator.Driver)16 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)12 DriverFactory (io.prestosql.operator.DriverFactory)9 DriverContext (io.prestosql.operator.DriverContext)7 PagesIndex (io.prestosql.operator.PagesIndex)7 ImmutableList (com.google.common.collect.ImmutableList)6 ScheduledSplit (io.prestosql.execution.ScheduledSplit)6 TaskSource (io.prestosql.execution.TaskSource)6 Split (io.prestosql.metadata.Split)6 Type (io.prestosql.spi.type.Type)6 TableHandle (io.prestosql.spi.metadata.TableHandle)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 NodeInfo (io.airlift.node.NodeInfo)4 Session (io.prestosql.Session)4 DynamicFilterCacheManager (io.prestosql.dynamicfilter.DynamicFilterCacheManager)4 FileSystemClientManager (io.prestosql.filesystem.FileSystemClientManager)4 LookupJoinOperators (io.prestosql.operator.LookupJoinOperators)4 StageExecutionDescriptor (io.prestosql.operator.StageExecutionDescriptor)4 TaskContext (io.prestosql.operator.TaskContext)4