Search in sources :

Example 26 with FilterNode

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

the class LocalDynamicFilter method create.

public static Optional<LocalDynamicFilter> create(AbstractJoinNode planNode, int partitionCount) {
    Set<String> joinDynamicFilters = planNode.getDynamicFilters().keySet();
    List<FilterNode> filterNodes = PlanNodeSearcher.searchFrom(planNode.getProbe()).where(LocalDynamicFilter::isFilterAboveTableScan).findAll();
    // Mapping from probe-side dynamic filters' IDs to their matching probe variables.
    ImmutableMultimap.Builder<String, DynamicFilterPlaceholder> probeVariablesBuilder = ImmutableMultimap.builder();
    for (FilterNode filterNode : filterNodes) {
        DynamicFilterExtractResult extractResult = extractDynamicFilters(filterNode.getPredicate());
        for (DynamicFilterPlaceholder placeholder : extractResult.getDynamicConjuncts()) {
            if (placeholder.getInput() instanceof VariableReferenceExpression) {
                // Add descriptors that match the local dynamic filter (from the current join node).
                if (joinDynamicFilters.contains(placeholder.getId())) {
                    probeVariablesBuilder.put(placeholder.getId(), placeholder);
                }
            }
        }
    }
    Multimap<String, DynamicFilterPlaceholder> probeVariables = probeVariablesBuilder.build();
    PlanNode buildNode = planNode.getBuild();
    Map<String, Integer> buildChannels = planNode.getDynamicFilters().entrySet().stream().filter(entry -> probeVariables.containsKey(entry.getKey())).collect(toMap(// Dynamic filter ID
    Map.Entry::getKey, // Build-side channel index
    entry -> {
        VariableReferenceExpression buildVariable = entry.getValue();
        int buildChannelIndex = buildNode.getOutputVariables().indexOf(buildVariable);
        verify(buildChannelIndex >= 0);
        return buildChannelIndex;
    }));
    if (buildChannels.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(new LocalDynamicFilter(probeVariables, buildChannels, partitionCount));
}
Also used : AbstractJoinNode(com.facebook.presto.sql.planner.plan.AbstractJoinNode) DynamicFilterExtractResult(com.facebook.presto.expressions.DynamicFilters.DynamicFilterExtractResult) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Multimap(com.google.common.collect.Multimap) SettableFuture(com.google.common.util.concurrent.SettableFuture) ArrayList(java.util.ArrayList) FilterNode(com.facebook.presto.spi.plan.FilterNode) Collectors.toMap(java.util.stream.Collectors.toMap) Verify.verify(com.google.common.base.Verify.verify) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) DynamicFilterPlaceholder(com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) PlanNodeSearcher(com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Consumer(java.util.function.Consumer) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) Optional(java.util.Optional) DynamicFilters.extractDynamicFilters(com.facebook.presto.expressions.DynamicFilters.extractDynamicFilters) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) FilterNode(com.facebook.presto.spi.plan.FilterNode) DynamicFilterPlaceholder(com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) DynamicFilterExtractResult(com.facebook.presto.expressions.DynamicFilters.DynamicFilterExtractResult) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 27 with FilterNode

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

the class TestPinotPlanOptimizer method testPartialPredicatePushdown.

@Test
public void testPartialPredicatePushdown() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, regionId, city, fare, secondsSinceEpoch);
    FilterNode filter = filter(planBuilder, tableScanNode, getRowExpression("lower(substr(city, 0, 3)) = 'del' AND fare > 100", defaultSessionHolder));
    PlanNode originalPlan = limit(planBuilder, 50L, filter);
    PlanNode optimized = getOptimizedPlan(planBuilder, originalPlan);
    PlanMatchPattern tableScanMatcher = PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT regionId, city, fare, secondsSinceEpoch FROM hybrid__TABLE_NAME_SUFFIX_TEMPLATE__ WHERE \\(fare > 100\\).*"), Optional.of(true), filter.getOutputVariables(), useSqlSyntax());
    assertPlanMatch(optimized, PlanMatchPattern.limit(50L, PlanMatchPattern.filter("lower(substr(city, 0, 3)) = 'del'", tableScanMatcher)), typeProvider);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 28 with FilterNode

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

the class TestPinotPlanOptimizer method testDatePredicatePushdown.

@Test
public void testDatePredicatePushdown() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    FilterNode filter = filter(planBuilder, tableScan(planBuilder, pinotTable, regionId, city, fare, daysSinceEpoch), getRowExpression("dayssinceepoch < DATE '2014-01-31'", defaultSessionHolder));
    PlanNode originalPlan = limit(planBuilder, 50L, filter);
    PlanNode optimized = getOptimizedPlan(planBuilder, originalPlan);
    assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT regionId, city, fare, daysSinceEpoch FROM hybrid WHERE \\(daysSinceEpoch < 16101\\) LIMIT 50"), Optional.of(false), originalPlan.getOutputVariables(), useSqlSyntax()), typeProvider);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 29 with FilterNode

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

the class TestPinotPlanOptimizer method testTimestampPredicatePushdown.

@Test
public void testTimestampPredicatePushdown() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    FilterNode filter = filter(planBuilder, tableScan(planBuilder, pinotTable, regionId, city, fare, millisSinceEpoch), getRowExpression("millissinceepoch < TIMESTAMP '2014-01-31 00:00:00 UTC'", defaultSessionHolder));
    PlanNode originalPlan = limit(planBuilder, 50L, filter);
    PlanNode optimized = getOptimizedPlan(planBuilder, originalPlan);
    assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT regionId, city, fare, millisSinceEpoch FROM hybrid WHERE \\(millisSinceEpoch < 1391126400000\\) LIMIT 50"), Optional.of(false), originalPlan.getOutputVariables(), useSqlSyntax()), typeProvider);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 30 with FilterNode

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

the class TestPinotPlanOptimizer method testTimestampFieldCompareToDateLiteralPredicatePushdown.

@Test
public void testTimestampFieldCompareToDateLiteralPredicatePushdown() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    FilterNode filter = filter(planBuilder, tableScan(planBuilder, pinotTable, regionId, city, fare, millisSinceEpoch), getRowExpression("millissinceepoch <  DATE '2014-01-31'", defaultSessionHolder));
    PlanNode originalPlan = limit(planBuilder, 50L, filter);
    PlanNode optimized = getOptimizedPlan(planBuilder, originalPlan);
    assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT regionId, city, fare, millisSinceEpoch FROM hybrid WHERE \\(millisSinceEpoch < 1391126400000\\) LIMIT 50"), Optional.of(false), originalPlan.getOutputVariables(), useSqlSyntax()), typeProvider);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Aggregations

FilterNode (com.facebook.presto.spi.plan.FilterNode)31 PlanNode (com.facebook.presto.spi.plan.PlanNode)22 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)19 Test (org.testng.annotations.Test)16 RowExpression (com.facebook.presto.spi.relation.RowExpression)15 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)11 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)10 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)10 ImmutableList (com.google.common.collect.ImmutableList)8 ColumnHandle (com.facebook.presto.spi.ColumnHandle)7 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)7 SemiJoinNode (com.facebook.presto.sql.planner.plan.SemiJoinNode)7 Expression (com.facebook.presto.sql.tree.Expression)7 Session (com.facebook.presto.Session)6 OriginalExpressionUtils.castToRowExpression (com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Map (java.util.Map)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Optional (java.util.Optional)5 LogicalRowExpressions (com.facebook.presto.expressions.LogicalRowExpressions)4