private static BetweenPredicate between(Expression expression, Expression min, Expression max) { return new BetweenPredicate(expression, min, max); }
@Override protected Object visitBetweenPredicate(BetweenPredicate node, Object context) { Object value = process(node.getValue(), context); if (value == null) { return null; } Object min = process(node.getMin(), context); if (min == null) { return null; } Object max = process(node.getMax(), context); if (max == null) { return null; } if (hasUnresolvedValue(value, min, max)) { return new BetweenPredicate( toExpression(value, type(node.getValue())), toExpression(min, type(node.getMin())), toExpression(max, type(node.getMax()))); } return invokeOperator(OperatorType.BETWEEN, types(node.getValue(), node.getMin(), node.getMax()), ImmutableList.of(value, min, max)); }
@Override protected Object visitBetweenPredicate(BetweenPredicate node, Object context) { Object value = process(node.getValue(), context); if (value == null) { return null; } Object min = process(node.getMin(), context); if (min == null) { return null; } Object max = process(node.getMax(), context); if (max == null) { return null; } if (hasUnresolvedValue(value, min, max)) { return new BetweenPredicate( toExpression(value, type(node.getValue())), toExpression(min, type(node.getMin())), toExpression(max, type(node.getMax()))); } return invokeOperator(OperatorType.BETWEEN, types(node.getValue(), node.getMin(), node.getMax()), ImmutableList.of(value, min, max)); }
private static BetweenPredicate between(Expression expression, Expression min, Expression max) { return new BetweenPredicate(expression, min, max); }
private static BetweenPredicate between(Symbol symbol, Expression min, Expression max) { return new BetweenPredicate(symbol.toSymbolReference(), min, max); }
private static BetweenPredicate between(Symbol symbol, Expression min, Expression max) { return new BetweenPredicate(symbol.toSymbolReference(), min, max); }
@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 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 protected ExtractionResult visitBetweenPredicate(BetweenPredicate node, Boolean complement) { // Re-write as two comparison expressions return process(and( new ComparisonExpression(GREATER_THAN_OR_EQUAL, node.getValue(), node.getMin()), new ComparisonExpression(LESS_THAN_OR_EQUAL, node.getValue(), node.getMax())), complement); }
@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")))); }
return new BetweenPredicate(reference, literalEncoder.toExpression(range.getLow().getValue(), type), literalEncoder.toExpression(range.getHigh().getValue(), type));
return new BetweenPredicate(reference, literalEncoder.toExpression(range.getLow().getValue(), type), literalEncoder.toExpression(range.getHigh().getValue(), type));