Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,11 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
val quotedColName = "`" + col.name + "`"
val colValue = col.dataType match {
case DoubleType | FloatType =>
nanvl(df.col(quotedColName), lit(null)) // nanvl only supports these types
// nanvl only supports these types
nanvl(df.col(quotedColName), lit(null).cast(col.dataType))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good change, but the test case is missing. To ensure this will not be changed by others in the future, could you also add another test case? For example,

    checkAnswer(
      Seq[(java.lang.Long, java.lang.Float)]((null, 3.14f), (9123146099426677101L, null),
        (9123146560113991650L, 1.6f), (null, null)).toDF("a", "b").na.fill(0.2),
      Row(0, 3.14f) :: Row(9123146099426677101L, 0.2f) :: Row(9123146560113991650L, 1.6f)
        :: Row(0, 0.2f) :: Nil
    )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The float one is covered by another test in fill with map, but still nice to have them explicitly to avoid being changed unexpectedly.

case _ => df.col(quotedColName)
}
coalesce(colValue, lit(replacement)).cast(col.dataType).as(col.name)
coalesce(colValue, lit(replacement).cast(col.dataType)).as(col.name)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSQLContext {
Row(1, 2) :: Row(-1, -2) :: Row(9123146099426677101L, 9123146560113991650L) :: Nil
)

checkAnswer(
Seq[(java.lang.Long, java.lang.Double)]((null, 3.14), (9123146099426677101L, null),
(9123146560113991650L, 1.6), (null, null)).toDF("a", "b").na.fill(0.2),
Row(0, 3.14) :: Row(9123146099426677101L, 0.2) :: Row(9123146560113991650L, 1.6)
:: Row(0, 0.2) :: Nil
)

checkAnswer(
Seq[(java.lang.Long, java.lang.Float)]((null, 3.14f), (9123146099426677101L, null),
(9123146560113991650L, 1.6f), (null, null)).toDF("a", "b").na.fill(0.2),
Row(0, 3.14f) :: Row(9123146099426677101L, 0.2f) :: Row(9123146560113991650L, 1.6f)
:: Row(0, 0.2f) :: Nil
)

checkAnswer(
Seq[(java.lang.Long, java.lang.Double)]((null, 1.23), (3L, null), (4L, 3.45))
.toDF("a", "b").na.fill(2.34),
Expand Down