@Override protected String visitNotExpression(NotExpression node, Void context) { return "(NOT " + process(node.getValue(), context) + ")"; }
private static Expression not(Expression booleanExpression) { return new NotExpression(booleanExpression); }
@Override protected Object visitNotExpression(NotExpression node, Object context) { Object value = process(node.getValue(), context); if (value == null) { return null; } if (value instanceof Expression) { return new NotExpression(toExpression(value, type(node.getValue()))); } return !(Boolean) value; }
@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)); } }
private static Expression complementIfNecessary(Expression expression, boolean complement) { return complement ? new NotExpression(expression) : expression; }
@Override protected ExtractionResult visitNotExpression(NotExpression node, Boolean complement) { return process(node.getValue(), !complement); }
@Override protected Object visitNotExpression(NotExpression node, Object context) { Object value = process(node.getValue(), context); if (value == null) { return null; } if (value instanceof Expression) { return new NotExpression(toExpression(value, expressionTypes.get(node.getValue()))); } return !(Boolean) value; }
private static NotExpression not(Expression expression) { return new NotExpression(expression); }
@Override protected R visitNotExpression(NotExpression node, C context) { return process(node.getValue(), 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)); } }
private List<Expression> extractDisjuncts(Type type, DiscreteValues discreteValues, SymbolReference reference) { List<Expression> values = discreteValues.getValues().stream() .map(object -> literalEncoder.toExpression(object, type)) .collect(toList()); // If values is empty, then the equatableValues was either ALL or NONE, both of which should already have been checked for checkState(!values.isEmpty()); Expression predicate; if (values.size() == 1) { predicate = new ComparisonExpression(EQUAL, reference, getOnlyElement(values)); } else { predicate = new InPredicate(reference, new InListExpression(values)); } if (!discreteValues.isWhiteList()) { predicate = new NotExpression(predicate); } return ImmutableList.of(predicate); }
@Override protected Boolean visitNotExpression(NotExpression node, Void context) { return process(node.getValue(), context); }
@Override public Node visitLogicalNot(SqlBaseParser.LogicalNotContext context) { return new NotExpression(getLocation(context), (Expression) visit(context.booleanExpression())); }
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; }
@Override public Expression rewriteIsNotNullPredicate(IsNotNullPredicate node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Expression value = treeRewriter.rewrite(node.getValue(), context); return new NotExpression(new IsNullPredicate(value)); }
private Expression combineRangeWithExcludedPoints(Type type, SymbolReference reference, Range range, List<Expression> excludedPoints) { if (excludedPoints.isEmpty()) { return processRange(type, range, reference); } Expression excludedPointsExpression = new NotExpression(new InPredicate(reference, new InListExpression(excludedPoints))); if (excludedPoints.size() == 1) { excludedPointsExpression = new ComparisonExpression(NOT_EQUAL, reference, getOnlyElement(excludedPoints)); } return combineConjuncts(processRange(type, range, reference), excludedPointsExpression); }
@Override protected Type visitNotExpression(NotExpression node, StackableAstVisitorContext<Context> context) { coerceType(context, node.getValue(), BOOLEAN, "Value of logical NOT expression"); return setExpressionType(node, BOOLEAN); }
private static Expression isNotNull(Expression expression) { return new NotExpression(new IsNullPredicate(expression)); }