expression.getOperator().flip(), crossProduct.stream() .map(expressions -> combinePredicates(expression.getOperator(), expressions))
@Override protected Void visitLogicalBinaryExpression(LogicalBinaryExpression node, Integer indentLevel) { print(indentLevel, node.getOperator().toString()); super.visitLogicalBinaryExpression(node, indentLevel + 1); return null; }
@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { return formatBinaryExpression(node.getOperator().toString(), node.getLeft(), node.getRight()); }
TupleDomain<Symbol> rightTupleDomain = rightResult.getTupleDomain(); LogicalBinaryExpression.Operator operator = complement ? node.getOperator().flip() : node.getOperator(); switch (operator) { case AND:
private static Expression extractCommonPredicates(LogicalBinaryExpression node) { List<List<Expression>> subPredicates = getSubPredicates(node); Set<Expression> commonPredicates = ImmutableSet.copyOf(subPredicates.stream() .map(Visitor::filterDeterministicPredicates) .reduce(Sets::intersection) .orElse(emptySet())); List<List<Expression>> uncorrelatedSubPredicates = subPredicates.stream() .map(predicateList -> removeAll(predicateList, commonPredicates)) .collect(toImmutableList()); LogicalBinaryExpression.Operator flippedOperator = node.getOperator().flip(); List<Expression> uncorrelatedPredicates = uncorrelatedSubPredicates.stream() .map(predicate -> combinePredicates(flippedOperator, predicate)) .collect(toImmutableList()); Expression combinedUncorrelatedPredicates = combinePredicates(node.getOperator(), uncorrelatedPredicates); return combinePredicates(flippedOperator, ImmutableList.<Expression>builder() .addAll(commonPredicates) .add(combinedUncorrelatedPredicates) .build()); }
@Override public Expression rewriteNotExpression(NotExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { if (node.getValue() instanceof LogicalBinaryExpression) { LogicalBinaryExpression child = (LogicalBinaryExpression) node.getValue(); List<Expression> predicates = extractPredicates(child); List<Expression> negatedPredicates = predicates.stream().map(predicate -> treeRewriter.rewrite((Expression) new NotExpression(predicate), context)).collect(toImmutableList()); return combinePredicates(child.getOperator().flip(), negatedPredicates); } else if (node.getValue() instanceof ComparisonExpression && ((ComparisonExpression) node.getValue()).getOperator() != IS_DISTINCT_FROM) { ComparisonExpression child = (ComparisonExpression) node.getValue(); return new ComparisonExpression(child.getOperator().negate(), treeRewriter.rewrite(child.getLeft(), context), treeRewriter.rewrite(child.getRight(), context)); } else if (node.getValue() instanceof NotExpression) { NotExpression child = (NotExpression) node.getValue(); return treeRewriter.rewrite(child.getValue(), context); } return new NotExpression(treeRewriter.rewrite(node.getValue(), context)); } }
public static Signature logicalExpressionSignature(LogicalBinaryExpression.Operator operator) { return internalScalarFunction(operator.name(), parseTypeSignature(StandardTypes.BOOLEAN), parseTypeSignature(StandardTypes.BOOLEAN), parseTypeSignature(StandardTypes.BOOLEAN)); }
@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { return formatBinaryExpression(node.getOperator().toString(), node.getLeft(), node.getRight()); }
@Override protected Void visitLogicalBinaryExpression(LogicalBinaryExpression node, Integer indentLevel) { print(indentLevel, node.getOperator().toString()); super.visitLogicalBinaryExpression(node, indentLevel + 1); return null; }