Search in sources :

Example 1 with BetweenPredicate

use of io.confluent.ksql.execution.expression.tree.BetweenPredicate in project ksql by confluentinc.

the class ExpressionFormatterTest method shouldFormatBetweenPredicate.

@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)"));
}
Also used : BetweenPredicate(io.confluent.ksql.execution.expression.tree.BetweenPredicate) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Example 2 with BetweenPredicate

use of io.confluent.ksql.execution.expression.tree.BetweenPredicate in project ksql by confluentinc.

the class ExpressionTreeRewriterTest method shouldRewriteBetweenPredicate.

@Test
public void shouldRewriteBetweenPredicate() {
    // Given:
    final BetweenPredicate parsed = parseExpression("1 BETWEEN 0 AND 2");
    when(processor.apply(parsed.getValue(), context)).thenReturn(expr1);
    when(processor.apply(parsed.getMin(), context)).thenReturn(expr2);
    when(processor.apply(parsed.getMax(), context)).thenReturn(expr3);
    // When:
    final Expression rewritten = expressionRewriter.rewrite(parsed, context);
    // Then:
    assertThat(rewritten, equalTo(new BetweenPredicate(parsed.getLocation(), expr1, expr2, expr3)));
}
Also used : BetweenPredicate(io.confluent.ksql.execution.expression.tree.BetweenPredicate) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) Test(org.junit.Test)

Example 3 with BetweenPredicate

use of io.confluent.ksql.execution.expression.tree.BetweenPredicate in project ksql by confluentinc.

the class InterpretedExpressionTest method shouldEvaluateBetween.

@Test
public void shouldEvaluateBetween() {
    // Given:
    final Expression expression1 = new BetweenPredicate(new IntegerLiteral(4), new IntegerLiteral(3), new IntegerLiteral(8));
    final Expression expression2 = new BetweenPredicate(new IntegerLiteral(0), new IntegerLiteral(3), new IntegerLiteral(8));
    final Expression expression3 = new BetweenPredicate(new StringLiteral("b"), new StringLiteral("a"), new StringLiteral("c"));
    final Expression expression4 = new BetweenPredicate(new StringLiteral("z"), new StringLiteral("a"), new StringLiteral("c"));
    // When:
    InterpretedExpression interpreter1 = interpreter(expression1);
    InterpretedExpression interpreter2 = interpreter(expression2);
    InterpretedExpression interpreter3 = interpreter(expression3);
    InterpretedExpression interpreter4 = interpreter(expression4);
    // Then:
    assertThat(interpreter1.evaluate(ROW), is(true));
    assertThat(interpreter2.evaluate(ROW), is(false));
    assertThat(interpreter3.evaluate(ROW), is(true));
    assertThat(interpreter4.evaluate(ROW), is(false));
}
Also used : BetweenPredicate(io.confluent.ksql.execution.expression.tree.BetweenPredicate) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 4 with BetweenPredicate

use of io.confluent.ksql.execution.expression.tree.BetweenPredicate in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldThrowNotKeyColumnForBetween.

@Test
public void shouldThrowNotKeyColumnForBetween() {
    // Given:
    final Expression expression = new BetweenPredicate(new StringLiteral("a"), new StringLiteral("b"), new IntegerLiteral(10));
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
    // Then:
    assertThat(e.getMessage(), containsString("A comparison must directly reference a key column"));
}
Also used : BetweenPredicate(io.confluent.ksql.execution.expression.tree.BetweenPredicate) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) KsqlException(io.confluent.ksql.util.KsqlException) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Aggregations

BetweenPredicate (io.confluent.ksql.execution.expression.tree.BetweenPredicate)4 Test (org.junit.Test)4 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)3 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)3 Expression (io.confluent.ksql.execution.expression.tree.Expression)3 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)3 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)3 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)3 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)2 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)2 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)2 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)2 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)2 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)2 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)2 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)2 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)1 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)1 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)1 KsqlException (io.confluent.ksql.util.KsqlException)1