You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flink.apache.org by "Ada Wong (Jira)" <ji...@apache.org> on 2021/12/23 12:53:00 UTC
[jira] [Created] (FLINK-25434) Throw an error when BigDecimal precision overflows.
Ada Wong created FLINK-25434:
--------------------------------
Summary: Throw an error when BigDecimal precision overflows.
Key: FLINK-25434
URL: https://issues.apache.org/jira/browse/FLINK-25434
Project: Flink
Issue Type: Bug
Components: Table SQL / Planner, Table SQL / Runtime
Affects Versions: 1.14.2
Reporter: Ada Wong
Lost a lot of data but no error was thrown.
As the following comment, If the precision overflows, null will be returned.
{code:java}
/**
If the precision overflows, null will be returned.
*/
public static @Nullable DecimalData fromBigDecimal(BigDecimal bd, int precision, int scale) {
bd = bd.setScale(scale, RoundingMode.HALF_UP);
if (bd.precision() > precision) {
return null;
}
long longVal = -1;
if (precision <= MAX_COMPACT_PRECISION) {
longVal = bd.movePointRight(scale).longValueExact();
}
return new DecimalData(precision, scale, longVal, bd);
} {code}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)