Github user maropu commented on a diff in the pull request:
https://github.com/apache/spark/pull/17848#discussion_r116891635
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/UDFRegistration.scala ---
@@ -115,6 +115,22 @@ class UDFRegistration private[sql] (functionRegistry:
FunctionRegistry) extends
def builder(e: Seq[Expression]) = ScalaUDF(func, dataType, e,
inputTypes.getOrElse(Nil), Some(name), nullable)
functionRegistry.registerFunction(name, builder)
UserDefinedFunction(func, dataType,
inputTypes).withName(name).withNullability(nullable)
--- End diff --
I probably miss your point though, I suggested code below;
```
/**
* Registers a Scala closure of 0 arguments as user-defined function
(UDF).
* @tparam RT return type of UDF.
* @since 1.3.0
*/
def register[RT: TypeTag](name: String, func: Function0[RT]):
UserDefinedFunction = {
register(name, func, deterministic = true, distinctLike = false)
}
/**
* Registers a Scala closure of 0 arguments as user-defined function
(UDF).
* @tparam RT return type of UDF.
* @since 2.3.0
*/
def register[RT: TypeTag](name: String, func: Function0[RT],
deterministic: Boolean, distinctLike: Boolean): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(Nil).toOption
def builder(e: Seq[Expression]) = ScalaUDF(func, dataType, e,
inputTypes.getOrElse(Nil), Some(name), nullable, deterministic, distinctLike)
functionRegistry.registerFunction(name, builder)
val udf = UserDefinedFunction(func, dataType,
inputTypes).withName(name).withNullability(nullable)
val withDeterminism = if (!deterministic) udf.nonDeterministic() else
udf
val withDistinctLike = if (distinctLike)
withDeterminism.withDistinctLike() else withDeterminism
withDistinctLike
}
```
---
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]