Search in sources :

Example 1 with IS_DISTINCT_FROM

use of io.trino.sql.tree.ComparisonExpression.Operator.IS_DISTINCT_FROM in project trino by trinodb.

the class JoinMatcher method matchDynamicFilters.

private boolean matchDynamicFilters(JoinNode joinNode, SymbolAliases symbolAliases) {
    if (expectedDynamicFilter.isEmpty()) {
        return true;
    }
    Set<DynamicFilterId> dynamicFilterIds = joinNode.getDynamicFilters().keySet();
    List<DynamicFilters.Descriptor> descriptors = searchFrom(joinNode.getLeft()).where(FilterNode.class::isInstance).findAll().stream().flatMap(filterNode -> extractExpressions(filterNode).stream()).flatMap(expression -> extractDynamicFilters(expression).getDynamicConjuncts().stream()).filter(descriptor -> dynamicFilterIds.contains(descriptor.getId())).collect(toImmutableList());
    Map<DynamicFilterId, Symbol> idToBuildSymbolMap = joinNode.getDynamicFilters();
    Set<Expression> actual = new HashSet<>();
    for (DynamicFilters.Descriptor descriptor : descriptors) {
        Expression probe = descriptor.getInput();
        Symbol build = idToBuildSymbolMap.get(descriptor.getId());
        if (build == null) {
            return false;
        }
        Expression expression;
        if (descriptor.isNullAllowed()) {
            expression = new NotExpression(new ComparisonExpression(IS_DISTINCT_FROM, probe, build.toSymbolReference()));
        } else {
            expression = new ComparisonExpression(descriptor.getOperator(), probe, build.toSymbolReference());
        }
        actual.add(expression);
    }
    Set<Expression> expected = expectedDynamicFilter.get().stream().map(pattern -> pattern.getExpression(symbolAliases)).collect(toImmutableSet());
    return expected.equals(actual);
}
Also used : PlanNodeSearcher.searchFrom(io.trino.sql.planner.optimizations.PlanNodeSearcher.searchFrom) DynamicFilters.extractDynamicFilters(io.trino.sql.DynamicFilters.extractDynamicFilters) FilterNode(io.trino.sql.planner.plan.FilterNode) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) PlanNode(io.trino.sql.planner.plan.PlanNode) HashSet(java.util.HashSet) DynamicFilters(io.trino.sql.DynamicFilters) DistributionType(io.trino.sql.planner.plan.JoinNode.DistributionType) IS_DISTINCT_FROM(io.trino.sql.tree.ComparisonExpression.Operator.IS_DISTINCT_FROM) NotExpression(io.trino.sql.tree.NotExpression) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ExpressionExtractor.extractExpressions(io.trino.sql.planner.ExpressionExtractor.extractExpressions) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) DynamicFilterPattern(io.trino.sql.planner.assertions.PlanMatchPattern.DynamicFilterPattern) JoinNode(io.trino.sql.planner.plan.JoinNode) Symbol(io.trino.sql.planner.Symbol) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) StatsProvider(io.trino.cost.StatsProvider) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Expression(io.trino.sql.tree.Expression) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Symbol(io.trino.sql.planner.Symbol) FilterNode(io.trino.sql.planner.plan.FilterNode) NotExpression(io.trino.sql.tree.NotExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) DynamicFilters.extractDynamicFilters(io.trino.sql.DynamicFilters.extractDynamicFilters) DynamicFilters(io.trino.sql.DynamicFilters) NotExpression(io.trino.sql.tree.NotExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Expression(io.trino.sql.tree.Expression) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) HashSet(java.util.HashSet)

Aggregations

MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Session (io.trino.Session)1 StatsProvider (io.trino.cost.StatsProvider)1 Metadata (io.trino.metadata.Metadata)1 DynamicFilters (io.trino.sql.DynamicFilters)1 DynamicFilters.extractDynamicFilters (io.trino.sql.DynamicFilters.extractDynamicFilters)1 ExpressionExtractor.extractExpressions (io.trino.sql.planner.ExpressionExtractor.extractExpressions)1 Symbol (io.trino.sql.planner.Symbol)1 NO_MATCH (io.trino.sql.planner.assertions.MatchResult.NO_MATCH)1 DynamicFilterPattern (io.trino.sql.planner.assertions.PlanMatchPattern.DynamicFilterPattern)1 PlanNodeSearcher.searchFrom (io.trino.sql.planner.optimizations.PlanNodeSearcher.searchFrom)1 DynamicFilterId (io.trino.sql.planner.plan.DynamicFilterId)1 FilterNode (io.trino.sql.planner.plan.FilterNode)1 JoinNode (io.trino.sql.planner.plan.JoinNode)1 DistributionType (io.trino.sql.planner.plan.JoinNode.DistributionType)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1