Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.trino.sql.tree.ArithmeticBinaryExpression;
import io.trino.sql.tree.ArithmeticUnaryExpression;
import io.trino.sql.tree.AstVisitor;
import io.trino.sql.tree.BetweenPredicate;
import io.trino.sql.tree.BinaryLiteral;
import io.trino.sql.tree.BooleanLiteral;
import io.trino.sql.tree.Cast;
Expand Down Expand Up @@ -534,6 +535,23 @@ protected Optional<ConnectorExpression> visitArithmeticBinary(ArithmeticBinaryEx
new Call(typeOf(node), functionNameForArithmeticBinaryOperator(node.getOperator()), ImmutableList.of(left, right))));
}

@Override
protected Optional<ConnectorExpression> visitBetweenPredicate(BetweenPredicate node, Void context)
{
if (!isComplexExpressionPushdown(session)) {
return Optional.empty();
}
return process(node.getValue()).flatMap(value ->
process(node.getMin()).flatMap(min ->
process(node.getMax()).map(max ->
new Call(
BOOLEAN,
AND_FUNCTION_NAME,
ImmutableList.of(
new Call(BOOLEAN, GREATER_THAN_OR_EQUAL_OPERATOR_FUNCTION_NAME, ImmutableList.of(value, min)),
new Call(BOOLEAN, LESS_THAN_OR_EQUAL_OPERATOR_FUNCTION_NAME, ImmutableList.of(value, max)))))));
}

@Override
protected Optional<ConnectorExpression> visitArithmeticUnary(ArithmeticUnaryExpression node, Void context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import io.trino.spi.type.Type;
import io.trino.sql.tree.ArithmeticBinaryExpression;
import io.trino.sql.tree.ArithmeticUnaryExpression;
import io.trino.sql.tree.BetweenPredicate;
import io.trino.sql.tree.ComparisonExpression;
import io.trino.sql.tree.DoubleLiteral;
import io.trino.sql.tree.Expression;
import io.trino.sql.tree.IsNotNullPredicate;
import io.trino.sql.tree.IsNullPredicate;
Expand All @@ -52,7 +54,10 @@

import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.airlift.slice.Slices.utf8Slice;
import static io.trino.spi.expression.StandardFunctions.AND_FUNCTION_NAME;
import static io.trino.spi.expression.StandardFunctions.GREATER_THAN_OR_EQUAL_OPERATOR_FUNCTION_NAME;
import static io.trino.spi.expression.StandardFunctions.IS_NULL_FUNCTION_NAME;
import static io.trino.spi.expression.StandardFunctions.LESS_THAN_OR_EQUAL_OPERATOR_FUNCTION_NAME;
import static io.trino.spi.expression.StandardFunctions.LIKE_PATTERN_FUNCTION_NAME;
import static io.trino.spi.expression.StandardFunctions.NEGATE_FUNCTION_NAME;
import static io.trino.spi.expression.StandardFunctions.NOT_FUNCTION_NAME;
Expand Down Expand Up @@ -223,6 +228,33 @@ public void testTranslateArithmeticUnaryPlus()
new Variable("double_symbol_1", DOUBLE));
}

@Test
public void testTranslateBetween()
{
assertTranslationToConnectorExpression(
TEST_SESSION,
new BetweenPredicate(
new SymbolReference("double_symbol_1"),
new DoubleLiteral("1.2"),
new SymbolReference("double_symbol_2")),
new Call(
BOOLEAN,
AND_FUNCTION_NAME,
List.of(
new Call(
BOOLEAN,
GREATER_THAN_OR_EQUAL_OPERATOR_FUNCTION_NAME,
List.of(
new Variable("double_symbol_1", DOUBLE),
new Constant(1.2d, DOUBLE))),
new Call(
BOOLEAN,
LESS_THAN_OR_EQUAL_OPERATOR_FUNCTION_NAME,
List.of(
new Variable("double_symbol_1", DOUBLE),
new Variable("double_symbol_2", DOUBLE))))));
}

@Test
public void testTranslateLike()
{
Expand Down