public static List<Expression> extractPredicates(LogicalBinaryExpression.Operator operator, Expression expression) { if (expression instanceof LogicalBinaryExpression && ((LogicalBinaryExpression) expression).getOperator() == operator) { LogicalBinaryExpression logicalBinaryExpression = (LogicalBinaryExpression) expression; return ImmutableList.<Expression>builder() .addAll(extractPredicates(operator, logicalBinaryExpression.getLeft())) .addAll(extractPredicates(operator, logicalBinaryExpression.getRight())) .build(); } return ImmutableList.of(expression); }
@Override protected PlanNodeStatsEstimate visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { switch (node.getOperator()) { case AND: return estimateLogicalAnd(node.getLeft(), node.getRight()); case OR: return estimateLogicalOr(node.getLeft(), node.getRight()); default: throw new IllegalArgumentException("Unexpected binary operator: " + node.getOperator()); } }
@Override protected Boolean visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { return process(node.getLeft(), context) && process(node.getRight(), context); }
@Override protected R visitLogicalBinaryExpression(LogicalBinaryExpression node, C context) { process(node.getLeft(), context); process(node.getRight(), context); return null; }
@Override protected Type visitLogicalBinaryExpression(LogicalBinaryExpression node, StackableAstVisitorContext<Context> context) { coerceType(context, node.getLeft(), BOOLEAN, "Left side of logical expression"); coerceType(context, node.getRight(), BOOLEAN, "Right side of logical expression"); return setExpressionType(node, BOOLEAN); }
@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { return formatBinaryExpression(node.getOperator().toString(), node.getLeft(), node.getRight()); }
@Override protected RowExpression visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { return call( logicalExpressionSignature(node.getOperator()), BOOLEAN, process(node.getLeft(), context), process(node.getRight(), context)); }
@Override protected Boolean visitLogicalBinaryExpression(LogicalBinaryExpression actual, Node expectedExpression) { if (expectedExpression instanceof LogicalBinaryExpression) { LogicalBinaryExpression expected = (LogicalBinaryExpression) expectedExpression; if (actual.getOperator() == expected.getOperator()) { return process(actual.getLeft(), expected.getLeft()) && process(actual.getRight(), expected.getRight()); } } return false; }
@Override protected ExtractionResult visitLogicalBinaryExpression(LogicalBinaryExpression node, Boolean complement) ExtractionResult leftResult = process(node.getLeft(), complement); ExtractionResult rightResult = process(node.getRight(), complement);
@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(); } }
@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.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 R visitLogicalBinaryExpression(LogicalBinaryExpression node, C context) { process(node.getLeft(), context); process(node.getRight(), context); return null; }
@Override protected Boolean visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { return process(node.getLeft(), context) && process(node.getRight(), context); }
@Override protected R visitLogicalBinaryExpression(LogicalBinaryExpression node, C context) { process(node.getLeft(), context); process(node.getRight(), context); return null; }
@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context) { return formatBinaryExpression(node.getOperator().toString(), node.getLeft(), node.getRight()); }
@Override protected String visitLogicalBinaryExpression(LogicalBinaryExpression node, Boolean unmangleNames) { return formatBinaryExpression(node.getType().toString(), node.getLeft(), node.getRight(), unmangleNames); }