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

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/DataFrameNaFunctions.scala
 ##########
 @@ -456,7 +456,7 @@ 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))
+      Seq(Literal(source), buildExpr(target))
 
 Review comment:
   This fix relies on the type coercion rule to do the casting in the another 
side. It could cause the difference of query results. For example, 
   
    ```
     def createNaNDF(): DataFrame = {
       Seq[(java.lang.Integer, java.lang.Long, java.lang.Short,
         java.lang.Byte, java.lang.Float, java.lang.Double)](
         (2, 2L, 2.toShort, 2.toByte, 2.0f, 2.0)
       ).toDF("int", "long", "short", "byte", "float", "double")
     }
   
     test("replace float with double") {
       createNaNDF().na.replace("*", Map(
         2.3 -> 9.0
       )).show()
   
       createNaNDF().na.replace("*", Map(
         2.3 -> 9.0
       )).explain(true)
     }
   ```

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

Reply via email to