use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ComparisonUtilTest method shouldAssertTrueForValidComparisons.
@Test
public void shouldAssertTrueForValidComparisons() {
// When:
int i = 0;
int j = 0;
for (final SqlType leftType : typesTable) {
for (final SqlType rightType : typesTable) {
if (expectedResults.get(i).get(j)) {
assertThat(ComparisonUtil.isValidComparison(leftType, ComparisonExpression.Type.EQUAL, rightType), is(true));
}
j++;
}
i++;
j = 0;
}
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ComparisonUtilTest method shouldThrowForInvalidComparisons.
@Test
public void shouldThrowForInvalidComparisons() {
// When:
int i = 0;
int j = 0;
for (final SqlType leftType : typesTable) {
for (final SqlType rightType : typesTable) {
assertThat(ComparisonUtil.isValidComparison(leftType, ComparisonExpression.Type.EQUAL, rightType), is(expectedResults.get(i).get(j)));
j++;
}
i++;
j = 0;
}
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateTypeForStructExpression.
@Test
public void shouldEvaluateTypeForStructExpression() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(COL0, SqlTypes.array(SqlTypes.INTEGER)).build();
expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
final Expression exp = new CreateStructExpression(ImmutableList.of(new Field("field1", new StringLiteral("foo")), new Field("field2", new UnqualifiedColumnReferenceExp(COL0)), new Field("field3", new CreateStructExpression(ImmutableList.of()))));
// When:
final SqlType sqlType = expressionTypeManager.getExpressionSqlType(exp);
// Then:
assertThat(sqlType, is(SqlTypes.struct().field("field1", SqlTypes.STRING).field("field2", SqlTypes.array(SqlTypes.INTEGER)).field("field3", SqlTypes.struct().build()).build()));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateLambdaInUDFWithArray.
@Test
public void shouldEvaluateLambdaInUDFWithArray() {
// Given:
givenUdfWithNameAndReturnType("TRANSFORM", SqlTypes.DOUBLE);
when(function.parameters()).thenReturn(ImmutableList.of(ArrayType.of(DoubleType.INSTANCE), LambdaType.of(ImmutableList.of(DoubleType.INSTANCE), DoubleType.INSTANCE)));
final Expression expression = new FunctionCall(FunctionName.of("TRANSFORM"), ImmutableList.of(ARRAYCOL, new LambdaFunctionCall(ImmutableList.of("X"), 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.array(SqlTypes.DOUBLE)), SqlArgument.of(SqlLambda.of(1))));
verify(function).getReturnType(ImmutableList.of(SqlArgument.of(SqlTypes.array(SqlTypes.DOUBLE)), SqlArgument.of(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.DOUBLE), SqlTypes.DOUBLE))));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldResolveTypeForAddDoubleIntegerLiteral.
@Test
public void shouldResolveTypeForAddDoubleIntegerLiteral() {
final Expression expression = new ArithmeticBinaryExpression(Operator.ADD, COL3, literal(10));
final SqlType type = expressionTypeManager.getExpressionSqlType(expression);
assertThat(type, is(SqlTypes.DOUBLE));
}
Aggregations