maropu 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_r311317299
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -562,8 +593,12 @@ case class Cast(child: Expression, dataType: DataType,
timeZoneId: Option[String
// FloatConverter
private[this] def castToFloat(from: DataType): Any => Any = from match {
case StringType =>
- buildCast[UTF8String](_, s => try s.toString.toFloat catch {
- case _: NumberFormatException => null
+ buildCast[UTF8String](_, s => {
+ val floatStr = s.toString
+ try floatStr.toFloat catch {
+ case _: NumberFormatException =>
Review comment:
Could we check the numbers by a simple query?, e.g.,
```
scala> spark.range(10).selectExpr("CAST(double(id) AS STRING)
a").write.save("/tmp/test")
scala> spark.read.load("/tmp/test").selectExpr("CAST(a AS
DOUBLE)").write.format("noop").save()
```
In another pr, I observed that a logic depending on exceptions cause high
performance penalties: https://github.com/lz4/lz4-java/pull/143
So, I'm a bit worried that this current logic has the same issue.
----------------------------------------------------------------
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]