@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { return formatBinaryExpression(node.getType().toString(), node.getLeft(), node.getRight()); }
public String visitLogicalBinaryExpression(LogicalBinaryExpression node, Boolean context) { return formatBinaryExpression(getLogicalContext(node.getType()), node.getLeft(), node.getRight(), context); }
@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Boolean context) { return '(' + process(node.getLeft(), context) + ' ' + node.getType().name() + ' ' + process(node.getRight(), context) + ')'; }
public static List<Expression> extractPredicates(LogicalBinaryExpression expression) { return extractPredicates(expression.getType(), expression); }
@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Boolean negate) { LogicalBinaryExpression.Type type = node.getType(); if (type == AND) { // TODO find a better way // Optimization for the case when one hand or binary expression is IS NOT NULL predicate if (node.getRight() instanceof IsNotNullPredicate && !(node.getLeft() instanceof IsNotNullPredicate) || node.getLeft() instanceof IsNotNullPredicate && !(node.getRight() instanceof IsNotNullPredicate)) { Expression isNotNull = node.getRight() instanceof IsNotNullPredicate ? node.getRight() : node.getLeft(); Expression setExpression = isNotNull == node.getRight() ? node.getLeft() : node.getRight(); String excludeQuery = process(new IsNullPredicate(((IsNotNullPredicate) isNotNull).getValue()), negate); return "SELECT l.date, l.dimension, l._user_set FROM (" + process(setExpression, negate) + ") l LEFT JOIN (" + excludeQuery + ") r ON (r.date = l.date AND l.dimension = r.dimension) WHERE r.date IS NULL"; } String right = process(node.getRight(), negate); String left = process(node.getLeft(), negate); // TODO: use INTERSECT when it's implemented in Presto. return "SELECT l.date, l.dimension, l._user_set FROM (" + left + ") l JOIN (" + right + ") r ON (r.date = l.date)"; } else if (type == OR) { return "SELECT date, dimension, _user_set FROM (" + process(node.getLeft(), negate) + " UNION ALL " + process(node.getRight(), negate) + ")"; } else { throw new IllegalStateException(); } }
public static List<Expression> extractPredicates(LogicalBinaryExpression.Type type, Expression expression) { if (expression instanceof LogicalBinaryExpression && ((LogicalBinaryExpression) expression).getType() == type) { LogicalBinaryExpression logicalBinaryExpression = (LogicalBinaryExpression) expression; return ImmutableList.<Expression>builder() .addAll(extractPredicates(type, logicalBinaryExpression.getLeft())) .addAll(extractPredicates(type, logicalBinaryExpression.getRight())) .build(); } return ImmutableList.of(expression); }
@Override protected Void visitLogicalBinaryExpression(LogicalBinaryExpression node, Integer indentLevel) { print(indentLevel, node.getType().toString()); super.visitLogicalBinaryExpression(node, indentLevel + 1); return null; }
@Override public Expression rewriteLogicalBinaryExpression(LogicalBinaryExpression node, NodeContext context, ExpressionTreeRewriter<NodeContext> treeRewriter) { List<Expression> predicates = extractPredicates(node.getType(), node).stream() .map(expression -> treeRewriter.rewrite(expression, NodeContext.NOT_ROOT_NODE)) .collect(toImmutableList()); List<List<Expression>> subPredicates = getSubPredicates(predicates); Set<Expression> commonPredicates = ImmutableSet.copyOf(subPredicates.stream() .map(this::filterDeterministicPredicates) .reduce(Sets::intersection) .orElse(emptySet())); List<List<Expression>> uncorrelatedSubPredicates = subPredicates.stream() .map(predicateList -> removeAll(predicateList, commonPredicates)) .collect(toImmutableList()); LogicalBinaryExpression.Type flippedNodeType = node.getType().flip(); List<Expression> uncorrelatedPredicates = uncorrelatedSubPredicates.stream() .map(predicate -> combinePredicates(flippedNodeType, predicate)) .collect(toImmutableList()); Expression combinedUncorrelatedPredicates = combinePredicates(node.getType(), uncorrelatedPredicates); // Do not simplify top level conjuncts if it would result in top level disjuncts // Conjuncts are easier to process when pushing down predicates. if (context.isRootNode() && flippedNodeType == OR && !combinedUncorrelatedPredicates.equals(FALSE_LITERAL)) { return combinePredicates(node.getType(), predicates); } return combinePredicates(flippedNodeType, ImmutableList.<Expression>builder() .addAll(commonPredicates) .add(combinedUncorrelatedPredicates) .build()); }
/** * Applies to any logical binary expression between clauses like, AND * and OR. In this case this will only take place in the WHERE clause. */ @Override public Void visitLogicalBinaryExpression( LogicalBinaryExpression node, Boolean capture) { process(node.getLeft(), true); switch (node.getType()) { case AND: translation.append(" and "); break; case OR: translation.append(" or "); break; } process(node.getRight(), true); return null; }
@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Boolean unmangleNames) { return formatBinaryExpression(node.getType().toString(), node.getLeft(), node.getRight(), unmangleNames); }
@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Boolean unmangleNames) { return formatBinaryExpression(node.getType().toString(), node.getLeft(), node.getRight(), unmangleNames); }
@Override public Expression rewriteLogicalBinaryExpression(LogicalBinaryExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { List<Expression> predicates = extractPredicates(node.getType(), node).stream() .map(p -> treeRewriter.rewrite(p, context)) .sorted((p1, p2) -> p1.toString().compareTo(p2.toString())) .collect(toList()); return binaryExpression(node.getType(), predicates); } }
@Override protected RowExpression visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { return call( logicalExpressionSignature(node.getType()), BOOLEAN, process(node.getLeft(), context), process(node.getRight(), context)); }
@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.getType().flip(), negatedPredicates); } else if (node.getValue() instanceof ComparisonExpression && ((ComparisonExpression) node.getValue()).getType() != IS_DISTINCT_FROM) { ComparisonExpression child = (ComparisonExpression) node.getValue(); return new ComparisonExpression( child.getType().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)); } }
QueryBuilder rq = rqWrap.getQuery(); if(lqWrap.getNestField() != null && lqWrap.getNestField().equals(rqWrap.getNestField())){ if(boolExp.getType() == LogicalBinaryExpression.Type.AND){ bqb.must(lq); bqb.must(rq); }else if(boolExp.getType() == LogicalBinaryExpression.Type.OR){ bqb.should(lq); bqb.should(rq); if(boolExp.getType() == LogicalBinaryExpression.Type.AND){ if(lqWrap.getNestField() != null) bqb.must(QueryBuilders.nestedQuery(lqWrap.getNestField(), lq, ScoreMode.None)); else bqb.must(lq); }else if(boolExp.getType() == LogicalBinaryExpression.Type.OR){ if(lqWrap.getNestField() != null) bqb.should(QueryBuilders.nestedQuery(lqWrap.getNestField(), lq, ScoreMode.None)); else bqb.should(lq);
IComparison left = process(boolExp.getLeft(), state); IComparison right = process(boolExp.getRight(), state); return new BooleanComparison(left, right, boolExp.getType() == LogicalBinaryExpression.Type.AND); }else if( node instanceof ComparisonExpression){ ComparisonExpression compareExp = (ComparisonExpression)node;