public List<Symbol> getOriginalDistinctAggregateArgs() { return aggregations.values().stream() .filter(aggregation -> aggregation.getMask().isPresent()) .map(Aggregation::getCall) .flatMap(function -> function.getArguments().stream()) .distinct() .map(Symbol::from) .collect(Collectors.toList()); }
public List<Symbol> getOriginalNonDistinctAggregateArgs() { return aggregations.values().stream() .filter(aggregation -> !aggregation.getMask().isPresent()) .map(Aggregation::getCall) .flatMap(function -> function.getArguments().stream()) .distinct() .map(Symbol::from) .collect(Collectors.toList()); }
public List<Symbol> getOriginalDistinctAggregateArgs() { return aggregations.values().stream() .filter(aggregation -> aggregation.getMask().isPresent()) .map(Aggregation::getCall) .flatMap(function -> function.getArguments().stream()) .distinct() .map(Symbol::from) .collect(Collectors.toList()); }
@Override public Void visitAggregation(AggregationNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child Set<Symbol> inputs = createInputs(source, boundSymbols); checkDependencies(inputs, node.getGroupingKeys(), "Invalid node. Grouping key symbols (%s) not in source plan output (%s)", node.getGroupingKeys(), node.getSource().getOutputSymbols()); for (Aggregation aggregation : node.getAggregations().values()) { Set<Symbol> dependencies = SymbolsExtractor.extractUnique(aggregation.getCall()); checkDependencies(inputs, dependencies, "Invalid node. Aggregation dependencies (%s) not in source plan output (%s)", dependencies, node.getSource().getOutputSymbols()); aggregation.getMask().ifPresent(mask -> { checkDependencies(inputs, ImmutableSet.of(mask), "Invalid node. Aggregation mask symbol (%s) not in source plan output (%s)", mask, node.getSource().getOutputSymbols()); }); } return null; }
private static AggregationNode.Aggregation removeDistinct(AggregationNode.Aggregation aggregation) { checkArgument(aggregation.getCall().isDistinct(), "Expected aggregation to have DISTINCT input"); FunctionCall call = aggregation.getCall(); return new AggregationNode.Aggregation( new FunctionCall( call.getName(), call.getWindow(), call.getFilter(), call.getOrderBy(), false, call.getArguments()), aggregation.getSignature(), aggregation.getMask()); } }
@Override public Void visitAggregation(AggregationNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child Set<Symbol> inputs = createInputs(source, boundSymbols); checkDependencies(inputs, node.getGroupingKeys(), "Invalid node. Grouping key symbols (%s) not in source plan output (%s)", node.getGroupingKeys(), node.getSource().getOutputSymbols()); for (Aggregation aggregation : node.getAggregations().values()) { Set<Symbol> dependencies = SymbolsExtractor.extractUnique(aggregation.getCall()); checkDependencies(inputs, dependencies, "Invalid node. Aggregation dependencies (%s) not in source plan output (%s)", dependencies, node.getSource().getOutputSymbols()); aggregation.getMask().ifPresent(mask -> { checkDependencies(inputs, ImmutableSet.of(mask), "Invalid node. Aggregation mask symbol (%s) not in source plan output (%s)", mask, node.getSource().getOutputSymbols()); }); } return null; }
@Override public Void visitAggregation(AggregationNode node, Void context) { StringBuilder builder = new StringBuilder(); for (Map.Entry<Symbol, Aggregation> entry : node.getAggregations().entrySet()) { if (entry.getValue().getMask().isPresent()) { builder.append(format("%s := %s (mask = %s)\\n", entry.getKey(), entry.getValue().getCall(), entry.getValue().getMask().get())); } else { builder.append(format("%s := %s\\n", entry.getKey(), entry.getValue().getCall())); } } printNode(node, format("Aggregate[%s]", node.getStep()), builder.toString(), NODE_COLORS.get(NodeType.AGGREGATE)); return node.getSource().accept(this, context); }
private static AggregationNode.Aggregation removeDistinct(AggregationNode.Aggregation aggregation) { checkArgument(aggregation.getCall().isDistinct(), "Expected aggregation to have DISTINCT input"); FunctionCall call = aggregation.getCall(); return new AggregationNode.Aggregation( new FunctionCall( call.getName(), call.getWindow(), call.getFilter(), call.getOrderBy(), false, call.getArguments()), aggregation.getSignature(), aggregation.getMask()); } }
@Override public Void visitAggregation(AggregationNode node, Void context) { StringBuilder builder = new StringBuilder(); for (Map.Entry<Symbol, Aggregation> entry : node.getAggregations().entrySet()) { if (entry.getValue().getMask().isPresent()) { builder.append(format("%s := %s (mask = %s)\\n", entry.getKey(), entry.getValue().getCall(), entry.getValue().getMask().get())); } else { builder.append(format("%s := %s\\n", entry.getKey(), entry.getValue().getCall())); } } printNode(node, format("Aggregate[%s]", node.getStep()), builder.toString(), NODE_COLORS.get(NodeType.AGGREGATE)); return node.getSource().accept(this, context); }
public List<Symbol> getOriginalNonDistinctAggregateArgs() { return aggregations.values().stream() .filter(aggregation -> !aggregation.getMask().isPresent()) .map(Aggregation::getCall) .flatMap(function -> function.getArguments().stream()) .distinct() .map(Symbol::from) .collect(Collectors.toList()); }
private static boolean noMasks(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .noneMatch(e -> e.getMask().isPresent()); }
private static boolean hasNoDistinctWithFilterOrMask(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .noneMatch(e -> e.getCall().isDistinct() && (e.getCall().getFilter().isPresent() || e.getMask().isPresent())); }
private static boolean noMasks(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .noneMatch(e -> e.getMask().isPresent()); }
private Aggregation map(Aggregation aggregation) { return new Aggregation( (FunctionCall) map(aggregation.getCall()), aggregation.getSignature(), aggregation.getMask().map(this::map)); }
private static Stream<Symbol> getAggregationInputs(AggregationNode.Aggregation aggregation) { return Streams.concat( SymbolsExtractor.extractUnique(aggregation.getCall()).stream(), aggregation.getMask().map(Stream::of).orElse(Stream.empty())); } }
private static Stream<Symbol> getAggregationInputs(AggregationNode.Aggregation aggregation) { return Streams.concat( SymbolsExtractor.extractUnique(aggregation.getCall()).stream(), aggregation.getMask().map(Stream::of).orElse(Stream.empty())); } }
private static boolean hasFilters(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .anyMatch(e -> e.getCall().getFilter().isPresent() && !e.getMask().isPresent()); // can't handle filtered aggregations with DISTINCT (conservatively, if they have a mask) }
private static boolean hasNoDistinctWithFilterOrMask(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .noneMatch(e -> e.getCall().isDistinct() && (e.getCall().getFilter().isPresent() || e.getMask().isPresent())); }
private static boolean hasFilters(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .anyMatch(e -> e.getCall().getFilter().isPresent() && !e.getMask().isPresent()); // can't handle filtered aggregations with DISTINCT (conservatively, if they have a mask) }
private Aggregation map(Aggregation aggregation) { return new Aggregation( (FunctionCall) map(aggregation.getCall()), aggregation.getSignature(), aggregation.getMask().map(this::map)); }