Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/12036#discussion_r57770133
--- 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)
+ } else {
+ // Check if the function to create is already existing. If so, throw
exception.
+ var funcExisting: Boolean = true
+ try {
+ if (sqlContext.sessionState.catalog.getFunction(func) == null) {
+ funcExisting = false
+ }
+ } catch {
+ case _: NoSuchFunctionException => funcExisting = false
+ }
--- End diff --
this is pretty round about way to write it. You can simplify this:
```
val funcExists =
try {
sqlContext.sessionState.catalog.getFunction(func) != null
} catch {
case _: NoSuchFunctionException => false
}
```
---
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]