use of io.confluent.ksql.execution.expression.tree.DoubleLiteral 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;
}
Aggregations