-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-20303][SQL] Rename createTempFunction to registerFunction #17615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ case class CreateFunctionCommand( | |
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
| val func = CatalogFunction(FunctionIdentifier(functionName, databaseName), className, resources) | ||
| if (isTemp) { | ||
| if (databaseName.isDefined) { | ||
| throw new AnalysisException(s"Specifying a database in CREATE TEMPORARY FUNCTION " + | ||
|
|
@@ -59,17 +60,13 @@ case class CreateFunctionCommand( | |
| // We first load resources and then put the builder in the function registry. | ||
| // Please note that it is allowed to overwrite an existing temp function. | ||
| catalog.loadFunctionResources(resources) | ||
| val info = new ExpressionInfo(className, functionName) | ||
| val builder = catalog.makeFunctionBuilder(functionName, className) | ||
| catalog.createTempFunction(functionName, info, builder, ignoreIfExists = false) | ||
| catalog.registerFunction(func, ignoreIfExists = false) | ||
| } else { | ||
| // For a permanent, we will store the metadata into underlying external catalog. | ||
| // This function will be loaded into the FunctionRegistry when a query uses it. | ||
| // We do not load it into FunctionRegistry right now. | ||
| // TODO: should we also parse "IF NOT EXISTS"? | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we support it? @cloud-fan @yhuai @rxin
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does hive support it?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. : ) Oracle has the |
||
| catalog.createFunction( | ||
| CatalogFunction(FunctionIdentifier(functionName, databaseName), className, resources), | ||
| ignoreIfExists = false) | ||
| catalog.createFunction(func, ignoreIfExists = false) | ||
| } | ||
| Seq.empty[Row] | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,8 @@ import org.apache.spark.sql.AnalysisException | |
| import org.apache.spark.sql.catalyst.FunctionIdentifier | ||
| import org.apache.spark.sql.catalyst.analysis.FunctionRegistry | ||
| import org.apache.spark.sql.catalyst.analysis.FunctionRegistry.FunctionBuilder | ||
| import org.apache.spark.sql.catalyst.catalog.{FunctionResourceLoader, GlobalTempViewManager, SessionCatalog} | ||
| import org.apache.spark.sql.catalyst.expressions.{Cast, Expression, ExpressionInfo} | ||
| import org.apache.spark.sql.catalyst.catalog.{CatalogFunction, FunctionResourceLoader, GlobalTempViewManager, SessionCatalog} | ||
| import org.apache.spark.sql.catalyst.expressions.{Cast, Expression} | ||
| import org.apache.spark.sql.catalyst.parser.ParserInterface | ||
| import org.apache.spark.sql.hive.HiveShim.HiveFunctionWrapper | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
@@ -124,13 +124,6 @@ private[sql] class HiveSessionCatalog( | |
| } | ||
|
|
||
| private def lookupFunction0(name: FunctionIdentifier, children: Seq[Expression]): Expression = { | ||
| // TODO: Once lookupFunction accepts a FunctionIdentifier, we should refactor this method to | ||
| // if (super.functionExists(name)) { | ||
| // super.lookupFunction(name, children) | ||
| // } else { | ||
| // // This function is a Hive builtin function. | ||
| // ... | ||
| // } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| val database = name.database.map(formatDatabaseName) | ||
| val funcName = name.copy(database = database) | ||
| Try(super.lookupFunction(funcName, children)) match { | ||
|
|
@@ -164,10 +157,11 @@ private[sql] class HiveSessionCatalog( | |
| } | ||
| } | ||
| val className = functionInfo.getFunctionClass.getName | ||
| val builder = makeFunctionBuilder(functionName, className) | ||
| val functionIdentifier = | ||
| FunctionIdentifier(functionName.toLowerCase(Locale.ROOT), database) | ||
| val func = CatalogFunction(functionIdentifier, className, Nil) | ||
| // Put this Hive built-in function to our function registry. | ||
| val info = new ExpressionInfo(className, functionName) | ||
| createTempFunction(functionName, info, builder, ignoreIfExists = false) | ||
| registerFunction(func, ignoreIfExists = false) | ||
| // Now, we need to create the Expression. | ||
| functionRegistry.lookupFunction(functionName, children) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
registerFunctionis the only caller ofmakeFunctionBuilderafter this PR.