Search in sources :

Example 21 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

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.getFunctionAndTypeManager(), plan.getStatsAndCosts(), session, 0, false));
    }
    SubPlan subplan = createSubPlans(session, plan, true);
    if (!subplan.getChildren().isEmpty()) {
        throw new AssertionError("Expected subplan to have no children");
    }
    LocalExecutionPlanner executionPlanner = new LocalExecutionPlanner(metadata, Optional.empty(), pageSourceManager, indexManager, partitioningProviderManager, nodePartitioningManager, pageSinkManager, distributedMetadataManager, expressionCompiler, pageFunctionCompiler, joinFilterFunctionCompiler, new IndexJoinLookupStats(), new TaskManagerConfig().setTaskConcurrency(4), new MemoryManagerConfig(), spillerFactory, singleStreamSpillerFactory, partitioningSpillerFactory, blockEncodingManager, new PagesIndex.TestingFactory(false), joinCompiler, new LookupJoinOperators(), new OrderingCompiler(), jsonCodec(TableCommitContext.class), new RowExpressionDeterminismEvaluator(metadata), new NoOpFragmentResultCacheManager(), new ObjectMapper(), standaloneSpillerFactory);
    // plan query
    StageExecutionDescriptor stageExecutionDescriptor = subplan.getFragment().getStageExecutionDescriptor();
    StreamingPlanSection streamingPlanSection = extractStreamingSections(subplan);
    checkState(streamingPlanSection.getChildren().isEmpty(), "expected no materialized exchanges");
    StreamingSubPlan streamingSubPlan = streamingPlanSection.getPlan();
    LocalExecutionPlan localExecutionPlan = executionPlanner.plan(taskContext, stageExecutionDescriptor, subplan.getFragment().getRoot(), subplan.getFragment().getPartitioningScheme(), subplan.getFragment().getTableScanSchedulingOrder(), outputFactory, Optional.empty(), new UnsupportedRemoteSourceFactory(), createTableWriteInfo(streamingSubPlan, metadata, session), false);
    // generate sources
    List<TaskSource> sources = new ArrayList<>();
    long sequenceId = 0;
    for (TableScanNode tableScan : findTableScanNodes(subplan.getFragment().getRoot())) {
        SplitSource splitSource = splitManager.getSplits(session, tableScan.getTable(), getSplitSchedulingStrategy(stageExecutionDescriptor, tableScan.getId()), WarningCollector.NOOP);
        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
    Set<PlanNodeId> tableScanPlanNodeIds = ImmutableSet.copyOf(subplan.getFragment().getTableScanSchedulingOrder());
    for (TaskSource source : sources) {
        DriverFactory driverFactory = driverFactoriesBySource.get(source.getPlanNodeId());
        checkState(driverFactory != null);
        boolean partitioned = tableScanPlanNodeIds.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(com.facebook.presto.operator.DriverContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TableCommitContext(com.facebook.presto.operator.TableCommitContext) Driver(com.facebook.presto.operator.Driver) TaskManagerConfig(com.facebook.presto.execution.TaskManagerConfig) PagesIndex(com.facebook.presto.operator.PagesIndex) NoOpFragmentResultCacheManager(com.facebook.presto.operator.NoOpFragmentResultCacheManager) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ImmutableSet(com.google.common.collect.ImmutableSet) OrderingCompiler(com.facebook.presto.sql.gen.OrderingCompiler) DriverFactory(com.facebook.presto.operator.DriverFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LookupJoinOperators(com.facebook.presto.operator.LookupJoinOperators) RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) LocalExecutionPlanner(com.facebook.presto.sql.planner.LocalExecutionPlanner) IndexJoinLookupStats(com.facebook.presto.operator.index.IndexJoinLookupStats) StageExecutionDescriptor(com.facebook.presto.operator.StageExecutionDescriptor) MemoryManagerConfig(com.facebook.presto.memory.MemoryManagerConfig) LocalExecutionPlan(com.facebook.presto.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) StreamingSubPlan(com.facebook.presto.execution.scheduler.StreamingSubPlan) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) StreamingPlanSection(com.facebook.presto.execution.scheduler.StreamingPlanSection) SplitSource(com.facebook.presto.split.SplitSource) Split(com.facebook.presto.metadata.Split) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) SubPlan(com.facebook.presto.sql.planner.SubPlan) StreamingSubPlan(com.facebook.presto.execution.scheduler.StreamingSubPlan) TaskSource(com.facebook.presto.execution.TaskSource)

Example 22 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

the class WarnOnScanWithoutPartitionPredicate method validate.

@Override
public void validate(PlanNode plan, Session session, Metadata metadata, SqlParser sqlParser, TypeProvider types, WarningCollector warningCollector) {
    for (TableScanNode scan : searchFrom(plan).where(TableScanNode.class::isInstance).<TableScanNode>findAll()) {
        TableHandle tableHandle = scan.getTable();
        TableLayoutFilterCoverage partitioningFilterCoverage = metadata.getTableLayoutFilterCoverage(session, tableHandle, warnOnNoTableLayoutFilter);
        if (partitioningFilterCoverage == NOT_COVERED) {
            String warningMessage = String.format("No partition filter for scan of table %s", scan.getTable().getConnectorHandle());
            warningCollector.add(new PrestoWarning(PERFORMANCE_WARNING, warningMessage));
        }
    }
}
Also used : TableLayoutFilterCoverage(com.facebook.presto.spi.TableLayoutFilterCoverage) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) PrestoWarning(com.facebook.presto.spi.PrestoWarning) TableHandle(com.facebook.presto.spi.TableHandle)

