@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new GroupIdNode(getId(), Iterables.getOnlyElement(newChildren), groupingSets, groupingColumns, aggregationArguments, groupIdSymbol); } }
groups.add(ImmutableList.copyOf(group1)); return new GroupIdNode( idAllocator.getNextId(), source,
@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 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())); }
if (groupingSets.size() > 1) { groupIdSymbol = Optional.of(symbolAllocator.newSymbol("groupId", BIGINT)); GroupIdNode groupId = new GroupIdNode(idAllocator.getNextId(), subPlan.getRoot(), groupingSets, groupingSetMappings, aggregationArguments, groupIdSymbol.get()); subPlan = new PlanBuilder(groupingTranslations, groupId, analysis.getParameters());
@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 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())); }
GroupIdNode groupId = new GroupIdNode(idAllocator.getNextId(), subPlan.getRoot(), subPlan.getRoot().getOutputSymbols(), groupingSetsSymbolsBuilder.build(), groupIdSymbol); subPlan = new PlanBuilder(subPlan.getTranslations(), groupId, subPlan.getSampleWeight()); distinctGroupingSymbolsBuilder.add(groupIdSymbol);