@Override public int hashCode() { return Objects.hash(sources, ImmutableSet.copyOf(extractConjuncts(filter)), outputSymbols); }
@Override public int hashCode() { return Objects.hash(sources, ImmutableSet.copyOf(extractConjuncts(filter)), outputSymbols); }
@Override public boolean equals(Object obj) { if (!(obj instanceof MultiJoinNode)) { return false; } MultiJoinNode other = (MultiJoinNode) obj; return this.sources.equals(other.sources) && ImmutableSet.copyOf(extractConjuncts(this.filter)).equals(ImmutableSet.copyOf(extractConjuncts(other.filter))) && this.outputSymbols.equals(other.outputSymbols); }
/** * Provides a convenience Iterable of Expression conjuncts which have not been added to the inference */ public static Iterable<Expression> nonInferrableConjuncts(Expression expression) { return filter(extractConjuncts(expression), not(isInferenceCandidate())); }
public static Expression filterConjuncts(Expression expression, Predicate<Expression> predicate) { List<Expression> conjuncts = extractConjuncts(expression).stream() .filter(predicate) .collect(toList()); return combineConjuncts(conjuncts); }
/** * Provides a convenience Iterable of Expression conjuncts which have not been added to the inference */ public static Iterable<Expression> nonInferrableConjuncts(Expression expression) { return filter(extractConjuncts(expression), not(isInferenceCandidate())); }
public static Expression filterConjuncts(Expression expression, Predicate<Expression> predicate) { List<Expression> conjuncts = extractConjuncts(expression).stream() .filter(predicate) .collect(toList()); return combineConjuncts(conjuncts); }
@Override public boolean equals(Object obj) { if (!(obj instanceof MultiJoinNode)) { return false; } MultiJoinNode other = (MultiJoinNode) obj; return this.sources.equals(other.sources) && ImmutableSet.copyOf(extractConjuncts(this.filter)).equals(ImmutableSet.copyOf(extractConjuncts(other.filter))) && this.outputSymbols.equals(other.outputSymbols); }
/** * Returns a subset of conjuncts matching one of the following shapes: * - ST_Contains(...) * - ST_Within(...) * - ST_Intersects(...) * <p> * Doesn't check or guarantee anything about function arguments. */ public static List<FunctionCall> extractSupportedSpatialFunctions(Expression filterExpression) { return extractConjuncts(filterExpression).stream() .filter(FunctionCall.class::isInstance) .map(FunctionCall.class::cast) .filter(SpatialJoinUtils::isSupportedSpatialFunction) .collect(toImmutableList()); }
public static Expression combineConjuncts(Collection<Expression> expressions) { requireNonNull(expressions, "expressions is null"); List<Expression> conjuncts = expressions.stream() .flatMap(e -> ExpressionUtils.extractConjuncts(e).stream()) .filter(e -> !e.equals(TRUE_LITERAL)) .collect(toList()); conjuncts = removeDuplicates(conjuncts); if (conjuncts.contains(FALSE_LITERAL)) { return FALSE_LITERAL; } return and(conjuncts); }
public static Expression combineConjuncts(Collection<Expression> expressions) { requireNonNull(expressions, "expressions is null"); List<Expression> conjuncts = expressions.stream() .flatMap(e -> ExpressionUtils.extractConjuncts(e).stream()) .filter(e -> !e.equals(TRUE_LITERAL)) .collect(toList()); conjuncts = removeDuplicates(conjuncts); if (conjuncts.contains(FALSE_LITERAL)) { return FALSE_LITERAL; } return and(conjuncts); }
public Builder extractInferenceCandidates(Expression expression) { return addAllEqualities(filter(extractConjuncts(expression), isInferenceCandidate())); }
private boolean canConvertOuterToInner(List<Symbol> innerSymbolsForOuterJoin, Expression inheritedPredicate) { Set<Symbol> innerSymbols = ImmutableSet.copyOf(innerSymbolsForOuterJoin); for (Expression conjunct : extractConjuncts(inheritedPredicate)) { if (DeterminismEvaluator.isDeterministic(conjunct)) { // Ignore a conjunct for this test if we can not deterministically get responses from it Object response = nullInputEvaluator(innerSymbols, conjunct); if (response == null || response instanceof NullLiteral || Boolean.FALSE.equals(response)) { // If there is a single conjunct that returns FALSE or NULL given all NULL inputs for the inner side symbols of an outer join // then this conjunct removes all effects of the outer join, and effectively turns this into an equivalent of an inner join. // So, let's just rewrite this join as an INNER join return true; } } } return false; }
public Builder extractInferenceCandidates(Expression expression) { return addAllEqualities(filter(extractConjuncts(expression), isInferenceCandidate())); }
@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; }
@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 void assertGetSortExpression(Expression expression, String expectedSymbol) { // for now we expect that search expressions contain all the conjuncts from filterExpression as more complex cases are not supported yet. assertGetSortExpression(expression, expectedSymbol, extractConjuncts(expression)); }
private void assertGetSortExpression(Expression expression, String expectedSymbol) { // for now we expect that search expressions contain all the conjuncts from filterExpression as more complex cases are not supported yet. assertGetSortExpression(expression, expectedSymbol, extractConjuncts(expression)); }
@Override public PlanNode visitSemiJoin(SemiJoinNode node, RewriteContext<Expression> context) { Expression inheritedPredicate = context.get(); if (!extractConjuncts(inheritedPredicate).contains(node.getSemiJoinOutput().toSymbolReference())) { return visitNonFilteringSemiJoin(node, context); } return visitFilteringSemiJoin(node, context); }
@Override public PlanNode visitSemiJoin(SemiJoinNode node, RewriteContext<Expression> context) { Expression inheritedPredicate = context.get(); if (!extractConjuncts(inheritedPredicate).contains(node.getSemiJoinOutput().toSymbolReference())) { return visitNonFilteringSemiJoin(node, context); } return visitFilteringSemiJoin(node, context); }