use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldFailOnDowncast.
@Test
public void shouldFailOnDowncast() {
// Given:
givenSourceStreamWithSchema(BIG_SCHEMA, SerdeFeatures.of(), SerdeFeatures.of());
final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(INT_COL), ImmutableList.of(new DoubleLiteral(1.1)));
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getCause(), (hasMessage(containsString("Expected type INTEGER for field"))));
}
use of io.confluent.ksql.execution.expression.tree.DoubleLiteral 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.DoubleLiteral 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));
}
use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateUnaryArithmetic.
@Test
public void shouldEvaluateUnaryArithmetic() {
// Given:
final Expression expression1 = new ArithmeticUnaryExpression(Optional.empty(), Sign.PLUS, new IntegerLiteral(1));
final Expression expression2 = new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new IntegerLiteral(1));
final Expression expression3 = new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new DecimalLiteral(new BigDecimal("345.5")));
final Expression expression4 = new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new DoubleLiteral(45.5d));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
InterpretedExpression interpreter3 = interpreter(expression3);
InterpretedExpression interpreter4 = interpreter(expression4);
// Then:
assertThat(interpreter1.evaluate(ROW), is(1));
assertThat(interpreter2.evaluate(ROW), is(-1));
assertThat(interpreter3.evaluate(ROW), is(new BigDecimal("-345.5")));
assertThat(interpreter4.evaluate(ROW), is(-45.5d));
}
use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.
the class UdafUtilTest method shouldThrowIfSubsequentParamsAreNotLiteral.
@Test
public void shouldThrowIfSubsequentParamsAreNotLiteral() {
// Given:
when(functionCall.getArguments()).thenReturn(ImmutableList.of(new UnqualifiedColumnReferenceExp(ColumnName.of("Bob")), new LongLiteral(10), new DoubleLiteral(1.0), new UnqualifiedColumnReferenceExp(ColumnName.of("Not good!"))));
// When:
final Exception e = assertThrows(KsqlException.class, () -> UdafUtil.createAggregateFunctionInitArgs(0, functionCall, KsqlConfig.empty()));
// Then:
assertThat(e.getMessage(), is("Parameter 4 passed to function AGG must be a literal constant, " + "but was expression: 'Not good!'"));
}
Aggregations