cast from bigdecimal to bigint throws ArithmeticException

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

cast from bigdecimal to bigint throws ArithmeticException

徐涛
Hi Experts,
        There is a Flink table which has a column typed as java.math.BigDecimal, then in SQL I try to cast it to type long,
        cast(duration as bigint)

        however it throws the following exception:
java.lang.ArithmeticException: Rounding necessary
        at java.math.BigDecimal.commonNeedIncrement(BigDecimal.java:4148)
        at java.math.BigDecimal.needIncrement(BigDecimal.java:4204)
        at java.math.BigDecimal.divideAndRound(BigDecimal.java:4112)
        at java.math.BigDecimal.setScale(BigDecimal.java:2452)
        at java.math.BigDecimal.longValueExact(BigDecimal.java:3090)
        at DataStreamCalcRule$45.processElement(Unknown Source)
        at org.apache.flink.table.runtime.CRowProcessRunner.processElement(CRowProcessRunner.scala:66)
        at org.apache.flink.table.runtime.CRowProcessRunner.processElement(CRowProcessRunner.scala:35)
        at org.apache.flink.streaming.api.operators.ProcessOperator.processElement(ProcessOperator.java:66)

        I wonder if it is not possible to cast java.math.BigDecimal to Long at runtime, is there anyway to achieve the cast?
        Thanks a lot !

Best
Henry