use of io.confluent.ksql.execution.expression.tree.WhenClause in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldGetCorrectSchemaForSearchedCaseWhenStruct.
@Test
public void shouldGetCorrectSchemaForSearchedCaseWhenStruct() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(10)), ADDRESS)), Optional.empty());
// When:
final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
// Then:
final SqlType sqlType = SCHEMA.findColumn(ADDRESS.getColumnName()).get().type();
assertThat(result, is(sqlType));
}
use of io.confluent.ksql.execution.expression.tree.WhenClause in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateSearchedCase.
@Test
public void shouldEvaluateSearchedCase() {
// Given:
final Expression case1 = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL7, new IntegerLiteral(10)), new StringLiteral("Large")), new WhenClause(new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL7, new IntegerLiteral(5)), new StringLiteral("Medium")), new WhenClause(new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL7, new IntegerLiteral(2)), new StringLiteral("Small"))), Optional.of(new StringLiteral("Tiny")));
final Expression case2 = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL7, new IntegerLiteral(6)), new StringLiteral("Blah"))), Optional.empty());
// When:
InterpretedExpression interpreter1 = interpreter(case1);
InterpretedExpression interpreter2 = interpreter(case2);
// Then:
assertThat(interpreter1.evaluate(make(7, 12)), is("Large"));
assertThat(interpreter1.evaluate(make(7, 9)), is("Medium"));
assertThat(interpreter1.evaluate(make(7, 3)), is("Small"));
assertThat(interpreter1.evaluate(make(7, 1)), is("Tiny"));
assertThat(interpreter2.evaluate(make(7, 1)), is("Blah"));
assertThat(interpreter2.evaluate(make(7, 10)), nullValue());
}
Aggregations