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; }
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 PlanNode replaceChildren(List<PlanNode> newChildren) { return new LimitNode(getId(), Iterables.getOnlyElement(newChildren), count, isPartial()); } }
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new LimitNode(getId(), Iterables.getOnlyElement(newChildren), count, isPartial()); } }
@Override public PlanNode visitLimit(LimitNode node, RewriteContext<Set<Symbol>> context) { ImmutableSet.Builder<Symbol> expectedInputs = ImmutableSet.<Symbol>builder() .addAll(context.get()); PlanNode source = context.rewrite(node.getSource(), expectedInputs.build()); return new LimitNode(node.getId(), source, node.getCount(), node.isPartial()); }
@Override public PlanNode visitLimit(LimitNode node, RewriteContext<Set<Symbol>> context) { ImmutableSet.Builder<Symbol> expectedInputs = ImmutableSet.<Symbol>builder() .addAll(context.get()); PlanNode source = context.rewrite(node.getSource(), expectedInputs.build()); return new LimitNode(node.getId(), source, node.getCount(), node.isPartial()); }
public LimitNode limit(long limit, PlanNode source) { return new LimitNode(idAllocator.getNextId(), source, limit, false); }
public LimitNode limit(long limit, PlanNode source) { return new LimitNode(idAllocator.getNextId(), source, limit, false); }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { LimitNode child = captures.get(CHILD); return Result.ofPlanNode( new LimitNode( parent.getId(), child.getSource(), Math.min(parent.getCount(), child.getCount()), parent.isPartial())); } }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { LimitNode child = captures.get(CHILD); return Result.ofPlanNode( new LimitNode( parent.getId(), child.getSource(), Math.min(parent.getCount(), child.getCount()), parent.isPartial())); } }
@Override public PlanNode visitPlan(PlanNode node, RewriteContext<LimitContext> context) { PlanNode rewrittenNode = context.defaultRewrite(node); LimitContext limit = context.get(); if (limit != null) { // Drop in a LimitNode b/c we cannot push our limit down any further rewrittenNode = new LimitNode(idAllocator.getNextId(), rewrittenNode, limit.getCount(), limit.isPartial()); } return rewrittenNode; }
@Override public PlanNode visitPlan(PlanNode node, RewriteContext<LimitContext> context) { PlanNode rewrittenNode = context.defaultRewrite(node); LimitContext limit = context.get(); if (limit != null) { // Drop in a LimitNode b/c we cannot push our limit down any further rewrittenNode = new LimitNode(idAllocator.getNextId(), rewrittenNode, limit.getCount(), limit.isPartial()); } return rewrittenNode; }
@Override @Deprecated public PlanNode visitAggregation(AggregationNode node, RewriteContext<LimitContext> context) { LimitContext limit = context.get(); if (limit != null && node.getAggregations().isEmpty() && node.getOutputSymbols().size() == node.getGroupingKeys().size() && node.getOutputSymbols().containsAll(node.getGroupingKeys())) { PlanNode rewrittenSource = context.rewrite(node.getSource()); return new DistinctLimitNode(idAllocator.getNextId(), rewrittenSource, limit.getCount(), false, rewrittenSource.getOutputSymbols(), Optional.empty()); } PlanNode rewrittenNode = context.defaultRewrite(node); if (limit != null) { // Drop in a LimitNode b/c limits cannot be pushed through aggregations rewrittenNode = new LimitNode(idAllocator.getNextId(), rewrittenNode, limit.getCount(), limit.isPartial()); } return rewrittenNode; }
@Override public PlanNode visitUnion(UnionNode node, RewriteContext<LimitContext> context) { LimitContext limit = context.get(); LimitContext childLimit = null; if (limit != null) { childLimit = new LimitContext(limit.getCount(), true); } List<PlanNode> sources = new ArrayList<>(); for (int i = 0; i < node.getSources().size(); i++) { sources.add(context.rewrite(node.getSources().get(i), childLimit)); } PlanNode output = new UnionNode(node.getId(), sources, node.getSymbolMapping(), node.getOutputSymbols()); if (limit != null) { output = new LimitNode(idAllocator.getNextId(), output, limit.getCount(), limit.isPartial()); } return output; }
@Override @Deprecated public PlanNode visitAggregation(AggregationNode node, RewriteContext<LimitContext> context) { LimitContext limit = context.get(); if (limit != null && node.getAggregations().isEmpty() && node.getOutputSymbols().size() == node.getGroupingKeys().size() && node.getOutputSymbols().containsAll(node.getGroupingKeys())) { PlanNode rewrittenSource = context.rewrite(node.getSource()); return new DistinctLimitNode(idAllocator.getNextId(), rewrittenSource, limit.getCount(), false, rewrittenSource.getOutputSymbols(), Optional.empty()); } PlanNode rewrittenNode = context.defaultRewrite(node); if (limit != null) { // Drop in a LimitNode b/c limits cannot be pushed through aggregations rewrittenNode = new LimitNode(idAllocator.getNextId(), rewrittenNode, limit.getCount(), limit.isPartial()); } return rewrittenNode; }
@Override public PlanNode visitUnion(UnionNode node, RewriteContext<LimitContext> context) { LimitContext limit = context.get(); LimitContext childLimit = null; if (limit != null) { childLimit = new LimitContext(limit.getCount(), true); } List<PlanNode> sources = new ArrayList<>(); for (int i = 0; i < node.getSources().size(); i++) { sources.add(context.rewrite(node.getSources().get(i), childLimit)); } PlanNode output = new UnionNode(node.getId(), sources, node.getSymbolMapping(), node.getOutputSymbols()); if (limit != null) { output = new LimitNode(idAllocator.getNextId(), output, limit.getCount(), limit.isPartial()); } return output; }
@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 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); }
@Test public void testLimit() { PlanNode node = new LimitNode(newId(), filter(baseTableScan, and( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), 1, false); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Pass through assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))); }
@Test public void testLimit() { PlanNode node = new LimitNode(newId(), filter(baseTableScan, and( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), 1, false); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Pass through assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts( equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))); }