use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldProcessCreateArrayExpressionCorrectly.
@Test
public void shouldProcessCreateArrayExpressionCorrectly() {
// Given:
Expression expression = new CreateArrayExpression(ImmutableList.of(new SubscriptExpression(MAPCOL, new StringLiteral("key1")), new DoubleLiteral(1.0d)));
// When:
String java = sqlToJavaVisitor.process(expression);
// Then:
assertThat(java, equalTo("((List)new ArrayBuilder(2)" + ".add( (new Supplier<Object>() {@Override public Object get() { try { return ((Double) ((java.util.Map)COL5).get(\"key1\")); } catch (Exception e) { " + onException("array item") + " }}}).get())" + ".add( (new Supplier<Object>() {@Override public Object get() { try { return 1E0; } catch (Exception e) { " + onException("array item") + " }}}).get()).build())"));
}
use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToDoubles.
@Test
public void shouldCoerceToDoubles() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new LongLiteral(1234567890), new DoubleLiteral(123.456), new StringLiteral("\t -100.010 \t"), BIGINT_EXPRESSION, DECIMAL_EXPRESSION, INT_EXPRESSION, DOUBLE_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.DOUBLE)));
assertThat(result.expressions(), is(ImmutableList.of(new DoubleLiteral(10.0), new DoubleLiteral(1234567890.0), new DoubleLiteral(123.456), new DoubleLiteral(-100.01), cast(BIGINT_EXPRESSION, SqlTypes.DOUBLE), cast(DECIMAL_EXPRESSION, SqlTypes.DOUBLE), cast(INT_EXPRESSION, SqlTypes.DOUBLE), DOUBLE_EXPRESSION)));
}
use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForComparisonWithNegativeNumbers.
@Test
public void shouldGenerateCorrectCodeForComparisonWithNegativeNumbers() {
// Given:
final Expression expression = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL3, new DoubleLiteral(-10.0));
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// Then:
assertThat(javaExpression, equalTo("((((Object)(COL3)) == null || ((Object)(-1E1)) == null) ? false : (COL3 > -1E1))"));
}
use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.
the class FunctionArgumentsUtilTest method shouldResolveLambdaWithoutGenerics.
@Test
public void shouldResolveLambdaWithoutGenerics() {
// Given:
givenUdfWithNameAndReturnType("SmallLambda", SqlTypes.DOUBLE);
when(function.parameters()).thenReturn(ImmutableList.of(ArrayType.of(ParamTypes.DOUBLE), LambdaType.of(ImmutableList.of(ParamTypes.INTEGER), ParamTypes.INTEGER)));
final FunctionCall expression = new FunctionCall(FunctionName.of("SmallLambda"), ImmutableList.of(ARRAYCOL, new LambdaFunctionCall(ImmutableList.of("2.3"), new ArithmeticBinaryExpression(Operator.ADD, new DoubleLiteral(2.3), new DoubleLiteral(2.3)))));
// When:
final FunctionTypeInfo argumentsAndContexts = FunctionArgumentsUtil.getFunctionTypeInfo(expressionTypeManager, expression, udfFactory, Collections.emptyMap());
// Then:
assertThat(argumentsAndContexts.getReturnType(), is(SqlTypes.DOUBLE));
assertThat(argumentsAndContexts.getArgumentInfos().size(), is(2));
verify(udfFactory).getFunction(ImmutableList.of(SqlArgument.of(SqlTypes.array(SqlTypes.DOUBLE)), SqlArgument.of(SqlLambda.of(1))));
verify(function).getReturnType(ImmutableList.of(SqlArgument.of(SqlTypes.array(SqlTypes.DOUBLE)), SqlArgument.of(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.INTEGER), SqlTypes.DOUBLE))));
}
use of io.confluent.ksql.execution.expression.tree.DoubleLiteral 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));
}
Aggregations