Search in sources :

Example 11 with SqlDecimal

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)));
}
Also used : SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) Test(org.junit.Test)

Example 12 with SqlDecimal

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));
}
Also used : SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) Test(org.junit.Test)

Example 13 with SqlDecimal

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)));
}
Also used : SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) Test(org.junit.Test)

Example 14 with SqlDecimal

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)));
}
Also used : SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) Test(org.junit.Test)

Example 15 with SqlDecimal

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));
}
Also used : SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) Test(org.junit.Test)

Aggregations

SqlDecimal (io.confluent.ksql.schema.ksql.types.SqlDecimal)20 Test (org.junit.Test)16 BigDecimal (java.math.BigDecimal)4 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)3 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)3 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)2 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)2 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)2 Expression (io.confluent.ksql.execution.expression.tree.Expression)2 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)2 Result (io.confluent.ksql.execution.util.CoercionUtil.Result)2 SqlArgument (io.confluent.ksql.schema.ksql.SqlArgument)2 KsqlException (io.confluent.ksql.util.KsqlException)2 DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)1 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)1 ArithmeticBinaryTerm (io.confluent.ksql.execution.interpreter.terms.ArithmeticBinaryTerm)1 ArithmeticUnaryTerm (io.confluent.ksql.execution.interpreter.terms.ArithmeticUnaryTerm)1 CastTerm (io.confluent.ksql.execution.interpreter.terms.CastTerm)1 Term (io.confluent.ksql.execution.interpreter.terms.Term)1 UdfSchemaProvider (io.confluent.ksql.function.udf.UdfSchemaProvider)1