use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToDecimals.
@Test
public void shouldCoerceToDecimals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new LongLiteral(1234567890), new StringLiteral("\t -100.010 \t"), BIGINT_EXPRESSION, DECIMAL_EXPRESSION, INT_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
final SqlDecimal decimalType = SqlTypes.decimal(22, 3);
assertThat(result.commonType(), is(Optional.of(decimalType)));
assertThat(result.expressions(), is(ImmutableList.of(new DecimalLiteral(new BigDecimal("10.000")), new DecimalLiteral(new BigDecimal("1234567890.000")), new DecimalLiteral(new BigDecimal("-100.010")), cast(BIGINT_EXPRESSION, decimalType), cast(DECIMAL_EXPRESSION, decimalType), cast(INT_EXPRESSION, decimalType))));
}
use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class UdfLoaderTest method shouldLoadFunctionWithSchemaProvider.
@Test
public void shouldLoadFunctionWithSchemaProvider() {
// Given:
final UdfFactory returnDecimal = FUNC_REG.getUdfFactory(FunctionName.of("returndecimal"));
// When:
final SqlDecimal decimal = SqlTypes.decimal(2, 1);
final List<SqlArgument> args = Collections.singletonList(SqlArgument.of(decimal));
final KsqlScalarFunction function = returnDecimal.getFunction(args);
// Then:
assertThat(function.getReturnType(args), equalTo(decimal));
}
use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class UdfLoaderTest method shouldThrowOnReturnTypeMismatch.
@Test
public void shouldThrowOnReturnTypeMismatch() {
// Given:
final UdfFactory returnIncompatible = FUNC_REG.getUdfFactory(of("returnincompatible"));
final SqlDecimal decimal = decimal(2, 1);
final List<SqlArgument> args = singletonList(SqlArgument.of(decimal));
final KsqlScalarFunction function = returnIncompatible.getFunction(args);
// When:
final Exception e = assertThrows(KsqlException.class, () -> function.getReturnType(args));
// Then:
assertThat(e.getMessage(), containsString("Return type DECIMAL(2, 1) of UDF RETURNINCOMPATIBLE does not " + "match the declared return type STRING."));
}
use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class UdfLoaderTest method shouldLoadDecimalUdfs.
@Test
public void shouldLoadDecimalUdfs() {
// Given:
final SqlDecimal schema = SqlTypes.decimal(2, 1);
// When:
final KsqlScalarFunction fun = FUNC_REG.getUdfFactory(FunctionName.of("floor")).getFunction(ImmutableList.of(SqlArgument.of(schema)));
// Then:
assertThat(fun.name().text(), equalToIgnoringCase("floor"));
}
use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToIntsToDecimals.
@Test
public void shouldCoerceToIntsToDecimals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new DecimalLiteral(new BigDecimal("1.1")), new IntegerLiteral(10), INT_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
final SqlDecimal decimalType = SqlTypes.decimal(11, 1);
assertThat(result.commonType(), is(Optional.of(decimalType)));
assertThat(result.expressions(), is(ImmutableList.of(new DecimalLiteral(new BigDecimal("1.1")), new DecimalLiteral(new BigDecimal("10.0")), cast(INT_EXPRESSION, decimalType))));
}
Aggregations