protected Node visitBetweenPredicate(final BetweenPredicate node, final Object context) { // use an if/else block here (instead of isPresent.map(...).orElse(...)) so only one object // gets instantiated (issue #1784) if (node.getLocation().isPresent()) { return new BetweenPredicate(node.getLocation().get(), (Expression) process(node.getValue(), context), (Expression) process(node.getMin(), context), (Expression) process(node.getMax(), context)); } else { return new BetweenPredicate((Expression) process(node.getValue(), context), (Expression) process(node.getMin(), context), (Expression) process(node.getMax(), context)); } }
@Override public Node visitBetween(final 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; }
@Test public void shouldFormatBetweenPredicate() { final BetweenPredicate predicate = new BetweenPredicate(new StringLiteral("blah"), new LongLiteral(5), new LongLiteral(10)); assertThat(ExpressionFormatter.formatExpression(predicate), equalTo("('blah' BETWEEN 5 AND 10)")); }