use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToIntsToDecimals.
@Test
public void shouldCoerceToIntsToDecimals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new DecimalLiteral(new BigDecimal("1.1")), new IntegerLiteral(10), INT_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
final SqlDecimal decimalType = SqlTypes.decimal(11, 1);
assertThat(result.commonType(), is(Optional.of(decimalType)));
assertThat(result.expressions(), is(ImmutableList.of(new DecimalLiteral(new BigDecimal("1.1")), new DecimalLiteral(new BigDecimal("10.0")), cast(INT_EXPRESSION, decimalType))));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldNotCoerceMapWithDifferentValueExpression.
@Test
public void shouldNotCoerceMapWithDifferentValueExpression() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(10))), new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), STRING_EXPRESSION)));
// When:
final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
// Then:
assertThat(e.getMessage(), startsWith("operator does not exist: MAP<INTEGER, INTEGER> = MAP<INTEGER, STRING> (MAP(10:=STR))"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldNotCoerceArrayOfIncompatibleLiterals.
@Test
public void shouldNotCoerceArrayOfIncompatibleLiterals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateArrayExpression(ImmutableList.of(new IntegerLiteral(10))), new CreateArrayExpression(ImmutableList.of(new BooleanLiteral(false))));
// When:
final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
// Then:
assertThat(e.getMessage(), startsWith("operator does not exist: ARRAY<INTEGER> = ARRAY<BOOLEAN> (ARRAY[false])"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceArrayOfCompatibleLiterals.
@Test
public void shouldCoerceArrayOfCompatibleLiterals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateArrayExpression(ImmutableList.of(new IntegerLiteral(10), new IntegerLiteral(289476))), new CreateArrayExpression(ImmutableList.of(new StringLiteral("123456789000"), new StringLiteral("22"), new StringLiteral("\t -100 \t"))));
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.array(SqlTypes.BIGINT))));
assertThat(result.expressions(), is(ImmutableList.of(cast(new CreateArrayExpression(ImmutableList.of(new IntegerLiteral(10), new IntegerLiteral(289476))), SqlTypes.array(SqlTypes.BIGINT)), cast(new CreateArrayExpression(ImmutableList.of(new StringLiteral("123456789000"), new StringLiteral("22"), new StringLiteral("\t -100 \t"))), SqlTypes.array(SqlTypes.BIGINT)))));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldNotCoerceStringExpressionToNumber.
@Test
public void shouldNotCoerceStringExpressionToNumber() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), STRING_EXPRESSION);
// When:
final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
// Then:
assertThat(e.getMessage(), startsWith("operator does not exist: INTEGER = STRING (STR)"));
}
Aggregations