imback82 commented on a change in pull request #26593: [SPARK-29890][SQL] 
DataFrameNaFunctions.fill should handle duplicate columns
URL: https://github.com/apache/spark/pull/26593#discussion_r349715065
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/DataFrameNaFunctionsSuite.scala
 ##########
 @@ -266,6 +267,32 @@ class DataFrameNaFunctionsSuite extends QueryTest with 
SharedSparkSession {
     assert(message.contains("Reference 'f2' is ambiguous"))
   }
 
+  test("fill with col(*)") {
+    val df = createDF()
+    // If columns are specified with "*", they are ignored.
+    checkAnswer(df.na.fill("new name", Seq("*")), df.collect())
+  }
+
+  test("fill with nested columns") {
+    val schema = new StructType()
+      .add("c1", new StructType()
+        .add("c1-1", StringType)
+        .add("c1-2", StringType))
+
+    val data = Seq(
+      Row(Row(null, "a2")),
+      Row(Row("b1", "b2")))
+
+    val df = spark.createDataFrame(
+      spark.sparkContext.parallelize(data), schema)
+
+    checkAnswer(df.select("c1.c1-1"),
+      Row(null) :: Row("b1") :: Nil)
+
+    // Nested columns are ignored for fill().
+    checkAnswer(df.na.fill("a1", Seq("c1.c1-1")), data)
 
 Review comment:
   This example works fine, and you also need to update the previous line to:
   ```
   checkAnswer(df.select("c1.c1-1"),
     Row(null) :: Row("b1") :: Row(null) :: Nil)
   ```
   (This is just to illustrate the nested type, but I can remove it if you 
think it's confusing.)
   
   The reason the nested types are ignored is the following check:
   ```Scala
     case (NumericType, dt) => dt.isInstanceOf[NumericType]
     case (StringType, dt) => dt == StringType
     case (BooleanType, dt) => dt == BooleanType
   ```
   The datatype for the nested column that is resolved to `Attribute` is 
`StructType`, so this will not be matched.
   

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