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)"));
}
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)));
}
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));
}
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"));
}
Aggregations