use of io.confluent.ksql.execution.expression.tree.IntegerLiteral 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.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldNotCoerceMapOfIncompatibleKeyLiterals.
@Test
public void shouldNotCoerceMapOfIncompatibleKeyLiterals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), new CreateMapExpression(ImmutableMap.of(new BooleanLiteral(false), new StringLiteral("123456789000"))));
// When:
final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
// Then:
assertThat(e.getMessage(), startsWith("operator does not exist: MAP<INTEGER, INTEGER> = MAP<BOOLEAN, STRING> (MAP(false:='123456789000'))"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral 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.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldNotCoerceMapWithDifferentKeyExpression.
@Test
public void shouldNotCoerceMapWithDifferentKeyExpression() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(10))), new CreateMapExpression(ImmutableMap.of(STRING_EXPRESSION, new IntegerLiteral(10))));
// When:
final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
// Then:
assertThat(e.getMessage(), startsWith("operator does not exist: MAP<INTEGER, INTEGER> = MAP<STRING, INTEGER> (MAP(STR:=10))"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral 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())));
}
Aggregations