@Override public Void visitTopN(final TopNNode node, Void context) { Iterable<String> keys = Iterables.transform(node.getOrderBy(), input -> input + " " + node.getOrderings().get(input)); printNode(node, format("TopN[%s]", node.getCount()), Joiner.on(", ").join(keys), NODE_COLORS.get(NodeType.TOPN)); return node.getSource().accept(this, context); }
@Override public Void visitTopN(TopNNode node, Integer indent) { Iterable<String> keys = Iterables.transform(node.getOrderBy(), input -> input + " " + node.getOrderings().get(input)); print(indent, "- TopN[%s by (%s)] => [%s]", node.getCount(), Joiner.on(", ").join(keys), formatOutputs(node.getOutputSymbols())); return processChildren(node, indent + 1); }
@Override public ActualProperties visitTopN(TopNNode node, List<ActualProperties> inputProperties) { ActualProperties properties = Iterables.getOnlyElement(inputProperties); List<SortingProperty<Symbol>> localProperties = node.getOrderBy().stream() .map(column -> new SortingProperty<>(column, node.getOrderings().get(column))) .collect(toImmutableList()); return ActualProperties.builderFrom(properties) .local(localProperties) .build(); }
@Override public PlanNode visitTopN(TopNNode node, RewriteContext<Void> context) { PlanNode source = context.rewrite(node.getSource()); ImmutableList.Builder<Symbol> symbols = ImmutableList.builder(); ImmutableMap.Builder<Symbol, SortOrder> orderings = ImmutableMap.builder(); for (Symbol symbol : node.getOrderBy()) { Symbol canonical = canonicalize(symbol); symbols.add(canonical); orderings.put(canonical, node.getOrderings().get(symbol)); } return new TopNNode(node.getId(), source, node.getCount(), symbols.build(), orderings.build(), node.isPartial()); }
@Override public PlanNode visitTopN(TopNNode node, RewriteContext<Set<Symbol>> context) { ImmutableSet.Builder<Symbol> expectedInputs = ImmutableSet.<Symbol>builder() .addAll(context.get()) .addAll(node.getOrderBy()); PlanNode source = context.rewrite(node.getSource(), expectedInputs.build()); return new TopNNode(node.getId(), source, node.getCount(), node.getOrderBy(), node.getOrderings(), node.isPartial()); }
@Override public PlanNode visitTopN(TopNNode node, List<PlanNode> newChildren) { return new TopNNode(node.getId(), Iterables.getOnlyElement(newChildren), node.getCount(), node.getOrderBy(), node.getOrderings(), node.isPartial()); }
@Override public PhysicalOperation visitTopN(TopNNode node, LocalExecutionPlanContext context) { PhysicalOperation source = node.getSource().accept(this, context); List<Symbol> orderBySymbols = node.getOrderBy(); List<Integer> sortChannels = new ArrayList<>(); List<SortOrder> sortOrders = new ArrayList<>(); for (Symbol symbol : orderBySymbols) { sortChannels.add(source.getLayout().get(symbol)); sortOrders.add(node.getOrderings().get(symbol)); } OperatorFactory operator = new TopNOperatorFactory( context.getNextOperatorId(), node.getId(), source.getTypes(), (int) node.getCount(), sortChannels, sortOrders, node.isPartial()); return new PhysicalOperation(operator, source.getLayout(), source); }
@Override public PlanNode visitTopN(TopNNode node, RewriteContext<LimitContext> context) { LimitContext limit = context.get(); PlanNode rewrittenSource = context.rewrite(node.getSource()); if (rewrittenSource == node.getSource() && limit == null) { return node; } long count = node.getCount(); if (limit != null) { count = Math.min(count, limit.getCount()); } return new TopNNode(node.getId(), rewrittenSource, count, node.getOrderBy(), node.getOrderings(), node.isPartial()); }
@Override public PlanWithProperties visitTopN(TopNNode node, Context context) { PlanWithProperties child = planChild(node, context.withPreferredProperties(PreferredProperties.any())); if (!child.getProperties().isSingleNode()) { child = withDerivedProperties( new TopNNode(idAllocator.getNextId(), child.getNode(), node.getCount(), node.getOrderBy(), node.getOrderings(), true), child.getProperties()); child = withDerivedProperties( gatheringExchange(idAllocator.getNextId(), child.getNode()), child.getProperties()); } return rebaseAndDeriveProperties(node, child); }