use of io.confluent.ksql.execution.expression.tree.LikePredicate in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateLikePredicate.
@Test
public void shouldEvaluateLikePredicate() {
// Given:
final Expression expression1 = new LikePredicate(new StringLiteral("catdog"), new StringLiteral("ca%og"), Optional.empty());
final Expression expression2 = new LikePredicate(new StringLiteral("cat%og"), new StringLiteral("cat\\%og"), Optional.empty());
final Expression expression3 = new LikePredicate(new StringLiteral("cat%og"), new StringLiteral("cat\\%og"), Optional.of('\\'));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
InterpretedExpression interpreter3 = interpreter(expression3);
// Then:
assertThat(interpreter1.evaluate(ROW), is(true));
assertThat(interpreter2.evaluate(ROW), is(false));
assertThat(interpreter3.evaluate(ROW), is(true));
}
use of io.confluent.ksql.execution.expression.tree.LikePredicate in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForLikePatternWithEscape.
@Test
public void shouldGenerateCorrectCodeForLikePatternWithEscape() {
// Given:
final Expression expression = new LikePredicate(COL1, new StringLiteral("%foo"), Optional.of('!'));
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// Then:
assertThat(javaExpression, equalTo("LikeEvaluator.matches(COL1, \"%foo\", '!')"));
}
use of io.confluent.ksql.execution.expression.tree.LikePredicate in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteLikePredicate.
@Test
public void shouldRewriteLikePredicate() {
// Given:
final LikePredicate parsed = parseExpression("col1 LIKE '%foo%' ESCAPE '!'");
when(processor.apply(parsed.getValue(), context)).thenReturn(expr1);
when(processor.apply(parsed.getPattern(), context)).thenReturn(expr2);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new LikePredicate(parsed.getLocation(), expr1, expr2, Optional.of('!'))));
}
use of io.confluent.ksql.execution.expression.tree.LikePredicate in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForLikePatternWithColRef.
@Test
public void shouldGenerateCorrectCodeForLikePatternWithColRef() {
// Given:
final Expression expression = new LikePredicate(COL1, COL1, Optional.empty());
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// Then:
assertThat(javaExpression, equalTo("LikeEvaluator.matches(COL1, COL1)"));
}
use of io.confluent.ksql.execution.expression.tree.LikePredicate in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateBooleanSchemaForNotLikeExpression.
@Test
public void shouldEvaluateBooleanSchemaForNotLikeExpression() {
final Expression expression = new NotExpression(new LikePredicate(COL1, new StringLiteral("%foo"), Optional.empty()));
final SqlType exprType0 = expressionTypeManager.getExpressionSqlType(expression);
assertThat(exprType0, is(SqlTypes.BOOLEAN));
}
Aggregations