Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/12036#discussion_r57802797
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala ---
@@ -86,13 +87,50 @@ case class DescribeDatabase(
extended: Boolean)(sql: String)
extends NativeDDLCommand(sql) with Logging
+/**
+ * The DDL command that creates a function.
+ * alias: the class name that implements the created function.
+ * resources: Jars, files, or archives which need to be added to the
environment when the function
+ * is referenced for the first time by a session.
+ * isTemp: indicates if it is a temporary function.
+ */
case class CreateFunction(
databaseName: Option[String],
functionName: String,
alias: String,
resources: Seq[(String, String)],
isTemp: Boolean)(sql: String)
- extends NativeDDLCommand(sql) with Logging
+ extends NativeDDLCommand(sql) with Logging {
+
+ override def run(sqlContext: SQLContext): Seq[Row] = {
+ val func = FunctionIdentifier(functionName, databaseName)
+ val catalogFunc = CatalogFunction(func, alias)
+ if (isTemp) {
+ // Set `ignoreIfExists` to false, so if the temporary function
already exists,
+ // an exception will be thrown.
+ val (info, builder) =
+
sqlContext.sessionState.functionRegistry.getFunctionBuilderAndInfo(functionName,
alias)
+ sqlContext.sessionState.catalog.createTempFunction(functionName,
info, builder, false)
--- End diff --
This is very confusing; We're supposed to be creating a new temporary
function but somehow we just get it from the function registry assuming it's
already there. It seems that `getFunctionBuilderAndInfo` doesn't actually "get"
the function, but also creates a new one and registers it. This doesn't seem
like the right way to approach this.
---
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]