aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
diff options
context:
space:
mode:
Diffstat (limited to 'sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala31
1 files changed, 14 insertions, 17 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
index faedf5f91c..1417bccf65 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
@@ -1050,7 +1050,7 @@ class SessionCatalog(
*
* This performs reflection to decide what type of [[Expression]] to return in the builder.
*/
- def makeFunctionBuilder(name: String, functionClassName: String): FunctionBuilder = {
+ protected def makeFunctionBuilder(name: String, functionClassName: String): FunctionBuilder = {
// TODO: at least support UDAFs here
throw new UnsupportedOperationException("Use sqlContext.udf.register(...) instead.")
}
@@ -1064,18 +1064,20 @@ class SessionCatalog(
}
/**
- * Create a temporary function.
- * This assumes no database is specified in `funcDefinition`.
+ * Registers a temporary or permanent function into a session-specific [[FunctionRegistry]]
*/
- def createTempFunction(
- name: String,
- info: ExpressionInfo,
- funcDefinition: FunctionBuilder,
- ignoreIfExists: Boolean): Unit = {
- if (functionRegistry.lookupFunctionBuilder(name).isDefined && !ignoreIfExists) {
- throw new TempFunctionAlreadyExistsException(name)
+ def registerFunction(
+ funcDefinition: CatalogFunction,
+ ignoreIfExists: Boolean,
+ functionBuilder: Option[FunctionBuilder] = None): Unit = {
+ val func = funcDefinition.identifier
+ if (functionRegistry.functionExists(func.unquotedString) && !ignoreIfExists) {
+ throw new AnalysisException(s"Function $func already exists")
}
- functionRegistry.registerFunction(name, info, funcDefinition)
+ val info = new ExpressionInfo(funcDefinition.className, func.database.orNull, func.funcName)
+ val builder =
+ functionBuilder.getOrElse(makeFunctionBuilder(func.unquotedString, funcDefinition.className))
+ functionRegistry.registerFunction(func.unquotedString, info, builder)
}
/**
@@ -1180,12 +1182,7 @@ class SessionCatalog(
// catalog. So, it is possible that qualifiedName is not exactly the same as
// catalogFunction.identifier.unquotedString (difference is on case-sensitivity).
// At here, we preserve the input from the user.
- val info = new ExpressionInfo(
- catalogFunction.className,
- qualifiedName.database.orNull,
- qualifiedName.funcName)
- val builder = makeFunctionBuilder(qualifiedName.unquotedString, catalogFunction.className)
- createTempFunction(qualifiedName.unquotedString, info, builder, ignoreIfExists = false)
+ registerFunction(catalogFunction.copy(identifier = qualifiedName), ignoreIfExists = false)
// Now, we need to create the Expression.
functionRegistry.lookupFunction(qualifiedName.unquotedString, children)
}