public <S> S capture(Capture<S> capture) { return captures().get(capture); }
@SuppressWarnings("unchecked cast") public <T> T get(Capture<T> capture) { if (this.equals(NIL)) { throw new NoSuchElementException("Requested value for unknown Capture. Was it registered in the Pattern?"); } else if (this.capture.equals(capture)) { return (T) value; } else { return tail.get(capture); } }
@Override public Result apply(ExchangeNode exchange, Captures captures, Context context) { AggregationNode aggregation = captures.get(AGGREGATION); GroupIdNode groupId = captures.get(GROUP_ID); return transform(aggregation, groupId, context) .map(newAggregation -> { PlanNode newExchange = exchange.replaceChildren(ImmutableList.of(newAggregation)); return Result.ofPlanNode(newExchange); }) .orElseGet(Result::empty); } }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { return Result.ofPlanNode(transpose(parent, captures.get(CHILD))); } }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { return Result.ofPlanNode(transpose(parent, captures.get(CHILD))); } }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { return Result.ofPlanNode(transpose(parent, captures.get(CHILD))); } }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { return Result.ofPlanNode(transpose(parent, captures.get(CHILD))); } }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { return Result.ofPlanNode(transpose(parent, captures.get(CHILD))); } }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { return Result.ofPlanNode(transpose(parent, captures.get(CHILD))); } }
@Override public Result apply(ProjectNode parent, Captures captures, Context context) { N targetNode = captures.get(targetCapture); return pruneInputs(targetNode.getOutputSymbols(), parent.getAssignments().getExpressions()) .flatMap(prunedOutputs -> this.pushDownProjectOff(context.getIdAllocator(), targetNode, prunedOutputs)) .map(newChild -> parent.replaceChildren(ImmutableList.of(newChild))) .map(Result::ofPlanNode) .orElse(Result.empty()); }
@Override public Result apply(ProjectNode parent, Captures captures, Context context) { N targetNode = captures.get(targetCapture); return pruneInputs(targetNode.getOutputSymbols(), parent.getAssignments().getExpressions()) .flatMap(prunedOutputs -> this.pushDownProjectOff(context.getIdAllocator(), targetNode, prunedOutputs)) .map(newChild -> parent.replaceChildren(ImmutableList.of(newChild))) .map(Result::ofPlanNode) .orElse(Result.empty()); }
@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 Result apply(LimitNode parent, Captures captures, Context context) { TopNNode child = captures.get(CHILD); return Result.ofPlanNode( new TopNNode( parent.getId(), child.getSource(), Math.min(parent.getCount(), child.getCount()), child.getOrderingScheme(), parent.isPartial() ? TopNNode.Step.PARTIAL : TopNNode.Step.SINGLE)); } }
@Override public Result apply(LimitNode parent, Captures captures, Context context) { TopNNode child = captures.get(CHILD); return Result.ofPlanNode( new TopNNode( parent.getId(), child.getSource(), Math.min(parent.getCount(), child.getCount()), child.getOrderingScheme(), parent.isPartial() ? TopNNode.Step.PARTIAL : TopNNode.Step.SINGLE)); } }
@Override public Result apply(FilterNode parent, Captures captures, Context context) { FilterNode child = captures.get(CHILD); return Result.ofPlanNode( new FilterNode( parent.getId(), child.getSource(), combineConjuncts(child.getPredicate(), parent.getPredicate()))); } }
@Override public Result apply(FilterNode parent, Captures captures, Context context) { FilterNode child = captures.get(CHILD); return Result.ofPlanNode( new FilterNode( parent.getId(), child.getSource(), combineConjuncts(child.getPredicate(), parent.getPredicate()))); } }
@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 Result apply(FilterNode filterNode, Captures captures, Context context) { TableScanNode tableScan = captures.get(TABLE_SCAN); PlanNode rewritten = planTableScan(tableScan, filterNode.getPredicate(), context.getSession(), context.getSymbolAllocator().getTypes(), context.getIdAllocator(), metadata, parser, domainTranslator); if (arePlansSame(filterNode, tableScan, rewritten)) { return Result.empty(); } return Result.ofPlanNode(rewritten); }
@Override public Result apply(FilterNode filterNode, Captures captures, Context context) { TableScanNode tableScan = captures.get(TABLE_SCAN); PlanNode rewritten = planTableScan(tableScan, filterNode.getPredicate(), context.getSession(), context.getSymbolAllocator().getTypes(), context.getIdAllocator(), metadata, parser, domainTranslator); if (arePlansSame(filterNode, tableScan, rewritten)) { return Result.empty(); } return Result.ofPlanNode(rewritten); }