private static Expression complementIfNecessary(Expression expression, boolean complement) { return complement ? new NotExpression(expression) : expression; }
private static NotExpression not(Expression expression) { return new NotExpression(expression); }
@Override public Node visitLogicalNot(SqlBaseParser.LogicalNotContext context) { return new NotExpression(getLocation(context), (Expression) visit(context.booleanExpression())); }
@Override public Node visitLogicalNot(SqlBaseParser.LogicalNotContext context) { return new NotExpression(getLocation(context), (Expression) visit(context.booleanExpression())); }
@Override public Expression rewriteIsNotNullPredicate(IsNotNullPredicate node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Expression value = treeRewriter.rewrite(node.getValue(), context); return new NotExpression(new IsNullPredicate(value)); }
@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); }
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 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 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; }
private static Expression isNotNull(Expression expression) { return new NotExpression(new IsNullPredicate(expression)); }
private static Expression isNotNull(Expression expression) { return new NotExpression(new IsNullPredicate(expression)); }
@Override public Node visitDistinctFrom(SqlBaseParser.DistinctFromContext context) { Expression expression = new ComparisonExpression( getLocation(context), ComparisonExpression.Operator.IS_DISTINCT_FROM, (Expression) visit(context.value), (Expression) visit(context.right)); if (context.NOT() != null) { expression = new NotExpression(getLocation(context), expression); } return expression; }
@Override public Node visitBetween(SqlBaseParser.BetweenContext context) { Expression expression = new BetweenPredicate( getLocation(context), (Expression) visit(context.value), (Expression) visit(context.lower), (Expression) visit(context.upper)); if (context.NOT() != null) { expression = new NotExpression(getLocation(context), expression); } return expression; }
@Override public Node visitLike(SqlBaseParser.LikeContext context) { Expression result = new LikePredicate( getLocation(context), (Expression) visit(context.value), (Expression) visit(context.pattern), visitIfPresent(context.escape, Expression.class)); if (context.NOT() != null) { result = new NotExpression(getLocation(context), result); } return result; }
@Override public Node visitInList(SqlBaseParser.InListContext context) { Expression result = new InPredicate( getLocation(context), (Expression) visit(context.value), new InListExpression(getLocation(context), visit(context.expression(), Expression.class))); if (context.NOT() != null) { result = new NotExpression(getLocation(context), result); } return result; }
@Override public Node visitInSubquery(SqlBaseParser.InSubqueryContext context) { Expression result = new InPredicate( getLocation(context), (Expression) visit(context.value), new SubqueryExpression(getLocation(context), (Query) visit(context.query()))); if (context.NOT() != null) { result = new NotExpression(getLocation(context), result); } return result; }
@Override public Node visitInList(SqlBaseParser.InListContext context) { Expression result = new InPredicate( getLocation(context), (Expression) visit(context.value), new InListExpression(getLocation(context), visit(context.expression(), Expression.class))); if (context.NOT() != null) { result = new NotExpression(getLocation(context), result); } return result; }
@Override public Node visitInSubquery(SqlBaseParser.InSubqueryContext context) { Expression result = new InPredicate( getLocation(context), (Expression) visit(context.value), new SubqueryExpression(getLocation(context), (Query) visit(context.query()))); if (context.NOT() != null) { result = new NotExpression(getLocation(context), result); } return result; }
@Test public void testBetween() { assertExpression("1 BETWEEN 2 AND 3", new BetweenPredicate(new LongLiteral("1"), new LongLiteral("2"), new LongLiteral("3"))); assertExpression("1 NOT BETWEEN 2 AND 3", new NotExpression(new BetweenPredicate(new LongLiteral("1"), new LongLiteral("2"), new LongLiteral("3")))); }