private static boolean isJoinEqualityCondition(Expression expression) { return expression instanceof ComparisonExpression && ((ComparisonExpression) expression).getOperator() == EQUAL && ((ComparisonExpression) expression).getLeft() instanceof SymbolReference && ((ComparisonExpression) expression).getRight() instanceof SymbolReference; }
public static Expression normalize(Expression expression) { if (expression instanceof NotExpression) { NotExpression not = (NotExpression) expression; if (not.getValue() instanceof ComparisonExpression && ((ComparisonExpression) not.getValue()).getOperator() != IS_DISTINCT_FROM) { ComparisonExpression comparison = (ComparisonExpression) not.getValue(); return new ComparisonExpression(comparison.getOperator().negate(), comparison.getLeft(), comparison.getRight()); } if (not.getValue() instanceof NotExpression) { return normalize(((NotExpression) not.getValue()).getValue()); } } return expression; }
public static Expression normalize(Expression expression) { if (expression instanceof NotExpression) { NotExpression not = (NotExpression) expression; if (not.getValue() instanceof ComparisonExpression && ((ComparisonExpression) not.getValue()).getType() != IS_DISTINCT_FROM) { ComparisonExpression comparison = (ComparisonExpression) not.getValue(); return new ComparisonExpression(comparison.getType().negate(), comparison.getLeft(), comparison.getRight()); } if (not.getValue() instanceof NotExpression) { return normalize(((NotExpression) not.getValue()).getValue()); } } return expression; } }
public static Expression equal(Expression left, Expression right) { return new ComparisonExpression(ComparisonExpression.Operator.EQUAL, left, right); }
newJoinPredicate = new ComparisonExpression(ComparisonExpression.Operator.EQUAL, new LongLiteral("0"), new LongLiteral("1")); ComparisonExpression equality = (ComparisonExpression) conjunct; boolean alignedComparison = Iterables.all(SymbolsExtractor.extractUnique(equality.getLeft()), in(node.getLeft().getOutputSymbols())); Expression leftExpression = (alignedComparison) ? equality.getLeft() : equality.getRight(); Expression rightExpression = (alignedComparison) ? equality.getRight() : equality.getLeft();
private boolean isEqualComparisonExpression(Expression conjunct) { return conjunct instanceof ComparisonExpression && ((ComparisonExpression) conjunct).getType() == ComparisonExpression.Type.EQUAL; }
private static boolean isEqualComparisonExpression(Expression conjunct) { return conjunct instanceof ComparisonExpression && ((ComparisonExpression) conjunct).getOperator() == ComparisonExpression.Operator.EQUAL; }
@Override protected Object visitComparisonExpression(ComparisonExpression node, Object context) { ComparisonExpression.Type type = node.getType(); Object left = process(node.getLeft(), context); if (left == null && type != ComparisonExpression.Type.IS_DISTINCT_FROM) { return null; } Object right = process(node.getRight(), context); if (type == ComparisonExpression.Type.IS_DISTINCT_FROM) { if (left == null && right == null) { return false; } else if (left == null || right == null) { return true; } } else if (right == null) { return null; } if (hasUnresolvedValue(left, right)) { return new ComparisonExpression(type, toExpression(left, expressionTypes.get(node.getLeft())), toExpression(right, expressionTypes.get(node.getRight()))); } if (type == ComparisonExpression.Type.IS_DISTINCT_FROM) { type = ComparisonExpression.Type.NOT_EQUAL; } return invokeOperator(OperatorType.valueOf(type.name()), types(node.getLeft(), node.getRight()), ImmutableList.of(left, right)); }
public Builder addEquality(Expression expression) { expression = normalizeInPredicateToEquality(expression); checkArgument(isInferenceCandidate().apply(expression), "Expression must be a simple equality: " + expression); ComparisonExpression comparison = (ComparisonExpression) expression; addEquality(comparison.getLeft(), comparison.getRight()); return this; }
private static ComparisonExpression lessThanOrEqual(Expression expression1, Expression expression2) { return new ComparisonExpression(ComparisonExpression.Operator.LESS_THAN_OR_EQUAL, expression1, expression2); }
newJoinPredicate = new ComparisonExpression(ComparisonExpression.Type.EQUAL, new LongLiteral("0"), new LongLiteral("1")); boolean alignedComparison = Iterables.all(DependencyExtractor.extractUnique(equality.getLeft()), in(node.getLeft().getOutputSymbols())); Expression leftExpression = (alignedComparison) ? equality.getLeft() : equality.getRight(); Expression rightExpression = (alignedComparison) ? equality.getRight() : equality.getLeft();
@Override protected Void visitComparisonExpression(ComparisonExpression node, Integer indentLevel) { print(indentLevel, node.getType().toString()); super.visitComparisonExpression(node, indentLevel + 1); return null; }
@Override protected Void visitComparisonExpression(ComparisonExpression node, Integer indentLevel) { print(indentLevel, node.getOperator().toString()); super.visitComparisonExpression(node, indentLevel + 1); return null; }
@Override protected String visitComparisonExpression(ComparisonExpression node, Boolean negate) { String left = process(node.getLeft(), negate); String right = process(node.getRight(), negate); String predicate = node.getType().getValue() + " " + right; if (negate) { predicate = String.format("not(%s)", predicate); } return "SELECT date, dimension, _user_set FROM " + left + " WHERE dimension " + predicate; }
@Override protected String visitComparisonExpression(ComparisonExpression node, Void context) { return formatBinaryExpression(node.getOperator().getValue(), node.getLeft(), node.getRight()); }
@Override protected Object visitComparisonExpression(ComparisonExpression node, Object context) { ComparisonExpression.Operator operator = node.getOperator(); Object left = process(node.getLeft(), context); if (left == null && operator != ComparisonExpression.Operator.IS_DISTINCT_FROM) { return null; } Object right = process(node.getRight(), context); if (operator == ComparisonExpression.Operator.IS_DISTINCT_FROM) { if (left == null && right == null) { return false; } else if (left == null || right == null) { return true; } } else if (right == null) { return null; } if (hasUnresolvedValue(left, right)) { return new ComparisonExpression(operator, toExpression(left, type(node.getLeft())), toExpression(right, type(node.getRight()))); } return invokeOperator(OperatorType.valueOf(operator.name()), types(node.getLeft(), node.getRight()), ImmutableList.of(left, right)); }
@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)); } }