Example 23 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

the class TestJdbcComputePushdown method assertPlanMatch.

private static void assertPlanMatch(PlanNode actual, PlanMatchPattern expected, TypeProvider typeProvider) {
    // always check the actual plan node has a filter node to prevent accidentally missing predicates
    Queue<PlanNode> nodes = new LinkedList<>(ImmutableSet.of(actual));
    boolean hasFilterNode = false;
    while (!nodes.isEmpty()) {
        PlanNode node = nodes.poll();
        nodes.addAll(node.getSources());
        // the following assertPlan will guarantee the completeness of the filter
        if (node instanceof FilterNode && node.getSources().get(0) instanceof TableScanNode) {
            hasFilterNode = true;
            break;
        }
    }
    assertTrue(hasFilterNode, "filter is missing from the pushdown plan");
    PlanAssert.assertPlan(TEST_SESSION, METADATA, (node, sourceStats, lookup, session, types) -> PlanNodeStatsEstimate.unknown(), new Plan(actual, typeProvider, StatsAndCosts.empty()), expected);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) Plan(com.facebook.presto.sql.planner.Plan) LinkedList(java.util.LinkedList)

Example 24 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

the class ApplyConnectorOptimization method buildConnectorPlanNodeContext.

private static ConnectorPlanNodeContext buildConnectorPlanNodeContext(PlanNode node, PlanNode parent, ImmutableMap.Builder<PlanNode, ConnectorPlanNodeContext> contextBuilder) {
    Set<ConnectorId> connectorIds;
    Set<Class<? extends PlanNode>> planNodeTypes;
    if (node.getSources().isEmpty()) {
        if (node instanceof TableScanNode) {
            connectorIds = ImmutableSet.of(((TableScanNode) node).getTable().getConnectorId());
            planNodeTypes = ImmutableSet.of(TableScanNode.class);
        } else {
            connectorIds = ImmutableSet.of(EMPTY_CONNECTOR_ID);
            planNodeTypes = ImmutableSet.of(node.getClass());
        }
    } else {
        connectorIds = new HashSet<>();
        planNodeTypes = new HashSet<>();
        for (PlanNode child : node.getSources()) {
            ConnectorPlanNodeContext childContext = buildConnectorPlanNodeContext(child, node, contextBuilder);
            connectorIds.addAll(childContext.getReachableConnectors());
            planNodeTypes.addAll(childContext.getReachablePlanNodeTypes());
        }
        planNodeTypes.add(node.getClass());
    }
    ConnectorPlanNodeContext connectorPlanNodeContext = new ConnectorPlanNodeContext(parent, connectorIds, planNodeTypes);
    contextBuilder.put(node, connectorPlanNodeContext);
    return connectorPlanNodeContext;
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 25 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

the class TestCostCalculator method testUnion.

@Test
public void testUnion() {
    TableScanNode ts1 = tableScan("ts1", "orderkey");
    TableScanNode ts2 = tableScan("ts2", "orderkey_0");
    UnionNode union = new UnionNode(Optional.empty(), new PlanNodeId("union"), ImmutableList.of(ts1, ts2), ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "orderkey_1", BIGINT)), ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "orderkey_1", BIGINT), ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "orderkey", BIGINT), new VariableReferenceExpression(Optional.empty(), "orderkey_0", BIGINT))));
    Map<String, PlanNodeStatsEstimate> stats = ImmutableMap.of("ts1", statsEstimate(ts1, 4000), "ts2", statsEstimate(ts2, 1000), "union", statsEstimate(ts1, 5000));
    Map<String, PlanCostEstimate> costs = ImmutableMap.of("ts1", cpuCost(1000), "ts2", cpuCost(1000));
    Map<String, Type> types = ImmutableMap.of("orderkey", BIGINT, "orderkey_0", BIGINT, "orderkey_1", BIGINT);
    assertCost(union, costs, stats).cpu(2000).memory(0).network(0);
    assertCostEstimatedExchanges(union, costs, stats).cpu(2000).memory(0).network(5000 * IS_NULL_OVERHEAD);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) UnionNode(com.facebook.presto.spi.plan.UnionNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test)

Aggregations

TableScanNode (com.facebook.presto.spi.plan.TableScanNode)60 Test (org.testng.annotations.Test)37 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)35 PlanNode (com.facebook.presto.spi.plan.PlanNode)29 ColumnHandle (com.facebook.presto.spi.ColumnHandle)25 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)21 ImmutableList (com.google.common.collect.ImmutableList)18 TableHandle (com.facebook.presto.spi.TableHandle)16 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)16 RowExpression (com.facebook.presto.spi.relation.RowExpression)15 ImmutableMap (com.google.common.collect.ImmutableMap)15 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)14 Optional (java.util.Optional)13 Type (com.facebook.presto.common.type.Type)12 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)12 SemiJoinNode (com.facebook.presto.sql.planner.plan.SemiJoinNode)12 FilterNode (com.facebook.presto.spi.plan.FilterNode)11 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)10 Metadata (com.facebook.presto.metadata.Metadata)10 ImmutableSet (com.google.common.collect.ImmutableSet)10