gengliangwang opened a new pull request #25300: [SPARK-28503] Return null result on cast an out-of-range value to a integral type URL: https://github.com/apache/spark/pull/25300 ## What changes were proposed in this pull request? Currently, when we convert an out-of-range value to a numeric type, the value is unexpected ``` scala> spark.sql("select cast(1234567890 as short)").show() +----------------------------+ |CAST(1234567890 AS SMALLINT)| +----------------------------+ | 722| +----------------------------+ ``` The result is actually `1234567890.toShort` (1234567890 & 0xffff). The issue exists in all the integral types: Byte/Short/Int/Long. In the current implementation of `Cast`, if the value is too big to fit in an integral type, only the low-order bits are returned. For Float/Double type, the value is converted as `PositiveInfinity` or `NegativeInfinity` on overflow. We can keep the current behavior. This PR is to convert out-of-range integral type castings to null results. ## How was this patch tested? 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]
