[
https://issues.apache.org/jira/browse/FLINK-3749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15240980#comment-15240980
]
ASF GitHub Bot commented on FLINK-3749:
---------------------------------------
Github user twalthr commented on a diff in the pull request:
https://github.com/apache/flink/pull/1881#discussion_r59699195
--- 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 --
No, thats a different issue. The `ExpressionParser` needs a large rework
for all that.
> Improve decimal handling
> ------------------------
>
> Key: FLINK-3749
> URL: https://issues.apache.org/jira/browse/FLINK-3749
> Project: Flink
> Issue Type: Bug
> Components: Table API
> Reporter: Timo Walther
> Assignee: Timo Walther
>
> The current decimal handling is too restrictive and does not allow literals
> such as "11.2".
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)