public PlanNode resolve(GroupReference groupReference) { return getNode(groupReference.getGroupId()); }
private boolean exploreChildren(int group, Context context, Matcher matcher) { boolean progress = false; PlanNode expression = context.memo.getNode(group); for (PlanNode child : expression.getSources()) { checkState(child instanceof GroupReference, "Expected child to be a group reference. Found: " + child.getClass().getName()); if (exploreGroup(((GroupReference) child).getGroupId(), context, matcher)) { progress = true; } } return progress; }
@Override public Void visitGroupReference(GroupReference node, Integer indent) { print(indent, "- GroupReference[%s] => [%s]", node.getGroupId(), formatOutputs(node.getOutputSymbols())); return null; }
private PlanNodeCostEstimate getGroupCost(GroupReference groupReference) { int group = groupReference.getGroupId(); Memo memo = this.memo.orElseThrow(() -> new IllegalStateException("CachingCostProvider without memo cannot handle GroupReferences")); Optional<PlanNodeCostEstimate> cost = memo.getCumulativeCost(group); if (cost.isPresent()) { return cost.get(); } PlanNodeCostEstimate cumulativeCost = calculateCumulativeCost(memo.getNode(group)); verify(!memo.getCumulativeCost(group).isPresent(), "Group cost already set"); memo.storeCumulativeCost(group, cumulativeCost); return cumulativeCost; }
private PlanNodeStatsEstimate getGroupStats(GroupReference groupReference) { int group = groupReference.getGroupId(); Memo memo = this.memo.orElseThrow(() -> new IllegalStateException("CachingStatsProvider without memo cannot handle GroupReferences")); Optional<PlanNodeStatsEstimate> stats = memo.getStats(group); if (stats.isPresent()) { return stats.get(); } PlanNodeStatsEstimate groupStats = statsCalculator.calculateStats(memo.getNode(group), this, lookup, session, types); verify(!memo.getStats(group).isPresent(), "Group stats already set"); memo.storeStats(group, groupStats); return groupStats; } }
private int insertRecursive(PlanNode node) { if (node instanceof GroupReference) { return ((GroupReference) node).getGroupId(); } int group = nextGroupId(); PlanNode rewritten = insertChildrenAndRewrite(node); groups.put(group, Group.withMember(rewritten)); incrementReferenceCounts(rewritten, group); return group; }
private int getChildGroup(Memo memo, int group) { PlanNode node = memo.getNode(group); GroupReference child = (GroupReference) node.getSources().get(0); return child.getGroupId(); }
public PlanNode replace(int group, PlanNode node, String reason) { PlanNode old = getGroup(group).membership; checkArgument(new HashSet<>(old.getOutputSymbols()).equals(new HashSet<>(node.getOutputSymbols())), "%s: transformed expression doesn't produce same outputs: %s vs %s", reason, old.getOutputSymbols(), node.getOutputSymbols()); if (node instanceof GroupReference) { node = getNode(((GroupReference) node).getGroupId()); } else { node = insertChildrenAndRewrite(node); } incrementReferenceCounts(node, group); getGroup(group).membership = node; decrementReferenceCounts(old, group); evictStatisticsAndCost(group); return node; }