Search in sources :

Example 46 with FilterNode

use of io.prestosql.spi.plan.FilterNode in project hetu-core by openlookeng.

the class TestEffectivePredicateExtractor method testLeftJoin.

@Test
public void testLeftJoin() {
    ImmutableList.Builder<JoinNode.EquiJoinClause> criteriaBuilder = ImmutableList.builder();
    criteriaBuilder.add(new JoinNode.EquiJoinClause(A, D));
    criteriaBuilder.add(new JoinNode.EquiJoinClause(B, E));
    List<JoinNode.EquiJoinClause> criteria = criteriaBuilder.build();
    Map<Symbol, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C)));
    TableScanNode leftScan = tableScanNode(leftAssignments);
    Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    FilterNode left = filter(leftScan, and(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), equals(GE, bigintLiteral(10))));
    FilterNode right = filter(rightScan, and(equals(DE, EE), lessThan(FE, bigintLiteral(100))));
    PlanNode node = new JoinNode(newId(), JoinNode.Type.LEFT, left, right, criteria, ImmutableList.<Symbol>builder().addAll(left.getOutputSymbols()).addAll(right.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // All right side symbols having output symbols should be checked against NULL
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), or(equals(DE, EE), and(isNull(DE), isNull(EE))), or(lessThan(FE, bigintLiteral(100)), isNull(FE)), or(equals(AE, DE), isNull(DE)), or(equals(BE, EE), isNull(EE))));
}
Also used : TestingColumnHandle(io.prestosql.testing.TestingMetadata.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 47 with FilterNode

use of io.prestosql.spi.plan.FilterNode in project hetu-core by openlookeng.

the class TestEffectivePredicateExtractor method testRightJoin.

@Test
public void testRightJoin() {
    ImmutableList.Builder<JoinNode.EquiJoinClause> criteriaBuilder = ImmutableList.builder();
    criteriaBuilder.add(new JoinNode.EquiJoinClause(A, D));
    criteriaBuilder.add(new JoinNode.EquiJoinClause(B, E));
    List<JoinNode.EquiJoinClause> criteria = criteriaBuilder.build();
    Map<Symbol, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C)));
    TableScanNode leftScan = tableScanNode(leftAssignments);
    Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    FilterNode left = filter(leftScan, and(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), equals(GE, bigintLiteral(10))));
    FilterNode right = filter(rightScan, and(equals(DE, EE), lessThan(FE, bigintLiteral(100))));
    PlanNode node = new JoinNode(newId(), JoinNode.Type.RIGHT, left, right, criteria, ImmutableList.<Symbol>builder().addAll(left.getOutputSymbols()).addAll(right.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // All left side symbols should be checked against NULL
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(or(lessThan(BE, AE), and(isNull(BE), isNull(AE))), or(lessThan(CE, bigintLiteral(10)), isNull(CE)), equals(DE, EE), lessThan(FE, bigintLiteral(100)), or(equals(AE, DE), isNull(AE)), or(equals(BE, EE), isNull(BE))));
}
Also used : TestingColumnHandle(io.prestosql.testing.TestingMetadata.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 48 with FilterNode

use of io.prestosql.spi.plan.FilterNode in project hetu-core by openlookeng.

the class TestEffectivePredicateExtractor method testInnerJoinPropagatesPredicatesViaEquiConditions.

@Test
public void testInnerJoinPropagatesPredicatesViaEquiConditions() {
    Map<Symbol, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C)));
    TableScanNode leftScan = tableScanNode(leftAssignments);
    Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    FilterNode left = filter(leftScan, equals(AE, bigintLiteral(10)));
    // predicates on "a" column should be propagated to output symbols via join equi conditions
    PlanNode node = new JoinNode(newId(), JoinNode.Type.INNER, left, rightScan, ImmutableList.of(new JoinNode.EquiJoinClause(A, D)), ImmutableList.<Symbol>builder().addAll(rightScan.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(DE, bigintLiteral(10))));
}
Also used : TestingColumnHandle(io.prestosql.testing.TestingMetadata.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) Symbol(io.prestosql.spi.plan.Symbol) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) FilterNode(io.prestosql.spi.plan.FilterNode) Test(org.testng.annotations.Test)

Example 49 with FilterNode

use of io.prestosql.spi.plan.FilterNode in project hetu-core by openlookeng.

the class SimpleFilterProjectSemiJoinStatsRule method calculate.

