Github user ramkrish86 commented on a diff in the pull request:
https://github.com/apache/flink/pull/1881#discussion_r59661849
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/CodeGenerator.scala
---
@@ -551,23 +551,27 @@ class CodeGenerator(
case BIGINT =>
val decimal = BigDecimal(value.asInstanceOf[java.math.BigDecimal])
if (decimal.isValidLong) {
- generateNonNullLiteral(resultType, decimal.longValue().toString)
+ generateNonNullLiteral(resultType, decimal.longValue().toString
+ "L")
}
else {
throw new CodeGenException("Decimal can not be converted to
long.")
}
case FLOAT =>
val decimal = BigDecimal(value.asInstanceOf[java.math.BigDecimal])
- if (decimal.isValidFloat) {
- generateNonNullLiteral(resultType, decimal.floatValue().toString
+ "f")
+ // check if we loose/change digits when converting to float
+ val converted = BigDecimal(decimal.floatValue().toString)
+ if (converted == decimal) {
+ generateNonNullLiteral(resultType, converted.toString + "f")
}
else {
throw new CodeGenException("Decimal can not be converted to
float.")
}
- case DOUBLE =>
+ case DOUBLE | DECIMAL =>
val decimal = BigDecimal(value.asInstanceOf[java.math.BigDecimal])
- if (decimal.isValidDouble) {
- generateNonNullLiteral(resultType,
decimal.doubleValue().toString)
+ // check if we loose/change digits when converting to double
+ val converted = BigDecimal(decimal.doubleValue().toString)
--- End diff --
So with this change all the 11.CAST(STRING) and 11.abs() all should work
right?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---