@Override @Deprecated public PlanNode visitSort(SortNode node, RewriteContext<LimitContext> context) { LimitContext limit = context.get(); PlanNode rewrittenSource = context.rewrite(node.getSource()); if (limit != null) { return new TopNNode(node.getId(), rewrittenSource, limit.getCount(), node.getOrderingScheme(), TopNNode.Step.SINGLE); } else if (rewrittenSource != node.getSource()) { return new SortNode(node.getId(), rewrittenSource, node.getOrderingScheme()); } return node; }
@Override public Void visitSort(SortNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child Set<Symbol> inputs = createInputs(source, boundSymbols); checkDependencies(inputs, node.getOutputSymbols(), "Invalid node. Output symbols (%s) not in source plan output (%s)", node.getOutputSymbols(), node.getSource().getOutputSymbols()); checkDependencies( inputs, node.getOrderingScheme().getOrderBy(), "Invalid node. Order by dependencies (%s) not in source plan output (%s)", node.getOrderingScheme().getOrderBy(), node.getSource().getOutputSymbols()); return null; }
@Override public PlanNode visitSort(SortNode node, List<PlanNode> newChildren) { return new SortNode(node.getId(), Iterables.getOnlyElement(newChildren), node.getOrderBy(), node.getOrderings()); }
private PlanBuilder sort(PlanBuilder subPlan, Optional<OrderBy> orderBy, Optional<String> limit, List<Expression> orderByExpressions) { if (!orderBy.isPresent()) { return subPlan; } Iterator<SortItem> sortItems = orderBy.get().getSortItems().iterator(); ImmutableList.Builder<Symbol> orderBySymbols = ImmutableList.builder(); Map<Symbol, SortOrder> orderings = new HashMap<>(); for (Expression fieldOrExpression : orderByExpressions) { Symbol symbol = subPlan.translate(fieldOrExpression); SortItem sortItem = sortItems.next(); if (!orderings.containsKey(symbol)) { orderBySymbols.add(symbol); orderings.put(symbol, toSortOrder(sortItem)); } } PlanNode planNode; OrderingScheme orderingScheme = new OrderingScheme(orderBySymbols.build(), orderings); if (limit.isPresent() && !limit.get().equalsIgnoreCase("all")) { planNode = new TopNNode(idAllocator.getNextId(), subPlan.getRoot(), Long.parseLong(limit.get()), orderingScheme, TopNNode.Step.SINGLE); } else { planNode = new SortNode(idAllocator.getNextId(), subPlan.getRoot(), orderingScheme); } return subPlan.withNewRoot(planNode); }
@Override public Void visitSort(SortNode node, Integer indent) { Iterable<String> keys = Iterables.transform(node.getOrderingScheme().getOrderBy(), input -> input + " " + node.getOrderingScheme().getOrdering(input)); boolean isPartial = false; if (SystemSessionProperties.isDistributedSortEnabled(session)) { isPartial = true; } print(indent, "- %sSort[%s] => [%s]", isPartial ? "Partial" : "", Joiner.on(", ").join(keys), formatOutputs(node.getOutputSymbols())); printPlanNodesStatsAndCost(indent + 2, node); printStats(indent + 2, node.getId()); return processChildren(node, indent + 1); }
for (Symbol symbol : node.getOrderingScheme().getOrderBy()) { desiredProperties.add(new SortingProperty<>(symbol, node.getOrderingScheme().getOrdering(symbol))); idAllocator.getNextId(), REMOTE, new SortNode( idAllocator.getNextId(), source, node.getOrderingScheme()), node.getOrderingScheme()), child.getProperties());
@Override public Map<PlanNodeId, SplitSource> visitSort(SortNode node, Void context) { return node.getSource().accept(this, context); }
@Override public Void visitSort(SortNode node, Void context) { printNode(node, format("Sort[%s]", Joiner.on(", ").join(node.getOrderingScheme().getOrderBy())), NODE_COLORS.get(NodeType.SORT)); return node.getSource().accept(this, context); }
@Override public Void visitSort(SortNode node, Void context) { PlanNode source = node.getSource(); source.accept(this, context); // visit child verifyUniqueId(node); Set<Symbol> inputs = ImmutableSet.copyOf(source.getOutputSymbols()); checkDependencies(inputs, node.getOutputSymbols(), "Invalid node. Output symbols (%s) not in source plan output (%s)", node.getOutputSymbols(), node.getSource().getOutputSymbols()); checkDependencies(inputs, node.getOrderBy(), "Invalid node. Order by dependencies (%s) not in source plan output (%s)", node.getOrderBy(), node.getSource().getOutputSymbols()); return null; }
@Override public Void visitSort(SortNode node, Integer indent) { Iterable<String> keys = Iterables.transform(node.getOrderBy(), input -> input + " " + node.getOrderings().get(input)); print(indent, "- Sort[%s] => [%s]", Joiner.on(", ").join(keys), formatOutputs(node.getOutputSymbols())); return processChildren(node, indent + 1); }
@Override public ActualProperties visitSort(SortNode node, List<ActualProperties> inputProperties) { ActualProperties properties = Iterables.getOnlyElement(inputProperties); List<SortingProperty<Symbol>> localProperties = node.getOrderingScheme().getOrderBy().stream() .map(column -> new SortingProperty<>(column, node.getOrderingScheme().getOrdering(column))) .collect(toImmutableList()); return ActualProperties.builderFrom(properties) .local(localProperties) .build(); }
@Override public Void visitSort(SortNode node, Void context) { printNode(node, format("Sort[%s]", Joiner.on(", ").join(node.getOrderBy())), NODE_COLORS.get(NodeType.SORT)); return node.getSource().accept(this, context); }
@Override public ActualProperties visitSort(SortNode 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 visitSort(SortNode node, RewriteContext<Set<Symbol>> context) { Set<Symbol> expectedInputs = ImmutableSet.copyOf(concat(context.get(), node.getOrderBy())); PlanNode source = context.rewrite(node.getSource(), expectedInputs); return new SortNode(node.getId(), source, node.getOrderBy(), node.getOrderings()); }
@Test public void testSort() { PlanNode node = new SortNode(newId(), filter(baseTableScan, and( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), new OrderingScheme(ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST))); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Pass through assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))); }
@Override public Map<Symbol, Symbol> visitSort(SortNode node, Set<Symbol> lookupSymbols) { return node.getSource().accept(this, lookupSymbols); }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { SortNode child = captures.get(CHILD); return Result.ofPlanNode( new TopNNode( parent.getId(), child.getSource(), parent.getCount(), child.getOrderingScheme(), parent.isPartial() ? TopNNode.Step.PARTIAL : TopNNode.Step.SINGLE)); } }
@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()); SortNode sortNode = (SortNode) node; if (!orderingSchemeMatches(orderBy, sortNode.getOrderingScheme(), symbolAliases)) { return NO_MATCH; } return MatchResult.match(); }
@Override public PlanNode visitSort(SortNode node, RewriteContext<LimitContext> context) { LimitContext limit = context.get(); PlanNode rewrittenSource = context.rewrite(node.getSource()); if (limit != null) { return new TopNNode(node.getId(), rewrittenSource, limit.getCount(), node.getOrderBy(), node.getOrderings(), false); } else if (rewrittenSource != node.getSource()) { return new SortNode(node.getId(), rewrittenSource, node.getOrderBy(), node.getOrderings()); } return node; }