maropu commented on a change in pull request #31769:
URL: https://github.com/apache/spark/pull/31769#discussion_r589205084
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameNaFunctionsSuite.scala
##########
@@ -485,4 +485,25 @@ class DataFrameNaFunctionsSuite extends QueryTest with
SharedSparkSession {
.na.fill(Map("Col" -> na)),
Row("abc", 23) :: Row("def", 44L) :: Row(na, 0L) :: Nil)
}
+
+ test("SPARK-34649 - replace value of a column with dot in the name") {
Review comment:
nit: `SPARK-34649:`
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameNaFunctionsSuite.scala
##########
@@ -485,4 +485,25 @@ class DataFrameNaFunctionsSuite extends QueryTest with
SharedSparkSession {
.na.fill(Map("Col" -> na)),
Row("abc", 23) :: Row("def", 44L) :: Row(na, 0L) :: Nil)
}
+
+ test("SPARK-34649 - replace value of a column with dot in the name") {
+ checkAnswer(
+ Seq(("abc", 23), ("def", 44), ("n/a", 0)).toDF("Col.1", "Col.2")
+ .na.replace("`Col.1`", Map( "n/a" -> "unknown")),
+ Row("abc", 23) :: Row("def", 44L) :: Row("unknown", 0L) :: Nil)
+ }
+
+ test("SPARK-34649 - replace value of a qualified-column with dot in the
name") {
Review comment:
ditto
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameNaFunctionsSuite.scala
##########
@@ -485,4 +485,25 @@ class DataFrameNaFunctionsSuite extends QueryTest with
SharedSparkSession {
.na.fill(Map("Col" -> na)),
Row("abc", 23) :: Row("def", 44L) :: Row(na, 0L) :: Nil)
}
+
+ test("SPARK-34649 - replace value of a column with dot in the name") {
+ checkAnswer(
+ Seq(("abc", 23), ("def", 44), ("n/a", 0)).toDF("Col.1", "Col.2")
+ .na.replace("`Col.1`", Map( "n/a" -> "unknown")),
+ Row("abc", 23) :: Row("def", 44L) :: Row("unknown", 0L) :: Nil)
+ }
+
+ test("SPARK-34649 - replace value of a qualified-column with dot in the
name") {
+ checkAnswer(
+ Seq(("abc", 23), ("def", 44), ("n/a", 0)).toDF("Col.1",
"Col.2").as("testDf")
+ .na.replace("testDf.`Col.1`", Map( "n/a" -> "unknown")),
+ Row("abc", 23) :: Row("def", 44L) :: Row("unknown", 0L) :: Nil)
+ }
+
+ test("SPARK-34649 - replace value of a dataframe having dot in the all
column names") {
Review comment:
ditto
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/DataFrameNaFunctions.scala
##########
@@ -359,6 +359,16 @@ final class DataFrameNaFunctions private[sql](df:
DataFrame) {
return df
}
+ val replaceableAttrs = AttributeSet(cols.map { colName =>
+ // Check column name exists
+ val attr = df.resolve(colName) match {
+ case a: Attribute => a
+ case _ => throw new UnsupportedOperationException(
+ s"Nested field ${colName} is not supported.")
Review comment:
The current behaviour just ignores input if given columns do not exist?
```
scala> df.na.replace("xxx", Map("n/a" -> "Unknown")).show()
+---+---+
| c0| c1|
+---+---+
|abc| 23|
|def| 44|
|n/a| 0|
+---+---+
```
----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]