Skip to content

Commit 9f523d3

Browse files
maropugatorsmile
authored andcommitted
[SPARK-19338][SQL] Add UDF names in explain
## What changes were proposed in this pull request? This pr added a variable for a UDF name in `ScalaUDF`. Then, if the variable filled, `DataFrame#explain` prints the name. ## How was this patch tested? Added a test in `UDFSuite`. Author: Takeshi YAMAMURO <linguin.m.s@gmail.com> Closes #16707 from maropu/SPARK-19338.
1 parent 2969fb4 commit 9f523d3

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ class Analyzer(
20712071

20722072
case p => p transformExpressionsUp {
20732073

2074-
case udf @ ScalaUDF(func, _, inputs, _) =>
2074+
case udf @ ScalaUDF(func, _, inputs, _, _) =>
20752075
val parameterTypes = ScalaReflection.getParameterTypes(func)
20762076
assert(parameterTypes.length == inputs.length)
20772077

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ScalaUDF.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ import org.apache.spark.sql.types.DataType
3535
* not want to perform coercion, simply use "Nil". Note that it would've been
3636
* better to use Option of Seq[DataType] so we can use "None" as the case for no
3737
* type coercion. However, that would require more refactoring of the codebase.
38+
* @param udfName The user-specified name of this UDF.
3839
*/
3940
case class ScalaUDF(
4041
function: AnyRef,
4142
dataType: DataType,
4243
children: Seq[Expression],
43-
inputTypes: Seq[DataType] = Nil)
44+
inputTypes: Seq[DataType] = Nil,
45+
udfName: Option[String] = None)
4446
extends Expression with ImplicitCastInputTypes with NonSQLExpression {
4547

4648
override def nullable: Boolean = true
4749

48-
override def toString: String = s"UDF(${children.mkString(", ")})"
50+
override def toString: String =
51+
s"${udfName.map(name => s"UDF:$name").getOrElse("UDF")}(${children.mkString(", ")})"
4952

5053
// scalastyle:off line.size.limit
5154

0 commit comments

Comments
 (0)