Search in sources :

Example 51 with ComparisonExpression

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

the class ExpressionTypeManagerTest method testComparisonExpr.

@Test
public void testComparisonExpr() {
    final Expression expression = new ComparisonExpression(Type.GREATER_THAN, TestExpressions.COL0, COL3);
    final SqlType exprType = expressionTypeManager.getExpressionSqlType(expression);
    assertThat(exprType, is(SqlTypes.BOOLEAN));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) 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) Test(org.junit.Test)

Example 52 with ComparisonExpression

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

the class ExpressionTypeManagerTest method shouldFailForCheckingComplexTypeEquality.

@Test
public void shouldFailForCheckingComplexTypeEquality() {
    // Given:
    final Expression expression = new ComparisonExpression(Type.EQUAL, MAPCOL, ADDRESS);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot compare COL5 (MAP<BIGINT, DOUBLE>) to COL6 " + "(STRUCT<`NUMBER` BIGINT, `STREET` STRING, `CITY` STRING, `STATE` STRING, " + "`ZIPCODE` BIGINT>) with EQUAL"));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) 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) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 53 with ComparisonExpression

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

the class ExpressionTypeManagerTest method shouldFailForComplexTypeComparison.

@Test
public void shouldFailForComplexTypeComparison() {
    // Given:
    final Expression expression = new ComparisonExpression(Type.GREATER_THAN, MAPCOL, ADDRESS);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot compare COL5 (MAP<BIGINT, DOUBLE>) to COL6 (STRUCT<`NUMBER` BIGINT, " + "`STREET` STRING, `CITY` STRING, `STATE` STRING, `ZIPCODE` BIGINT>) " + "with GREATER_THAN"));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) 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) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 54 with ComparisonExpression

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

the class ExpressionTypeManagerTest method shouldGetCorrectSchemaForSearchedCase.

@Test
public void shouldGetCorrectSchemaForSearchedCase() {
    // Given:
    final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.LESS_THAN, COL7, new IntegerLiteral(10)), new StringLiteral("small")), new WhenClause(new ComparisonExpression(Type.LESS_THAN, COL7, new IntegerLiteral(100)), new StringLiteral("medium"))), Optional.of(new StringLiteral("large")));
    // When:
    final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
    // Then:
    assertThat(result, is(SqlTypes.STRING));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) 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) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 55 with ComparisonExpression

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

the class SqlPredicateTest method shouldCompileEvaluator.

@Test
public void shouldCompileEvaluator() {
    // Given:
    predicate = new SqlPredicate(new ComparisonExpression(Type.LESS_THAN, COL0, new LongLiteral(100)), SCHEMA, KSQL_CONFIG, functionRegistry);
    transformer = predicate.getTransformer(processingLogger);
    // When:
    final Optional<GenericRow> result1 = transformer.transform("key", genericRow(99L), ctx);
    final Optional<GenericRow> result2 = transformer.transform("key", genericRow(100L), ctx);
    // Then:
    assertThat(result1, is(not(Optional.empty())));
    assertThat(result2, is(Optional.empty()));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Aggregations

ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)102 Test (org.junit.Test)100 Expression (io.confluent.ksql.execution.expression.tree.Expression)72 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)67 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)65 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)60 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)60 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)55 KsqlException (io.confluent.ksql.util.KsqlException)26 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)25 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)23 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)19 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)19 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)19 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)19 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)19 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)19 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)14 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)13 WindowBounds (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds)12