You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/08/02 12:44:38 UTC

[GitHub] [spark] kiszk commented on a change in pull request #25300: [SPARK-28503][SQL] Return null result on cast an out-of-range value to a integral type

kiszk commented on a change in pull request #25300: [SPARK-28503][SQL] Return null result on cast an out-of-range value to a integral type
URL: https://github.com/apache/spark/pull/25300#discussion_r310113589
 
 

 ##########
 File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ##########
 @@ -442,8 +443,38 @@ case class Cast(child: Expression, dataType: DataType, timeZoneId: Option[String
       buildCast[Int](_, d => null)
     case TimestampType =>
       buildCast[Long](_, t => timestampToLong(t))
-    case x: NumericType =>
-      b => x.numeric.asInstanceOf[Numeric[Any]].toLong(b)
+    case ByteType =>
+      b => b.asInstanceOf[Byte].toLong
+    case ShortType =>
+      b => b.asInstanceOf[Short].toLong
+    case IntegerType =>
+      b => b.asInstanceOf[Int].toLong
 
 Review comment:
   In summary, I think that this slightly improve improve performance.
   
   My guess (I have not seen generated code by HotSpot) is that this cast (e.g. `b.asInstanceOf[Int]`) removes table lookup of invocation of `toLong`. As a result, we expect the code in `toLong` is inlined to caller. On the other hand, the original code (`asInstanceOf[Numeric[Any]].toLong(b)`) has a table lookup for invoking `toLong`. Thus, it is not expected to apply inlining.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org