@Override public PlanNode visitFilter(FilterNode node, RewriteContext<Void> context) { PlanNode source = context.rewrite(node.getSource()); return new FilterNode(node.getId(), source, canonicalize(node.getPredicate())); }
@Override public Void visitFilter(FilterNode 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()); Set<Symbol> dependencies = SymbolsExtractor.extractUnique(node.getPredicate()); checkDependencies(inputs, dependencies, "Invalid node. Predicate dependencies (%s) not in source plan output (%s)", dependencies, node.getSource().getOutputSymbols()); return null; }
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new FilterNode(getId(), Iterables.getOnlyElement(newChildren), predicate); } }
@Deprecated @Override public PlanNode visitFilter(FilterNode node, RewriteContext<Expression> context) { PlanNode rewrittenPlan = context.rewrite(node.getSource(), combineConjuncts(node.getPredicate(), context.get())); if (!(rewrittenPlan instanceof FilterNode)) { return rewrittenPlan; } FilterNode rewrittenFilterNode = (FilterNode) rewrittenPlan; if (!areExpressionsEquivalent(rewrittenFilterNode.getPredicate(), node.getPredicate()) || node.getSource() != rewrittenFilterNode.getSource()) { return rewrittenPlan; } return node; }
@Override public PlanNode visitMarkDistinct(MarkDistinctNode node, RewriteContext<Expression> context) { Set<Symbol> pushDownableSymbols = ImmutableSet.copyOf(node.getDistinctSymbols()); Map<Boolean, List<Expression>> conjuncts = extractConjuncts(context.get()).stream() .collect(Collectors.partitioningBy(conjunct -> SymbolsExtractor.extractUnique(conjunct).stream().allMatch(pushDownableSymbols::contains))); PlanNode rewrittenNode = context.defaultRewrite(node, combineConjuncts(conjuncts.get(true))); if (!conjuncts.get(false).isEmpty()) { rewrittenNode = new FilterNode(idAllocator.getNextId(), rewrittenNode, combineConjuncts(conjuncts.get(false))); } return rewrittenNode; }
private PlanNode rewriteFilterSource(FilterNode filterNode, PlanNode source, Symbol rowNumberSymbol, int upperBound) { ExtractionResult extractionResult = fromPredicate(metadata, session, filterNode.getPredicate(), types); TupleDomain<Symbol> tupleDomain = extractionResult.getTupleDomain(); if (!isEqualRange(tupleDomain, rowNumberSymbol, upperBound)) { return new FilterNode(filterNode.getId(), source, filterNode.getPredicate()); } // Remove the row number domain because it is absorbed into the node Map<Symbol, Domain> newDomains = tupleDomain.getDomains().get().entrySet().stream() .filter(entry -> !entry.getKey().equals(rowNumberSymbol)) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); // Construct a new predicate TupleDomain<Symbol> newTupleDomain = TupleDomain.withColumnDomains(newDomains); Expression newPredicate = ExpressionUtils.combineConjuncts( extractionResult.getRemainingExpression(), domainTranslator.toPredicate(newTupleDomain)); if (newPredicate.equals(BooleanLiteral.TRUE_LITERAL)) { return source; } return new FilterNode(filterNode.getId(), source, newPredicate); }
@Override public PlanNode visitFilter(FilterNode node, RewriteContext<Void> context) { FilterNode rewrittenNode = (FilterNode) context.defaultRewrite(node); return new FilterNode(idAllocator.getNextId(), rewrittenNode.getSource(), replaceExpression(rewrittenNode.getPredicate(), mapping)); }
@Override public Result apply(FilterNode node, Captures captures, Context context) { JoinNode joinNode = captures.get(JOIN); Expression filter = node.getPredicate(); List<FunctionCall> spatialFunctions = extractSupportedSpatialFunctions(filter); for (FunctionCall spatialFunction : spatialFunctions) { Result result = tryCreateSpatialJoin(context, joinNode, filter, node.getId(), node.getOutputSymbols(), spatialFunction, Optional.empty(), metadata, splitManager, pageSourceManager, sqlParser); if (!result.isEmpty()) { return result; } } List<ComparisonExpression> spatialComparisons = extractSupportedSpatialComparisons(filter); for (ComparisonExpression spatialComparison : spatialComparisons) { Result result = tryCreateSpatialJoin(context, joinNode, filter, node.getId(), node.getOutputSymbols(), spatialComparison, metadata, splitManager, pageSourceManager, sqlParser); if (!result.isEmpty()) { return result; } } return Result.empty(); } }
@Override public Void visitFilter(FilterNode node, ImmutableList.Builder<Expression> context) { context.add(node.getPredicate()); return super.visitFilter(node, context); }
private static Expression simplifyExpressions(Expression expression) { PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator(); FilterNode filterNode = new FilterNode( planNodeIdAllocator.getNextId(), new ValuesNode(planNodeIdAllocator.getNextId(), emptyList(), emptyList()), expression); FilterNode simplifiedNode = (FilterNode) SIMPLIFIER.optimize( filterNode, TEST_SESSION, booleanSymbolTypeMapFor(expression), new SymbolAllocator(), planNodeIdAllocator); return simplifiedNode.getPredicate(); }
@Override public Void visitFilter(FilterNode node, Integer indent) { print(indent, "- Filter[%s] => [%s]", node.getPredicate(), formatOutputs(node.getOutputSymbols())); return processChildren(node, indent + 1); }
criteria, ImmutableList.<Symbol>builder() .addAll(left.getOutputSymbols()) .addAll(right.getOutputSymbols()) .build(), Optional.empty(),
@Override public Map<Symbol, Symbol> visitFilter(FilterNode node, Set<Symbol> lookupSymbols) { return node.getSource().accept(this, lookupSymbols); }
@Override public PlanNodeCostEstimate visitFilter(FilterNode node, Void context) { return cpuCost(getStats(node.getSource()).getOutputSizeInBytes(node.getOutputSymbols(), types)); }
@Override public Void visitFilter(FilterNode node, Integer indent) { return visitScanFilterAndProjectInfo(node.getId(), Optional.of(node), Optional.empty(), indent); }
@Override public JoinGraph visitFilter(FilterNode node, Context context) { JoinGraph graph = node.getSource().accept(this, context); return graph.withFilter(node.getPredicate()); }
@Override public PlanNode visitGroupId(GroupIdNode node, RewriteContext<Expression> context) { Map<Symbol, SymbolReference> commonGroupingSymbolMapping = node.getGroupingColumns().entrySet().stream() .filter(entry -> node.getCommonGroupingColumns().contains(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().toSymbolReference())); Predicate<Expression> pushdownEligiblePredicate = conjunct -> SymbolsExtractor.extractUnique(conjunct).stream() .allMatch(commonGroupingSymbolMapping.keySet()::contains); Map<Boolean, List<Expression>> conjuncts = extractConjuncts(context.get()).stream().collect(Collectors.partitioningBy(pushdownEligiblePredicate)); // Push down conjuncts from the inherited predicate that apply to common grouping symbols PlanNode rewrittenNode = context.defaultRewrite(node, inlineSymbols(commonGroupingSymbolMapping, combineConjuncts(conjuncts.get(true)))); // All other conjuncts, if any, will be in the filter node. if (!conjuncts.get(false).isEmpty()) { rewrittenNode = new FilterNode(idAllocator.getNextId(), rewrittenNode, combineConjuncts(conjuncts.get(false))); } return rewrittenNode; }
@Override public PlanNode visitFilter(FilterNode node, List<PlanNode> newChildren) { return new FilterNode(node.getId(), Iterables.getOnlyElement(newChildren), node.getPredicate()); }
node.getSource(), ImmutableSet.of(), ImmutableList.of(), if (containsCorrelation(node.getSource(), correlation)) { childDecorrelationResultOptional = lookup.resolve(node.getSource()).accept(this, null); Expression predicate = node.getPredicate(); Map<Boolean, List<Expression>> predicates = ExpressionUtils.extractConjuncts(predicate).stream() .collect(Collectors.partitioningBy(PlanNodeDecorrelator.DecorrelatingVisitor.this::isCorrelated)); FilterNode newFilterNode = new FilterNode( idAllocator.getNextId(), childDecorrelationResult.node,
@Override protected Optional<PlanNode> pushDownProjectOff(PlanNodeIdAllocator idAllocator, FilterNode filterNode, Set<Symbol> referencedOutputs) { Set<Symbol> prunedFilterInputs = Streams.concat( referencedOutputs.stream(), SymbolsExtractor.extractUnique(filterNode.getPredicate()).stream()) .collect(toImmutableSet()); return restrictChildOutputs(idAllocator, filterNode, prunedFilterInputs); } }