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/01 21:51:15 UTC

[GitHub] [spark] dongjoon-hyun commented on a change in pull request #25331: [SPARK-27768][SQL] Infinity, -Infinity, NaN should be recognized in a case insensitive manner.

dongjoon-hyun commented on a change in pull request #25331: [SPARK-27768][SQL] Infinity, -Infinity, NaN should be recognized in a case insensitive manner.
URL: https://github.com/apache/spark/pull/25331#discussion_r309911639
 
 

 ##########
 File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ##########
 @@ -563,7 +573,17 @@ case class Cast(child: Expression, dataType: DataType, timeZoneId: Option[String
   private[this] def castToFloat(from: DataType): Any => Any = from match {
     case StringType =>
       buildCast[UTF8String](_, s => try s.toString.toFloat catch {
-        case _: NumberFormatException => null
+        case _: NumberFormatException =>
+          val str = s.trim.toString
+          if (str.equalsIgnoreCase("infinity")) {
+            Float.PositiveInfinity
+          } else if (str.equalsIgnoreCase("-infinity")) {
+            Float.NegativeInfinity
+          } else if (str.equalsIgnoreCase("nan")) {
+            Float.NaN
+          } else {
+            null
+          }
 
 Review comment:
   To avoid duplications, shall we make a function for this since we have the same `Float` logic twice here and line 1268?

----------------------------------------------------------------
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