cloud-fan commented on a change in pull request #26738: [SPARK-30082][SQL] Do not replace Zeros when replacing NaNs URL: https://github.com/apache/spark/pull/26738#discussion_r353008601
########## File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameNaFunctions.scala ########## @@ -456,11 +456,23 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) { val keyExpr = df.col(col.name).expr def buildExpr(v: Any) = Cast(Literal(v), keyExpr.dataType) val branches = replacementMap.flatMap { case (source, target) => - Seq(buildExpr(source), buildExpr(target)) + if (isNaN(source) || isNaN(target)) { + col.dataType match { + case IntegerType | LongType | ShortType | ByteType => Seq.empty Review comment: checked with scala ``` scala> Float.NaN == 0 res0: Boolean = false scala> Float.NaN.toInt == 0 res1: Boolean = true ``` This is also true in Spark. When comparing float and int, we cast int to float to compare, so `NaN != 0`. I think it's a bug that we cast the value to the column type and compare. We shouldn't do any cast and let the type coercion rules to do proper cast for `CaseKeyWhen` ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org