Search in sources :

Example 6 with LikePredicate

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

the class ExpressionTypeManagerTest method shouldEvaluateBooleanSchemaForLikeExpression.

@Test
public void shouldEvaluateBooleanSchemaForLikeExpression() {
    final Expression expression = 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) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) Test(org.junit.Test)

Example 7 with LikePredicate

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

the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForLikePattern.

@Test
public void shouldGenerateCorrectCodeForLikePattern() {
    // Given:
    final Expression expression = new LikePredicate(COL1, new StringLiteral("%foo"), Optional.empty());
    // 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 8 with LikePredicate

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

the class ExpressionFormatterTest method shouldFormatLikePredicate.

@Test
public void shouldFormatLikePredicate() {
    final LikePredicate predicate = new LikePredicate(new StringLiteral("string"), new StringLiteral("*"), Optional.empty());
    assertThat(ExpressionFormatter.formatExpression(predicate), equalTo("('string' LIKE '*')"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) Test(org.junit.Test)

Example 9 with LikePredicate

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

the class ExpressionFormatterTest method shouldFormatLikePredicateWithEscape.

@Test
public void shouldFormatLikePredicateWithEscape() {
    final LikePredicate predicate = new LikePredicate(new StringLiteral("string"), new StringLiteral("*"), Optional.of('!'));
    assertThat(ExpressionFormatter.formatExpression(predicate), equalTo("('string' LIKE '*' ESCAPE '!')"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) Test(org.junit.Test)

Example 10 with LikePredicate

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

the class QueryFilterNodeTest method shouldThrowNonStringForLike.

@Test
public void shouldThrowNonStringForLike() {
    // Given:
    final Expression expression = new LikePredicate(new StringLiteral("a"), new IntegerLiteral(10), Optional.empty());
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
    // Then:
    assertThat(e.getMessage(), containsString("Like condition must be between strings"));
}
Also used : 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) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) KsqlException(io.confluent.ksql.util.KsqlException) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) 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