Source:
<code>public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator, Session session) { if (!(node instanceof AggregationNode)) { return Optional.empty(); } AggregationNode aggregation = (AggregationNode) node; boolean hasFilters = aggregation.getAggregations() <START> .entrySet().stream() <END> .anyMatch(e -> e.getValue().getCall().getFilter().isPresent() && !e.getValue().getMask().isPresent()); if (!hasFilters) { return Optional.empty(); } Assignments.Builder newAssignments = Assignments.builder(); ImmutableMap.Builder<Symbol, Aggregation> aggregations = ImmutableMap.builder(); for (Map.Entry<Symbol, Aggregation> entry : aggregation.getAggregations().entrySet()) { Symbol output = entry.getKey(); FunctionCall call = entry.getValue().getCall(); Optional<Symbol> mask = entry.getValue().getMask(); if (call.getFilter().isPresent()) { Expression filter = call.getFilter().get(); Symbol symbol = symbolAllocator.newSymbol(filter, BOOLEAN); newAssignments.put(symbol, filter); mask = Optional.of(symbol); } aggregations.put(output, new Aggregation( new FunctionCall(call.getName(), call.getWindow(), Optional.empty(), call.isDistinct(), call.getArguments()), entry.getValue().getSignature(), mask)); } newAssignments.putIdentities(aggregation.getSource().getOutputSymbols()); return Optional.of( new AggregationNode( idAllocator.getNextId(), new ProjectNode( idAllocator.getNextId(), aggregation.getSource(), newAssignments.build()), aggregations.build(), aggregation.getGroupingSets(), aggregation.getStep(), aggregation.getHashSymbol(), aggregation.getGroupIdSymbol())); }</code><technical_language>Change values</technical_language>

Target:
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator, Session session) { if (!(node instanceof AggregationNode)) { return Optional.empty(); } AggregationNode aggregation = (AggregationNode) node; boolean hasFilters = aggregation.getAggregations() .values().stream() .anyMatch(e -> e.getCall().getFilter().isPresent() && !e.getMask().isPresent()); if (!hasFilters) { return Optional.empty(); } Assignments.Builder newAssignments = Assignments.builder(); ImmutableMap.Builder<Symbol, Aggregation> aggregations = ImmutableMap.builder(); for (Map.Entry<Symbol, Aggregation> entry : aggregation.getAggregations().entrySet()) { Symbol output = entry.getKey(); FunctionCall call = entry.getValue().getCall(); Optional<Symbol> mask = entry.getValue().getMask(); if (call.getFilter().isPresent()) { Expression filter = call.getFilter().get(); Symbol symbol = symbolAllocator.newSymbol(filter, BOOLEAN); newAssignments.put(symbol, filter); mask = Optional.of(symbol); } aggregations.put(output, new Aggregation( new FunctionCall(call.getName(), call.getWindow(), Optional.empty(), call.isDistinct(), call.getArguments()), entry.getValue().getSignature(), mask)); } newAssignments.putIdentities(aggregation.getSource().getOutputSymbols()); return Optional.of( new AggregationNode( idAllocator.getNextId(), new ProjectNode( idAllocator.getNextId(), aggregation.getSource(), newAssignments.build()), aggregations.build(), aggregation.getGroupingSets(), aggregation.getStep(), aggregation.getHashSymbol(), aggregation.getGroupIdSymbol())); }