use of io.confluent.ksql.execution.expression.tree.LongLiteral 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!'"));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatCast.
@Test
public void shouldFormatCast() {
// Given:
final Cast cast = new Cast(new LongLiteral(1), new Type(SqlTypes.DOUBLE));
// When:
final String result = ExpressionFormatter.formatExpression(cast);
// Then:
assertThat(result, equalTo("CAST(1 AS DOUBLE)"));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class ImplicitlyCastResolver method resolveToDecimal.
@SuppressWarnings("CyclomaticComplexiIntegerLiteralty")
private static Expression resolveToDecimal(final Expression expression, final SqlDecimal toDecimalType) {
final BigDecimal literalValue;
if (expression instanceof IntegerLiteral) {
literalValue = BigDecimal.valueOf(((IntegerLiteral) expression).getValue());
} else if (expression instanceof LongLiteral) {
literalValue = BigDecimal.valueOf(((LongLiteral) expression).getValue());
} else if (expression instanceof DoubleLiteral) {
literalValue = BigDecimal.valueOf(((DoubleLiteral) expression).getValue());
} else if (expression instanceof DecimalLiteral) {
literalValue = ((DecimalLiteral) expression).getValue();
} else {
return expression;
}
final SqlDecimal fromDecimalType = (SqlDecimal) DecimalUtil.fromValue(literalValue);
if (DecimalUtil.canImplicitlyCast(fromDecimalType, toDecimalType)) {
return new DecimalLiteral(expression.getLocation(), DecimalUtil.cast(literalValue, toDecimalType.getPrecision(), toDecimalType.getScale()));
}
return expression;
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class LiteralUtilTest method shouldThrowConvertingOtherLiteralTypesToBoolean.
@Test
public void shouldThrowConvertingOtherLiteralTypesToBoolean() {
// When:
final Exception e = assertThrows(KsqlException.class, () -> LiteralUtil.toBoolean(new LongLiteral(10), "bob"));
// Then:
assertThat(e.getMessage(), containsString("Property 'bob' is not a boolean value"));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class GroupByParamsFactoryTest method shouldGenerateKeyNameFromOtherExpressionType.
@Test
public void shouldGenerateKeyNameFromOtherExpressionType() {
// Given:
when(groupBy0.getExpression()).thenReturn(new LongLiteral(1));
// When:
final LogicalSchema schema = GroupByParamsFactory.buildSchema(SOURCE_SCHEMA, ImmutableList.of(groupBy0, groupBy1));
// Then:
assertThat(schema, is(LogicalSchema.builder().keyColumn(ColumnName.of("KSQL_COL_1"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K1"), SqlTypes.INTEGER).valueColumns(SOURCE_SCHEMA.value()).build()));
}
Aggregations