Search in sources :

Example 1 with LikePredicate

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

Example 2 with LikePredicate

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\", '!')"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) 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) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 3 with LikePredicate

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('!'))));
}
Also used : 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) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) Test(org.junit.Test)

Example 4 with LikePredicate

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)"));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) 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) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 5 with LikePredicate

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));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) 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) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) Test(org.junit.Test)

Aggregations

LikePredicate (io.confluent.ksql.execution.expression.tree.LikePredicate)10 Test (org.junit.Test)10 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)8 Expression (io.confluent.ksql.execution.expression.tree.Expression)8 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)8 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)8 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)7 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)7 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)7 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)7 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)7 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)7 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)6 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)6 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)4 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)3 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)2 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)1