private Optional<PlanNodeStatsEstimate> calculate(FilterNode filterNode, SemiJoinNode semiJoinNode, StatsProvider statsProvider, Session session, TypeProvider types) {
    PlanNodeStatsEstimate sourceStats = statsProvider.getStats(semiJoinNode.getSource());
    PlanNodeStatsEstimate filteringSourceStats = statsProvider.getStats(semiJoinNode.getFilteringSource());
    Symbol filteringSourceJoinSymbol = semiJoinNode.getFilteringSourceJoinSymbol();
    Symbol sourceJoinSymbol = semiJoinNode.getSourceJoinSymbol();
    Optional<SemiJoinOutputFilter> semiJoinOutputFilter;
    if (isExpression(filterNode.getPredicate())) {
        semiJoinOutputFilter = extractSemiJoinOutputFilter(castToExpression(filterNode.getPredicate()), semiJoinNode.getSemiJoinOutput());
    } else {
        VariableReferenceExpression semiJoinOutput = new VariableReferenceExpression(semiJoinNode.getSemiJoinOutput().getName(), types.get(semiJoinNode.getSemiJoinOutput()));
        semiJoinOutputFilter = extractSemiJoinOutputFilter(filterNode.getPredicate(), semiJoinOutput);
    }
    if (!semiJoinOutputFilter.isPresent()) {
        return Optional.empty();
    }
    PlanNodeStatsEstimate semiJoinStats;
    if (semiJoinOutputFilter.get().isNegated()) {
        semiJoinStats = computeAntiJoin(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol);
    } else {
        semiJoinStats = computeSemiJoin(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol);
    }
    if (semiJoinStats.isOutputRowCountUnknown()) {
        return Optional.of(PlanNodeStatsEstimate.unknown());
    }
    // apply remaining predicate
    PlanNodeStatsEstimate filteredStats;
    if (isExpression(filterNode.getPredicate())) {
        filteredStats = filterStatsCalculator.filterStats(semiJoinStats, castToExpression(semiJoinOutputFilter.get().getRemainingPredicate()), session, types);
    } else {
        Map<Integer, Symbol> layout = SymbolUtils.toLayOut(filterNode.getOutputSymbols());
        filteredStats = filterStatsCalculator.filterStats(semiJoinStats, semiJoinOutputFilter.get().getRemainingPredicate(), session, types, layout);
    }
    if (filteredStats.isOutputRowCountUnknown()) {
        return Optional.of(semiJoinStats.mapOutputRowCount(rowCount -> rowCount * UNKNOWN_FILTER_COEFFICIENT));
    }
    return Optional.of(filteredStats);
}
Also used : Iterables(com.google.common.collect.Iterables) Lookup(io.prestosql.sql.planner.iterative.Lookup) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) TypeProvider(io.prestosql.sql.planner.TypeProvider) Pattern(io.prestosql.matching.Pattern) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) CallExpression(io.prestosql.spi.relation.CallExpression) FilterNode(io.prestosql.spi.plan.FilterNode) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) ProjectNodeUtils.isIdentity(io.prestosql.sql.relational.ProjectNodeUtils.isIdentity) Symbol(io.prestosql.spi.plan.Symbol) SymbolUtils(io.prestosql.sql.planner.SymbolUtils) NotExpression(io.prestosql.sql.tree.NotExpression) UNKNOWN_FILTER_COEFFICIENT(io.prestosql.cost.FilterStatsCalculator.UNKNOWN_FILTER_COEFFICIENT) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) SemiJoinStatsCalculator.computeSemiJoin(io.prestosql.cost.SemiJoinStatsCalculator.computeSemiJoin) SemiJoinStatsCalculator.computeAntiJoin(io.prestosql.cost.SemiJoinStatsCalculator.computeAntiJoin) ExpressionUtils.combineConjuncts(io.prestosql.sql.ExpressionUtils.combineConjuncts) Patterns.filter(io.prestosql.sql.planner.plan.Patterns.filter) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PlanNode(io.prestosql.spi.plan.PlanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) List(java.util.List) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) SymbolReference(io.prestosql.sql.tree.SymbolReference) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) ExpressionUtils.extractConjuncts(io.prestosql.sql.ExpressionUtils.extractConjuncts) Symbol(io.prestosql.spi.plan.Symbol) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression)

Aggregations

FilterNode (io.prestosql.spi.plan.FilterNode)49 PlanNode (io.prestosql.spi.plan.PlanNode)33 Symbol (io.prestosql.spi.plan.Symbol)32 TableScanNode (io.prestosql.spi.plan.TableScanNode)27 RowExpression (io.prestosql.spi.relation.RowExpression)25 Expression (io.prestosql.sql.tree.Expression)24 ProjectNode (io.prestosql.spi.plan.ProjectNode)23 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)19 Map (java.util.Map)18 Optional (java.util.Optional)18 ImmutableList (com.google.common.collect.ImmutableList)17 Session (io.prestosql.Session)17 List (java.util.List)17 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)16 JoinNode (io.prestosql.spi.plan.JoinNode)14 Metadata (io.prestosql.metadata.Metadata)13 Test (org.testng.annotations.Test)13 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)12 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)12 CallExpression (io.prestosql.spi.relation.CallExpression)11