protected Node visitInPredicate(final InPredicate 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 InPredicate(node.getLocation().get(), (Expression) process(node.getValue(), context), (Expression) process(node.getValueList(), context)); } else { return new InPredicate((Expression) process(node.getValue(), context), (Expression) process(node.getValueList(), context)); } }
@Override protected Node visitInPredicate(final InPredicate node, final Node parent) { node.setParent(parent); process(node.getValue(), node); process(node.getValueList(), node); return null; }
@Override protected R visitInPredicate(final InPredicate node, final C context) { process(node.getValue(), context); process(node.getValueList(), context); return null; }
@Override public Node visitInList(final 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 protected R visitInPredicate(final InPredicate node, final C context) { process(node.getValue(), context); process(node.getValueList(), context); return null; }
@Override public Node visitInSubquery(final 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 protected String visitInPredicate(final InPredicate node, final Boolean unmangleNames) { return "(" + process(node.getValue(), unmangleNames) + " IN " + process(node.getValueList(), unmangleNames) + ")"; }
@Test public void shouldFormatInPredicate() { assertThat(ExpressionFormatter.formatExpression(new InPredicate(new StringLiteral("foo"), new StringLiteral("a"))), equalTo("('foo' IN 'a')")); }