Github user windpiger commented on a diff in the pull request:
https://github.com/apache/spark/pull/15994#discussion_r89727312
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/DataFrameNaFunctions.scala ---
@@ -437,4 +444,38 @@ final class DataFrameNaFunctions private[sql](df:
DataFrame) {
case v => throw new IllegalArgumentException(
s"Unsupported value type ${v.getClass.getName} ($v).")
}
+
+ /**
+ * (Scala-specific) Returns a new [[DataFrame]] that replaces null or
NaN values in specified
+ * numeric, bool, string columns. If a specified column is not a
numeric, boolean, string column,
+ * it is ignored.
+ *
+ * @since 2.1.0
+ */
+ private def fill1[T](value: T, cols: Seq[String]): DataFrame = {
+ value match {
+ case _: jl.Double | _: jl.Integer | _: jl.Float | _: jl.Boolean | _:
jl.Long | _: String =>
+ case _ =>
+ throw new IllegalArgumentException(
+ s"Unsupported value type ${value.getClass.getName} ($value).")
+ }
+
+ val targetColumnType = value match {
+ case _: jl.Double | _: jl.Integer | _: jl.Float | _: jl.Long =>
NumericType
+ case _: jl.Boolean => BooleanType
+ case _: String => StringType
+ }
+
+ val columnEquals = df.sparkSession.sessionState.analyzer.resolver
+ val projections = df.schema.fields.map { f =>
+ // Only fill if the column is part of the cols list.
+ if (((f.dataType.isInstanceOf[NumericType] && targetColumnType ==
NumericType)
--- End diff --
Thanks!
I have modified except one:
If T is a double type , this should be apply to all Numeric columns(include
LongType/IntegerType), or just apply to FractionType?
The fill(value Double) apply to all Numeric columns, and I think fill(value
Long) also keep the logic.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]