@Override public Map<PlanNodeId, SplitSource> visitGroupId(GroupIdNode node, Void context) { return node.getSource().accept(this, context); }
@Override public Void visitGroupId(GroupIdNode node, Void context) { // grouping sets are easier to understand in terms of inputs List<String> inputGroupingSetSymbols = node.getGroupingSets().stream() .map(set -> "(" + Joiner.on(", ").join(set.stream() .map(symbol -> node.getGroupingColumns().get(symbol)) .collect(Collectors.toList())) + ")") .collect(Collectors.toList()); printNode(node, "GroupId", Joiner.on(", ").join(inputGroupingSetSymbols), NODE_COLORS.get(NodeType.AGGREGATE)); return node.getSource().accept(this, context); }
@Override public PlanNode visitGroupId(GroupIdNode node, RewriteContext<Set<Symbol>> context) { ImmutableSet.Builder<Symbol> expectedInputs = ImmutableSet.builder(); List<Symbol> newAggregationArguments = node.getAggregationArguments().stream() .filter(context.get()::contains) .collect(Collectors.toList()); expectedInputs.addAll(newAggregationArguments); ImmutableList.Builder<List<Symbol>> newGroupingSets = ImmutableList.builder(); Map<Symbol, Symbol> newGroupingMapping = new HashMap<>(); for (List<Symbol> groupingSet : node.getGroupingSets()) { ImmutableList.Builder<Symbol> newGroupingSet = ImmutableList.builder(); for (Symbol output : groupingSet) { if (context.get().contains(output)) { newGroupingSet.add(output); newGroupingMapping.putIfAbsent(output, node.getGroupingColumns().get(output)); expectedInputs.add(node.getGroupingColumns().get(output)); } } newGroupingSets.add(newGroupingSet.build()); } PlanNode source = context.rewrite(node.getSource(), expectedInputs.build()); return new GroupIdNode(node.getId(), source, newGroupingSets.build(), newGroupingMapping, newAggregationArguments, node.getGroupIdSymbol()); }
@Override public PlanWithProperties visitGroupId(GroupIdNode node, HashComputationSet parentPreference) { // remove any hash symbols not exported by the source of this node return planSimpleNodeWithProperties(node, parentPreference.pruneSymbols(node.getSource().getOutputSymbols())); }
@Override public PlanNode visitGroupId(GroupIdNode node, RewriteContext<Void> context) { PlanNode source = context.rewrite(node.getSource()); Map<Symbol, Symbol> newGroupingMappings = new HashMap<>(); ImmutableList.Builder<List<Symbol>> newGroupingSets = ImmutableList.builder(); for (List<Symbol> groupingSet : node.getGroupingSets()) { ImmutableList.Builder<Symbol> newGroupingSet = ImmutableList.builder(); for (Symbol output : groupingSet) { newGroupingMappings.putIfAbsent(canonicalize(output), canonicalize(node.getGroupingColumns().get(output))); newGroupingSet.add(canonicalize(output)); } newGroupingSets.add(newGroupingSet.build()); } return new GroupIdNode(node.getId(), source, newGroupingSets.build(), newGroupingMappings, canonicalizeAndDistinct(node.getAggregationArguments()), canonicalize(node.getGroupIdSymbol())); }
@Override public PhysicalOperation visitGroupId(GroupIdNode node, LocalExecutionPlanContext context) PhysicalOperation source = node.getSource().accept(this, context); Map<Symbol, Integer> newLayout = new HashMap<>(); ImmutableList.Builder<Type> outputTypes = ImmutableList.builder();
@Override public Void visitGroupId(GroupIdNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child checkDependencies(source.getOutputSymbols(), node.getInputSymbols(), "Invalid node. Grouping symbols (%s) not in source plan output (%s)", node.getInputSymbols(), source.getOutputSymbols()); return null; }
@Override public Optional<SplitSource> visitGroupId(GroupIdNode node, Void context) { return node.getSource().accept(this, context); }
@Override public Void visitGroupId(GroupIdNode node, Void context) { node.getSource().accept(this, context); builder.add(node.getGroupIdSymbol()); return null; }
@Override public PlanNode visitGroupId(GroupIdNode node, RewriteContext<Set<Symbol>> context) { checkState(node.getDistinctGroupingColumns().stream().allMatch(column -> context.get().contains(column))); PlanNode source = context.rewrite(node.getSource(), ImmutableSet.copyOf(context.get())); List<Symbol> requiredSymbols = context.get().stream() .filter(symbol -> !symbol.equals(node.getGroupIdSymbol())) .collect(toImmutableList()); return new GroupIdNode(node.getId(), source, requiredSymbols, node.getGroupingSets(), node.getGroupIdSymbol()); }
@Override public PhysicalOperation visitGroupId(GroupIdNode node, LocalExecutionPlanContext context) { PhysicalOperation source = node.getSource().accept(this, context); // add groupId to the layout int groupIdChannel = source.getLayout().values().stream() .mapToInt(Integer::intValue) .max() .orElse(-1) + 1; Map<Symbol, Integer> newLayout = ImmutableMap.<Symbol, Integer>builder() .putAll(source.getLayout()) .put(node.getGroupIdSymbol(), groupIdChannel) .build(); List<List<Integer>> groupingSetChannels = node.getGroupingSets().stream() .map(groupingSet -> getChannelsForSymbols(groupingSet, source.getLayout())) .collect(toImmutableList()); OperatorFactory groupIdOperatorFactory = new GroupIdOperator.GroupIdOperatorFactory(context.getNextOperatorId(), node.getId(), source.getTypes(), groupingSetChannels); return new PhysicalOperation(groupIdOperatorFactory, newLayout, source); }
@Override public PlanNode visitGroupId(GroupIdNode node, RewriteContext<Void> context) { PlanNode source = context.rewrite(node.getSource()); List<List<Symbol>> groupingSetsSymbols = node.getGroupingSets().stream() .map(this::canonicalize) .collect(Collectors.toList()); return new GroupIdNode(node.getId(), source, canonicalize(node.getInputSymbols()), groupingSetsSymbols, canonicalize(node.getGroupIdSymbol())); }
@Override public Void visitGroupId(GroupIdNode node, Void context) { PlanNode source = node.getSource(); source.accept(this, context); // visit child verifyUniqueId(node); checkDependencies(source.getOutputSymbols(), node.getInputSymbols(), "Invalid node. Grouping symbols (%s) not in source plan output (%s)", node.getInputSymbols(), source.getOutputSymbols()); return null; }