use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldHandleEmpty.
@Test
public void shouldHandleEmpty() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of();
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.empty()));
assertThat(result.expressions(), is(ImmutableList.of()));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result 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.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldHandleSomeNulls.
@Test
public void shouldHandleSomeNulls() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new NullLiteral(), new IntegerLiteral(10), new NullLiteral(), new LongLiteral(20L), new NullLiteral());
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.BIGINT)));
assertThat(result.expressions(), is(ImmutableList.of(new NullLiteral(), new LongLiteral(10), new NullLiteral(), new LongLiteral(20L), new NullLiteral())));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceMapOfCompatibleLiterals.
@Test
public void shouldCoerceMapOfCompatibleLiterals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), new CreateMapExpression(ImmutableMap.of(new StringLiteral("123456789000"), new StringLiteral("\t -100 \t"))));
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER))));
assertThat(result.expressions(), is(ImmutableList.of(cast(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER)), cast(new CreateMapExpression(ImmutableMap.of(new StringLiteral("123456789000"), new StringLiteral("\t -100 \t"))), SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER)))));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceLambdaVariables.
@Test
public void shouldCoerceLambdaVariables() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(BIGINT_EXPRESSION, new LambdaVariable("X"), INT_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager, Collections.singletonMap("X", SqlTypes.INTEGER));
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.BIGINT)));
assertThat(result.expressions(), is(ImmutableList.of(BIGINT_EXPRESSION, cast(new LambdaVariable("X"), SqlTypes.BIGINT), cast(INT_EXPRESSION, SqlTypes.BIGINT))));
}
Aggregations