@Override public PlanNode visitTopNRowNumber(TopNRowNumberNode node, RewriteContext<Void> context) { return new TopNRowNumberNode( node.getId(), context.rewrite(node.getSource()), canonicalizeAndDistinct(node.getSpecification()), canonicalize(node.getRowNumberSymbol()), node.getMaxRowCountPerPartition(), node.isPartial(), canonicalize(node.getHashSymbol())); }
@Override public Void visitTopNRowNumber(TopNRowNumberNode node, Void context) { printNode(node, "TopNRowNumber", format("partition by = %s|order by = %s|n = %s", Joiner.on(", ").join(node.getPartitionBy()), Joiner.on(", ").join(node.getOrderingScheme().getOrderBy()), node.getMaxRowCountPerPartition()), NODE_COLORS.get(NodeType.WINDOW)); return node.getSource().accept(this, context); }
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new TopNRowNumberNode(getId(), Iterables.getOnlyElement(newChildren), specification, rowNumberSymbol, maxRowCountPerPartition, partial, hashSymbol); } }
@Override public Void visitTopNRowNumber(TopNRowNumberNode node, Integer indent) { List<String> partitionBy = node.getPartitionBy().stream() .map(Functions.toStringFunction()) .collect(toImmutableList()); List<String> orderBy = node.getOrderingScheme().getOrderBy().stream() .map(input -> input + " " + node.getOrderingScheme().getOrdering(input)) .collect(toImmutableList()); List<String> args = new ArrayList<>(); args.add(format("partition by (%s)", Joiner.on(", ").join(partitionBy))); args.add(format("order by (%s)", Joiner.on(", ").join(orderBy))); print(indent, "- TopNRowNumber[%s limit %s]%s => [%s]", Joiner.on(", ").join(args), node.getMaxRowCountPerPartition(), formatHash(node.getHashSymbol()), formatOutputs(node.getOutputSymbols())); printPlanNodesStatsAndCost(indent + 2, node); printStats(indent + 2, node.getId()); print(indent + 2, "%s := %s", node.getRowNumberSymbol(), "row_number()"); return processChildren(node, indent + 1); }
Function<PlanNode, PlanNode> addExchange; if (node.getPartitionBy().isEmpty()) { preferredChildProperties = PreferredProperties.any(); addExchange = partial -> gatheringExchange(idAllocator.getNextId(), REMOTE, partial); preferredChildProperties = PreferredProperties.partitionedWithLocal(ImmutableSet.copyOf(node.getPartitionBy()), grouped(node.getPartitionBy())) .mergeWithParent(preferredProperties); addExchange = partial -> partitionedExchange(idAllocator.getNextId(), REMOTE, partial, node.getPartitionBy(), node.getHashSymbol()); if (!child.getProperties().isStreamPartitionedOn(node.getPartitionBy())) { new TopNRowNumberNode( idAllocator.getNextId(), child.getNode(), node.getSpecification(), node.getRowNumberSymbol(), node.getMaxRowCountPerPartition(), true, node.getHashSymbol()), child.getProperties());
@Override public Void visitTopNRowNumber(TopNRowNumberNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child Set<Symbol> inputs = createInputs(source, boundSymbols); checkDependencies(inputs, node.getPartitionBy(), "Invalid node. Partition by symbols (%s) not in source plan output (%s)", node.getPartitionBy(), node.getSource().getOutputSymbols()); checkDependencies( inputs, node.getOrderingScheme().getOrderBy(), "Invalid node. Order by symbols (%s) not in source plan output (%s)", node.getOrderingScheme().getOrderBy(), node.getSource().getOutputSymbols()); return null; }
@Override public PlanWithProperties visitTopNRowNumber(TopNRowNumberNode node, StreamPreferredProperties parentPreferences) { StreamPreferredProperties requiredProperties = parentPreferences.withDefaultParallelism(session); // final topN row number requires that all data be partitioned if (!node.isPartial()) { requiredProperties = requiredProperties.withPartitioning(node.getPartitionBy()); } return planAndEnforceChildren(node, requiredProperties, requiredProperties); }
@Override public ActualProperties visitTopNRowNumber(TopNRowNumberNode node, List<ActualProperties> inputProperties) { ActualProperties properties = Iterables.getOnlyElement(inputProperties); ImmutableList.Builder<LocalProperty<Symbol>> localProperties = ImmutableList.builder(); localProperties.add(new GroupingProperty<>(node.getPartitionBy())); for (Symbol column : node.getOrderingScheme().getOrderBy()) { localProperties.add(new SortingProperty<>(column, node.getOrderingScheme().getOrdering(column))); } return ActualProperties.builderFrom(properties) .local(localProperties.build()) .build(); }
@Override public Map<PlanNodeId, SplitSource> visitTopNRowNumber(TopNRowNumberNode node, Void context) { return node.getSource().accept(this, context); }
private TopNRowNumberNode convertToTopNRowNumber(WindowNode windowNode, int limit) { return new TopNRowNumberNode(idAllocator.getNextId(), windowNode.getSource(), windowNode.getSpecification(), getOnlyElement(windowNode.getWindowFunctions().keySet()), limit, false, Optional.empty()); }
@Override public Void visitTopNRowNumber(TopNRowNumberNode node, Integer indent) { List<String> partitionBy = node.getPartitionBy().stream() .map(Functions.toStringFunction()) .collect(toImmutableList()); List<String> orderBy = node.getOrderingScheme().getOrderBy().stream() .map(input -> input + " " + node.getOrderingScheme().getOrdering(input)) .collect(toImmutableList()); List<String> args = new ArrayList<>(); args.add(format("partition by (%s)", Joiner.on(", ").join(partitionBy))); args.add(format("order by (%s)", Joiner.on(", ").join(orderBy))); print(indent, "- TopNRowNumber[%s limit %s]%s => [%s]", Joiner.on(", ").join(args), node.getMaxRowCountPerPartition(), formatHash(node.getHashSymbol()), formatOutputs(node.getOutputSymbols())); printPlanNodesStatsAndCost(indent + 2, node); printStats(indent + 2, node.getId()); print(indent + 2, "%s := %s", node.getRowNumberSymbol(), "row_number()"); return processChildren(node, indent + 1); }
Function<PlanNode, PlanNode> addExchange; if (node.getPartitionBy().isEmpty()) { preferredChildProperties = PreferredProperties.any(); addExchange = partial -> gatheringExchange(idAllocator.getNextId(), REMOTE, partial); preferredChildProperties = PreferredProperties.partitionedWithLocal(ImmutableSet.copyOf(node.getPartitionBy()), grouped(node.getPartitionBy())) .mergeWithParent(preferredProperties); addExchange = partial -> partitionedExchange(idAllocator.getNextId(), REMOTE, partial, node.getPartitionBy(), node.getHashSymbol()); if (!child.getProperties().isStreamPartitionedOn(node.getPartitionBy())) { new TopNRowNumberNode( idAllocator.getNextId(), child.getNode(), node.getSpecification(), node.getRowNumberSymbol(), node.getMaxRowCountPerPartition(), true, node.getHashSymbol()), child.getProperties());
@Override public Void visitTopNRowNumber(TopNRowNumberNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child Set<Symbol> inputs = createInputs(source, boundSymbols); checkDependencies(inputs, node.getPartitionBy(), "Invalid node. Partition by symbols (%s) not in source plan output (%s)", node.getPartitionBy(), node.getSource().getOutputSymbols()); checkDependencies( inputs, node.getOrderingScheme().getOrderBy(), "Invalid node. Order by symbols (%s) not in source plan output (%s)", node.getOrderingScheme().getOrderBy(), node.getSource().getOutputSymbols()); return null; }
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new TopNRowNumberNode(getId(), Iterables.getOnlyElement(newChildren), specification, rowNumberSymbol, maxRowCountPerPartition, partial, hashSymbol); } }
@Override public PlanWithProperties visitTopNRowNumber(TopNRowNumberNode node, StreamPreferredProperties parentPreferences) { StreamPreferredProperties requiredProperties = parentPreferences.withDefaultParallelism(session); // final topN row number requires that all data be partitioned if (!node.isPartial()) { requiredProperties = requiredProperties.withPartitioning(node.getPartitionBy()); } return planAndEnforceChildren(node, requiredProperties, requiredProperties); }
@Override public ActualProperties visitTopNRowNumber(TopNRowNumberNode node, List<ActualProperties> inputProperties) { ActualProperties properties = Iterables.getOnlyElement(inputProperties); ImmutableList.Builder<LocalProperty<Symbol>> localProperties = ImmutableList.builder(); localProperties.add(new GroupingProperty<>(node.getPartitionBy())); for (Symbol column : node.getOrderingScheme().getOrderBy()) { localProperties.add(new SortingProperty<>(column, node.getOrderingScheme().getOrdering(column))); } return ActualProperties.builderFrom(properties) .local(localProperties.build()) .build(); }
@Override public Map<PlanNodeId, SplitSource> visitTopNRowNumber(TopNRowNumberNode node, Void context) { return node.getSource().accept(this, context); }
private TopNRowNumberNode convertToTopNRowNumber(WindowNode windowNode, int limit) { return new TopNRowNumberNode(idAllocator.getNextId(), windowNode.getSource(), windowNode.getSpecification(), getOnlyElement(windowNode.getWindowFunctions().keySet()), limit, false, Optional.empty()); }
@Override public PlanNode visitTopNRowNumber(TopNRowNumberNode node, RewriteContext<Void> context) { return new TopNRowNumberNode( node.getId(), context.rewrite(node.getSource()), canonicalizeAndDistinct(node.getSpecification()), canonicalize(node.getRowNumberSymbol()), node.getMaxRowCountPerPartition(), node.isPartial(), canonicalize(node.getHashSymbol())); }
@Override public Void visitTopNRowNumber(TopNRowNumberNode node, Void context) { printNode(node, "TopNRowNumber", format("partition by = %s|order by = %s|n = %s", Joiner.on(", ").join(node.getPartitionBy()), Joiner.on(", ").join(node.getOrderingScheme().getOrderBy()), node.getMaxRowCountPerPartition()), NODE_COLORS.get(NodeType.WINDOW)); return node.getSource().accept(this, context); }