use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceStructOfCompatibleLiterals.
@Test
public void shouldCoerceStructOfCompatibleLiterals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateStructExpression(ImmutableList.of(new Field("a", new IntegerLiteral(10)))), new CreateStructExpression(ImmutableList.of(new Field("a", new StringLiteral("123456789000")))));
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
final SqlStruct sqlStruct = SqlTypes.struct().field("a", SqlTypes.BIGINT).build();
assertThat(result.commonType(), is(Optional.of(sqlStruct)));
assertThat(result.expressions(), is(ImmutableList.of(cast(new CreateStructExpression(ImmutableList.of(new Field("a", new IntegerLiteral(10)))), sqlStruct), cast(new CreateStructExpression(ImmutableList.of(new Field("a", new StringLiteral("123456789000")))), sqlStruct))));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceStringNumericWithDecimalPointToDecimals.
@Test
public void shouldCoerceStringNumericWithDecimalPointToDecimals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new StringLiteral("1.0"));
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.decimal(11, 1))));
assertThat(result.expressions(), is(ImmutableList.of(new DecimalLiteral(new BigDecimal("10.0")), new DecimalLiteral(new BigDecimal("1.0")))));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToDoubles.
@Test
public void shouldCoerceToDoubles() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new LongLiteral(1234567890), new DoubleLiteral(123.456), new StringLiteral("\t -100.010 \t"), BIGINT_EXPRESSION, DECIMAL_EXPRESSION, INT_EXPRESSION, DOUBLE_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.DOUBLE)));
assertThat(result.expressions(), is(ImmutableList.of(new DoubleLiteral(10.0), new DoubleLiteral(1234567890.0), new DoubleLiteral(123.456), new DoubleLiteral(-100.01), cast(BIGINT_EXPRESSION, SqlTypes.DOUBLE), cast(DECIMAL_EXPRESSION, SqlTypes.DOUBLE), cast(INT_EXPRESSION, SqlTypes.DOUBLE), DOUBLE_EXPRESSION)));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToBigIntIfStringNumericTooWideForInt.
@Test
public void shouldCoerceToBigIntIfStringNumericTooWideForInt() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new StringLiteral("1234567890000"));
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.BIGINT)));
assertThat(result.expressions(), is(ImmutableList.of(new LongLiteral(10), new LongLiteral(1234567890000L))));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToBooleans.
@Test
public void shouldCoerceToBooleans() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new BooleanLiteral(true), new StringLiteral("FaLsE"), BOOL_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.BOOLEAN)));
assertThat(result.expressions(), is(ImmutableList.of(new BooleanLiteral(true), new BooleanLiteral(false), BOOL_EXPRESSION)));
}
Aggregations