use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateTypeForCreateArrayExpression.
@Test
public void shouldEvaluateTypeForCreateArrayExpression() {
// Given:
Expression expression = new CreateArrayExpression(ImmutableList.of(new UnqualifiedColumnReferenceExp(COL0)));
// When:
final SqlType type = expressionTypeManager.getExpressionSqlType(expression);
// Then:
assertThat(type, is(SqlTypes.array(SqlTypes.BIGINT)));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateLambdaInUDFWithMap.
@Test
public void shouldEvaluateLambdaInUDFWithMap() {
// Given:
givenUdfWithNameAndReturnType("TRANSFORM", SqlTypes.DOUBLE);
when(function.parameters()).thenReturn(ImmutableList.of(MapType.of(DoubleType.INSTANCE, DoubleType.INSTANCE), LambdaType.of(ImmutableList.of(LongType.INSTANCE, DoubleType.INSTANCE), DoubleType.INSTANCE)));
final Expression expression = new FunctionCall(FunctionName.of("TRANSFORM"), ImmutableList.of(MAPCOL, new LambdaFunctionCall(ImmutableList.of("X", "Y"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("X"), new IntegerLiteral(5)))));
// When:
final SqlType exprType = expressionTypeManager.getExpressionSqlType(expression);
// Then:
assertThat(exprType, is(SqlTypes.DOUBLE));
verify(udfFactory).getFunction(ImmutableList.of(SqlArgument.of(SqlTypes.map(SqlTypes.BIGINT, SqlTypes.DOUBLE)), SqlArgument.of(SqlLambda.of(2))));
verify(function).getReturnType(ImmutableList.of(SqlArgument.of(SqlTypes.map(SqlTypes.BIGINT, SqlTypes.DOUBLE)), SqlArgument.of(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.BIGINT, SqlTypes.DOUBLE), SqlTypes.BIGINT))));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldResolveTypeForMultiplyBigintIntegerLiteral.
@Test
public void shouldResolveTypeForMultiplyBigintIntegerLiteral() {
final Expression expression = new ArithmeticBinaryExpression(Operator.MULTIPLY, TestExpressions.COL0, literal(10));
final SqlType type = expressionTypeManager.getExpressionSqlType(expression);
assertThat(type, is(SqlTypes.BIGINT));
}
use of io.confluent.ksql.schema.ksql.types.SqlType 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));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateBooleanSchemaForInExpression.
@Test
public void shouldEvaluateBooleanSchemaForInExpression() {
final Expression expression = new InPredicate(TestExpressions.COL0, new InListExpression(ImmutableList.of(new StringLiteral("key1"))));
final SqlType exprType0 = expressionTypeManager.getExpressionSqlType(expression);
assertThat(exprType0, is(SqlTypes.BOOLEAN));
}
Aggregations