use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class DecimalUtilTest method shouldConvertDecimalToSqlDecimal.
@Test
public void shouldConvertDecimalToSqlDecimal() {
// Given:
final SqlDecimal given = SqlTypes.decimal(2, 2);
// When:
final SqlDecimal decimal = DecimalUtil.toSqlDecimal(given);
// Then:
assertThat(decimal, is(SqlTypes.decimal(2, 2)));
}
use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class DecimalUtilTest method shouldAllowImplicitlyCastOnEqualSchema.
@Test
public void shouldAllowImplicitlyCastOnEqualSchema() {
// Given:
final SqlDecimal s1 = SqlTypes.decimal(5, 2);
final SqlDecimal s2 = SqlTypes.decimal(5, 2);
// When:
final boolean compatible = DecimalUtil.canImplicitlyCast(s1, s2);
// Then:
assertThat(compatible, is(true));
}
use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class DecimalUtilTest method shouldConvertLongToSqlDecimal.
@Test
public void shouldConvertLongToSqlDecimal() {
// When:
final SqlDecimal decimal = DecimalUtil.toSqlDecimal(SqlTypes.BIGINT);
// Then:
assertThat(decimal, is(SqlTypes.decimal(19, 0)));
}
use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class DecimalUtilTest method shouldWidenBigIntAndDecimal.
@Test
public void shouldWidenBigIntAndDecimal() {
// Given:
final SqlDecimal smallerPrecision = SqlTypes.decimal(14, 3);
final SqlDecimal largerPrecision = SqlTypes.decimal(20, 0);
// Then:
assertThat(DecimalUtil.widen(smallerPrecision, SqlTypes.BIGINT), is(SqlTypes.decimal(22, 3)));
assertThat(DecimalUtil.widen(SqlTypes.BIGINT, largerPrecision), is(SqlTypes.decimal(20, 0)));
}
use of io.confluent.ksql.schema.ksql.types.SqlDecimal in project ksql by confluentinc.
the class DecimalUtilTest method shouldAllowImplicitlyCastOnLowerPrecision.
@Test
public void shouldAllowImplicitlyCastOnLowerPrecision() {
// Given:
final SqlDecimal s1 = SqlTypes.decimal(2, 1);
final SqlDecimal s2 = SqlTypes.decimal(1, 1);
// When:
final boolean compatible = DecimalUtil.canImplicitlyCast(s1, s2);
// Then:
assertThat(compatible, is(false));
}
Aggregations