use of io.confluent.ksql.execution.expression.tree.DecimalLiteral 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.DecimalLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceStringNumericWithENotationToDecimals.
@Test
public void shouldCoerceStringNumericWithENotationToDecimals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new StringLiteral("1e3"));
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.decimal(10, 0))));
assertThat(result.expressions(), is(ImmutableList.of(new DecimalLiteral(new BigDecimal("10")), new DecimalLiteral(new BigDecimal("1000")))));
}
use of io.confluent.ksql.execution.expression.tree.DecimalLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldHandleNullKeyForSourceWithKeyField.
@Test
public void shouldHandleNullKeyForSourceWithKeyField() {
// Given:
givenSourceStreamWithSchema(BIG_SCHEMA, SerdeFeatures.of(), SerdeFeatures.of());
final ConfiguredStatement<InsertValues> statement = givenInsertValues(allAndPseudoColumnNames(BIG_SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new IntegerLiteral(0), new LongLiteral(2), new DoubleLiteral(3.0), new BooleanLiteral("TRUE"), new StringLiteral("str"), new DecimalLiteral(new BigDecimal("1.2"))));
// When:
executor.execute(statement, mock(SessionProperties.class), engine, serviceContext);
// Then:
verify(keySerializer).serialize(TOPIC_NAME, genericKey("str"));
verify(valueSerializer).serialize(TOPIC_NAME, genericRow("str", 0, 2L, 3.0, true, "str", new BigDecimal("1.2", new MathContext(2))));
verify(producer).send(new ProducerRecord<>(TOPIC_NAME, null, 1L, KEY, VALUE));
}
use of io.confluent.ksql.execution.expression.tree.DecimalLiteral in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToBigint.
@Test
public void shouldEvaluateCastToBigint() {
// Given:
final Expression cast1 = new Cast(new IntegerLiteral(10), new Type(SqlPrimitiveType.of("BIGINT")));
final Expression cast2 = new Cast(new StringLiteral("1234"), new Type(SqlPrimitiveType.of("BIGINT")));
final Expression cast3 = new Cast(new DoubleLiteral(12.5), new Type(SqlPrimitiveType.of("BIGINT")));
final Expression cast4 = new Cast(new DecimalLiteral(new BigDecimal("4567.5")), new Type(SqlPrimitiveType.of("BIGINT")));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
InterpretedExpression interpreter4 = interpreter(cast4);
// Then:
assertThat(interpreter1.evaluate(ROW), is(10L));
assertThat(interpreter2.evaluate(ROW), is(1234L));
assertThat(interpreter3.evaluate(ROW), is(12L));
assertThat(interpreter4.evaluate(ROW), is(4567L));
}
use of io.confluent.ksql.execution.expression.tree.DecimalLiteral in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToInteger.
@Test
public void shouldEvaluateCastToInteger() {
// Given:
final Expression cast1 = new Cast(new LongLiteral(10L), new Type(SqlPrimitiveType.of("INTEGER")));
final Expression cast2 = new Cast(new StringLiteral("1234"), new Type(SqlPrimitiveType.of("INTEGER")));
final Expression cast3 = new Cast(new DoubleLiteral(12.5), new Type(SqlPrimitiveType.of("INTEGER")));
final Expression cast4 = new Cast(new DecimalLiteral(new BigDecimal("4567.5")), new Type(SqlPrimitiveType.of("INTEGER")));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
InterpretedExpression interpreter4 = interpreter(cast4);
// Then:
assertThat(interpreter1.evaluate(ROW), is(10));
assertThat(interpreter2.evaluate(ROW), is(1234));
assertThat(interpreter3.evaluate(ROW), is(12));
assertThat(interpreter4.evaluate(ROW), is(4567));
}
Aggregations