turboFei opened a new pull request #27151: SPARK-26218: [Follow up] throw 
exception on overflow for integers
URL: https://github.com/apache/spark/pull/27151
 
 
   ### What changes were proposed in this pull request?
   When spark.sql.ansi.enabled is true, for the statement:
   ```
   select cast(cast(2147483648 as Float) as Integer) //result is 2147483647
   ```
   Its result is 2147483647 and does not throw `ArithmeticException`.
   
   The root cause is that:
   
https://github.com/apache/spark/blob/94fc0e3235162afc6038019eed6ec546e3d1983e/sql/catalyst/src/main/scala/org/apache/spark/sql/types/numerics.scala#L129-L141
   
   But it does not work.
   For example:
   
   
![image](https://user-images.githubusercontent.com/6757692/72074911-badfde80-332d-11ea-963e-2db0e43c33e8.png)
   
   In this PR, I fix it my compare Math.floor(x) with Int.MaxValue directly.
   
   ### Why are the changes needed?
   Result corrupt.
   
   
   ### Does this PR introduce any user-facing change?
   No
   
   
   ### How was this patch tested?
   
   Added Unit test.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to