Search in sources :

Example 1 with AbstractJoinNode

use of com.facebook.presto.sql.planner.plan.AbstractJoinNode 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)

Aggregations

Domain (com.facebook.presto.common.predicate.Domain)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 DynamicFilterExtractResult (com.facebook.presto.expressions.DynamicFilters.DynamicFilterExtractResult)1 DynamicFilterPlaceholder (com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder)1 DynamicFilters.extractDynamicFilters (com.facebook.presto.expressions.DynamicFilters.extractDynamicFilters)1 FilterNode (com.facebook.presto.spi.plan.FilterNode)1 PlanNode (com.facebook.presto.spi.plan.PlanNode)1 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)1 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)1 PlanNodeSearcher (com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher)1 AbstractJoinNode (com.facebook.presto.sql.planner.plan.AbstractJoinNode)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Multimap (com.google.common.collect.Multimap)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1