@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 Void visitGroupId(GroupIdNode node, Integer indent) { // grouping sets are easier to understand in terms of inputs List<List<Symbol>> inputGroupingSetSymbols = node.getGroupingSets().stream() .map(set -> set.stream() .map(symbol -> node.getGroupingColumns().get(symbol)) .collect(Collectors.toList())) .collect(Collectors.toList()); print(indent, "- GroupId%s => [%s]", inputGroupingSetSymbols, formatOutputs(node.getOutputSymbols())); printPlanNodesStatsAndCost(indent + 2, node); printStats(indent + 2, node.getId()); for (Map.Entry<Symbol, Symbol> mapping : node.getGroupingColumns().entrySet()) { print(indent + 2, "%s := %s", mapping.getKey(), mapping.getValue()); } return processChildren(node, indent + 1); }
@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()); }
for (Symbol output : node.getGroupingSets().stream().flatMap(Collection::stream).collect(Collectors.toSet())) { newLayout.put(output, outputChannel++); outputTypes.add(source.getTypes().get(source.getLayout().get(node.getGroupingColumns().get(output)))); for (List<Symbol> groupingSet : node.getGroupingSets()) { ImmutableMap.Builder<Integer, Integer> setMapping = ImmutableMap.builder();
@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 MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) { checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName()); GroupIdNode groudIdNode = (GroupIdNode) node; List<List<Symbol>> actualGroups = groudIdNode.getGroupingSets(); List<Symbol> actualAggregationArguments = groudIdNode.getAggregationArguments(); if (actualGroups.size() != groups.size()) { return NO_MATCH; } for (int i = 0; i < actualGroups.size(); i++) { if (!AggregationMatcher.matches(groups.get(i), actualGroups.get(i), symbolAliases)) { return NO_MATCH; } } if (!AggregationMatcher.matches(identityMappings.keySet(), actualAggregationArguments, symbolAliases)) { return NO_MATCH; } return match(groupIdAlias, groudIdNode.getGroupIdSymbol().toSymbolReference()); }
@Override public Void visitGroupId(GroupIdNode node, Integer indent) { print(indent, "- GroupId%s => [%s]", node.getGroupingSets(), formatOutputs(node.getOutputSymbols())); return processChildren(node, indent + 1); }
@Override public PlanNode visitGroupId(GroupIdNode node, List<PlanNode> newChildren) { return new GroupIdNode(node.getId(), Iterables.getOnlyElement(newChildren), node.getInputSymbols(), 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<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 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())); }