### Question:
PruneApplyCorrelation implements Rule<ApplyNode> { @Override public Result apply(ApplyNode applyNode, Captures captures, Context context) { Set<Symbol> subquerySymbols = extractUnique(applyNode.getSubquery(), context.getLookup()); List<Symbol> newCorrelation = applyNode.getCorrelation().stream() .filter(subquerySymbols::contains) .collect(toImmutableList()); if (newCorrelation.size() < applyNode.getCorrelation().size()) { return Result.ofPlanNode(new ApplyNode( applyNode.getId(), applyNode.getInput(), applyNode.getSubquery(), applyNode.getSubqueryAssignments(), newCorrelation, applyNode.getOriginSubquery())); } return Result.empty(); }  @Override Pattern<ApplyNode> getPattern(); @Override Result apply(ApplyNode applyNode, Captures captures, Context context);  }### Answer:
@Test public void testPruneCorrelationSymbolNotReferencedInSubquery() { tester().assertThat(new PruneApplyCorrelation()) .on(p -> { Symbol a = p.symbol("a"); Symbol inputSymbol = p.symbol("input_symbol"); Symbol subquerySymbol = p.symbol("subquery_symbol"); Symbol inResult = p.symbol("in_result"); return p.apply( Assignments.of(inResult, new InPredicate(a.toSymbolReference(), subquerySymbol.toSymbolReference())), ImmutableList.of(inputSymbol), p.values(a, inputSymbol), p.values(subquerySymbol)); }) .matches( apply( ImmutableList.of(), ImmutableMap.of("in_result", ExpressionMatcher.inPredicate(new SymbolReference("a"), new SymbolReference("subquery_symbol"))), values("a", "input_symbol"), values("subquery_symbol"))); }
@Test public void testAllCorrelationSymbolsReferencedInSubquery() { tester().assertThat(new PruneApplyCorrelation()) .on(p -> { Symbol a = p.symbol("a"); Symbol inputSymbol = p.symbol("input_symbol"); Symbol subquerySymbol = p.symbol("subquery_symbol"); Symbol inResult = p.symbol("in_result"); return p.apply( Assignments.of(inResult, new InPredicate(a.toSymbolReference(), subquerySymbol.toSymbolReference())), ImmutableList.of(inputSymbol), p.values(a, inputSymbol), p.filter( new ComparisonExpression(GREATER_THAN, subquerySymbol.toSymbolReference(), inputSymbol.toSymbolReference()), p.values(subquerySymbol))); }) .doesNotFire(); }