@Override public Void visitLimit(LimitNode node, Integer indent) { print(indent, "- Limit%s[%s] => [%s]", node.isPartial() ? "Partial" : "", node.getCount(), formatOutputs(node.getOutputSymbols())); printPlanNodesStatsAndCost(indent + 2, node); printStats(indent + 2, node.getId()); return processChildren(node, indent + 1); }
private PlanBuilder limit(PlanBuilder subPlan, Optional<OrderBy> orderBy, Optional<String> limit) { if (!orderBy.isPresent() && limit.isPresent()) { if (!limit.get().equalsIgnoreCase("all")) { long limitValue = Long.parseLong(limit.get()); subPlan = subPlan.withNewRoot(new LimitNode(idAllocator.getNextId(), subPlan.getRoot(), limitValue, false)); } } return subPlan; }
@Override public PhysicalOperation visitLimit(LimitNode node, LocalExecutionPlanContext context) { PhysicalOperation source = node.getSource().accept(this, context); OperatorFactory operatorFactory = new LimitOperatorFactory(context.getNextOperatorId(), node.getId(), node.getCount()); return new PhysicalOperation(operatorFactory, source.getLayout(), context, source); }
@Override public PlanWithProperties visitLimit(LimitNode node, PreferredProperties preferredProperties) { PlanWithProperties child = planChild(node, PreferredProperties.any()); if (!child.getProperties().isSingleNode()) { child = withDerivedProperties( new LimitNode(idAllocator.getNextId(), child.getNode(), node.getCount(), true), child.getProperties()); child = withDerivedProperties( gatheringExchange(idAllocator.getNextId(), REMOTE, child.getNode()), child.getProperties()); } return rebaseAndDeriveProperties(node, child); }
@Override public PlanNode visitLimit(LimitNode node, RewriteContext<LimitContext> context) { long count = node.getCount(); if (context.get() != null) { count = Math.min(count, context.get().getCount()); } // return empty ValuesNode in case of limit 0 if (count == 0) { return new ValuesNode(idAllocator.getNextId(), node.getOutputSymbols(), ImmutableList.of()); } // default visitPlan logic will insert the limit node return context.rewrite(node.getSource(), new LimitContext(count, false)); }
@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 Void visitLimit(LimitNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child return null; }
@Override public Void visitLimit(LimitNode node, Integer indent) { print(indent, "- Limit[%s] => [%s]", node.getCount(), formatOutputs(node.getOutputSymbols())); return processChildren(node, indent + 1); }
@Override public Result apply(LimitNode limit, Captures captures, Context context) { return Result.ofPlanNode(new ValuesNode(limit.getId(), limit.getOutputSymbols(), ImmutableList.of())); } }
@Override public Boolean visitLimit(LimitNode node, Void context) { return node.getCount() <= 1; }
@Override public PlanNodeCostEstimate visitLimit(LimitNode node, Void context) { // This is just a wild guess. First of all, LimitNode is rather rare except as a top node of a query plan, // so proper cost estimation is not that important. Second, since LimitNode can lead to incomplete evaluation // of the source, true cost estimation should be implemented as a "constraint" enforced on a sub-tree and // evaluated in context of actual source node type (and their sources). return cpuCost(getStats(node).getOutputSizeInBytes(node.getOutputSymbols(), types)); }
@Override public PlanWithProperties visitLimit(LimitNode node, StreamPreferredProperties parentPreferences) { if (node.isPartial()) { return planAndEnforceChildren( node, parentPreferences.withoutPreference().withDefaultParallelism(session), parentPreferences.withDefaultParallelism(session)); } // final limit requires that all data be in one stream // also, a final changes the input organization completely, so we do not pass through parent preferences return planAndEnforceChildren( node, singleStream(), defaultParallelism(session)); }
public LimitNode limit(long limit, PlanNode source) { return new LimitNode(idAllocator.getNextId(), source, limit, false); }
@Override public Range<Long> visitLimit(LimitNode node, Void context) { Range<Long> sourceCardinalityRange = node.getSource().accept(this, null); long upper = node.getCount(); if (sourceCardinalityRange.hasUpperBound()) { upper = min(sourceCardinalityRange.upperEndpoint(), node.getCount()); } long lower = min(upper, sourceCardinalityRange.lowerEndpoint()); return Range.closed(lower, upper); } }
@Override public PhysicalOperation visitLimit(LimitNode node, LocalExecutionPlanContext context) { PhysicalOperation source = node.getSource().accept(this, context); OperatorFactory operatorFactory = new LimitOperatorFactory(context.getNextOperatorId(), node.getId(), source.getTypes(), node.getCount()); return new PhysicalOperation(operatorFactory, source.getLayout(), source); }