@Test public void testGroupByEmpty() { PlanNode node = new AggregationNode( newId(), filter(baseTableScan, FALSE_LITERAL), ImmutableMap.of(), globalAggregation(), ImmutableList.of(), AggregationNode.Step.FINAL, Optional.empty(), Optional.empty()); Expression effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(effectivePredicate, TRUE_LITERAL); }
@Test public void testInnerJoinWithFalseFilter() { 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); PlanNode node = new JoinNode(newId(), JoinNode.Type.INNER, leftScan, rightScan, ImmutableList.of(new JoinNode.EquiJoinClause(A, D)), ImmutableList.<Symbol>builder() .addAll(leftScan.getOutputSymbols()) .addAll(rightScan.getOutputSymbols()) .build(), Optional.of(FALSE_LITERAL), Optional.empty(), Optional.empty(), Optional.empty()); Expression effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(effectivePredicate, FALSE_LITERAL); }
@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()); Expression effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals( normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(DE, bigintLiteral(10)))); }
ImmutableList.copyOf(assignments.keySet()), assignments); Expression effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(effectivePredicate, BooleanLiteral.TRUE_LITERAL); TupleDomain.none(), TupleDomain.all()); effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(effectivePredicate, FALSE_LITERAL); TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(A), Domain.singleValue(BIGINT, 1L))), TupleDomain.all()); effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(1L), AE))); scanAssignments.get(B), Domain.singleValue(BIGINT, 2L))), TupleDomain.all()); effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(2L), BE), equals(bigintLiteral(1L), AE))); TupleDomain.all(), TupleDomain.all()); effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(effectivePredicate, BooleanLiteral.TRUE_LITERAL);
@Test public void testFilter() { PlanNode node = filter(baseTableScan, and( greaterThan(AE, new FunctionCall(QualifiedName.of("rand"), ImmutableList.of())), lessThan(BE, bigintLiteral(10)))); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Non-deterministic functions should be purged assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BE, bigintLiteral(10)))); }
Optional.empty()); Expression effectivePredicate = effectivePredicateExtractor.extract(node);
Expression sourceEffectivePredicate = filterDeterministicConjuncts(effectivePredicateExtractor.extract(node.getSource())); Expression filteringSourceEffectivePredicate = filterDeterministicConjuncts(effectivePredicateExtractor.extract(node.getFilteringSource())); Expression joinExpression = new ComparisonExpression( ComparisonExpression.Operator.EQUAL,
Optional.empty()); Expression effectivePredicate = effectivePredicateExtractor.extract(node);
@Test public void testWindow() { PlanNode node = new WindowNode(newId(), filter(baseTableScan, and( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), new WindowNode.Specification( ImmutableList.of(A), Optional.of(new OrderingScheme( ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST)))), ImmutableMap.of(), Optional.empty(), ImmutableSet.of(), 0); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Pass through assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))); }
@Test public void testSemiJoin() { PlanNode node = new SemiJoinNode(newId(), filter(baseTableScan, and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100)))), filter(baseTableScan, greaterThan(AE, bigintLiteral(5))), A, B, C, Optional.empty(), Optional.empty(), Optional.empty()); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Currently, only pull predicates through the source plan assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100))))); }
Optional.empty()); Expression effectivePredicate = effectivePredicateExtractor.extract(node);
Optional.empty()); Expression effectivePredicate = effectivePredicateExtractor.extract(node);
@Test public void testTopN() { PlanNode node = new TopNNode(newId(), filter(baseTableScan, and( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), 1, new OrderingScheme(ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST)), TopNNode.Step.PARTIAL); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Pass through assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))); }
@Test public void testSort() { PlanNode node = new SortNode(newId(), filter(baseTableScan, and( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), new OrderingScheme(ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST))); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Pass through assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))); }
Optional.empty()); Expression effectivePredicate = effectivePredicateExtractor.extract(node);
@Test public void testProject() { PlanNode node = new ProjectNode(newId(), filter(baseTableScan, and( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), Assignments.of(D, AE, E, CE)); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Rewrite in terms of project output symbols assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts( lessThan(DE, bigintLiteral(10)), equals(DE, EE))); }
@Test public void testAggregation() { PlanNode node = new AggregationNode(newId(), filter(baseTableScan, and( equals(AE, DE), equals(BE, EE), equals(CE, FE), lessThan(DE, bigintLiteral(10)), lessThan(CE, DE), greaterThan(AE, bigintLiteral(2)), equals(EE, FE))), ImmutableMap.of( C, new Aggregation(fakeFunction(), fakeFunctionHandle("test", AGGREGATE), Optional.empty()), D, new Aggregation(fakeFunction(), fakeFunctionHandle("test", AGGREGATE), Optional.empty())), singleGroupingSet(ImmutableList.of(A, B, C)), ImmutableList.of(), AggregationNode.Step.FINAL, Optional.empty(), Optional.empty()); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Rewrite in terms of group by symbols assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts( lessThan(AE, bigintLiteral(10)), lessThan(BE, AE), greaterThan(AE, bigintLiteral(2)), equals(BE, CE))); }
@Test public void testUnion() { ImmutableListMultimap<Symbol, Symbol> symbolMapping = ImmutableListMultimap.of(A, B, A, C, A, E); PlanNode node = new UnionNode(newId(), ImmutableList.of( filter(baseTableScan, greaterThan(AE, bigintLiteral(10))), filter(baseTableScan, and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100)))), filter(baseTableScan, and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100))))), symbolMapping, ImmutableList.copyOf(symbolMapping.keySet())); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Only the common conjuncts can be inferred through a Union assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(greaterThan(AE, bigintLiteral(10)))); }
@Test public void testLimit() { PlanNode node = new LimitNode(newId(), filter(baseTableScan, and( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), 1, false); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Pass through assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))); }