use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCastDecimalToDoubleInBinaryExpression.
@Test
public void shouldGenerateCastDecimalToDoubleInBinaryExpression() {
// Given:
final ArithmeticBinaryExpression binExp = new ArithmeticBinaryExpression(Operator.ADD, new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")), new UnqualifiedColumnReferenceExp(ColumnName.of("COL3")));
// When:
final String java = sqlToJavaVisitor.process(binExp);
// Then:
final String doubleCast = CastEvaluator.generateCode("COL8", SqlTypes.decimal(2, 1), SqlTypes.DOUBLE, ksqlConfig);
assertThat(java, containsString(doubleCast));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class FunctionArgumentsUtilTest method shouldResolveLambdaWithoutGenerics.
@Test
public void shouldResolveLambdaWithoutGenerics() {
// Given:
givenUdfWithNameAndReturnType("SmallLambda", SqlTypes.DOUBLE);
when(function.parameters()).thenReturn(ImmutableList.of(ArrayType.of(ParamTypes.DOUBLE), LambdaType.of(ImmutableList.of(ParamTypes.INTEGER), ParamTypes.INTEGER)));
final FunctionCall expression = new FunctionCall(FunctionName.of("SmallLambda"), ImmutableList.of(ARRAYCOL, new LambdaFunctionCall(ImmutableList.of("2.3"), new ArithmeticBinaryExpression(Operator.ADD, new DoubleLiteral(2.3), new DoubleLiteral(2.3)))));
// When:
final FunctionTypeInfo argumentsAndContexts = FunctionArgumentsUtil.getFunctionTypeInfo(expressionTypeManager, expression, udfFactory, Collections.emptyMap());
// Then:
assertThat(argumentsAndContexts.getReturnType(), is(SqlTypes.DOUBLE));
assertThat(argumentsAndContexts.getArgumentInfos().size(), is(2));
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.INTEGER), SqlTypes.DOUBLE))));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression 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.execution.expression.tree.ArithmeticBinaryExpression 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));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldFailIfWhenIsNotBoolean.
@Test
public void shouldFailIfWhenIsNotBoolean() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ArithmeticBinaryExpression(Operator.ADD, TestExpressions.COL0, new IntegerLiteral(10)), new StringLiteral("foo"))), Optional.empty());
// When:
final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), containsString("WHEN operand type should be boolean." + System.lineSeparator() + "Type for '(COL0 + 10)' is BIGINT"));
}
Aggregations