planga82 commented on a change in pull request #26890: [SPARK-30039][SQL] CREATE FUNCTION should do multi-catalog resolution URL: https://github.com/apache/spark/pull/26890#discussion_r358613325
########## File path: sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala ########## @@ -474,48 +474,48 @@ class ResolveSessionCatalog( tbl.asTableIdentifier, propertyKey) - case DescribeFunctionStatement(CatalogAndIdentifier(catalog, functionIdent), extended) => - val functionIdentifier = if (isSessionCatalog(catalog)) { - functionIdent.asMultipartIdentifier match { - case Seq(db, fn) => FunctionIdentifier(fn, Some(db)) - case Seq(fn) => FunctionIdentifier(fn, None) - case _ => - throw new AnalysisException(s"Unsupported function name '${functionIdent.quoted}'") - } - } else { - throw new AnalysisException ("DESCRIBE FUNCTION is only supported in v1 catalog") - } - DescribeFunctionCommand(functionIdentifier, extended) + case DescribeFunctionStatement(CatalogAndIdentifier(catalog, ident), extended) => + val functionIdent = + parseSessionCatalogFunctionIdentifier("DESCRIBE FUNCTION", catalog, ident) + DescribeFunctionCommand(functionIdent, extended) case ShowFunctionsStatement(userScope, systemScope, pattern, fun) => val (database, function) = fun match { - case Some(CatalogAndIdentifier(catalog, functionIdent)) => - if (isSessionCatalog(catalog)) { - functionIdent.asMultipartIdentifier match { - case Seq(db, fn) => (Some(db), Some(fn)) - case Seq(fn) => (None, Some(fn)) - case _ => - throw new AnalysisException(s"Unsupported function name '${functionIdent.quoted}'") - } - } else { - throw new AnalysisException ("SHOW FUNCTIONS is only supported in v1 catalog") - } + case Some(CatalogAndIdentifier(catalog, ident)) => + val FunctionIdentifier(fn, db) = + parseSessionCatalogFunctionIdentifier("SHOW FUNCTIONS", catalog, ident) + (db, Some(fn)) case None => (None, pattern) } ShowFunctionsCommand(database, function, userScope, systemScope) - case DropFunctionStatement(CatalogAndIdentifier(catalog, functionIdent), ifExists, isTemp) => - if (isSessionCatalog(catalog)) { - val (database, function) = functionIdent.asMultipartIdentifier match { - case Seq(db, fn) => (Some(db), fn) - case Seq(fn) => (None, fn) - case _ => - throw new AnalysisException(s"Unsupported function name '${functionIdent.quoted}'") - } - DropFunctionCommand(database, function, ifExists, isTemp) - } else { - throw new AnalysisException("DROP FUNCTION is only supported in v1 catalog") + case DropFunctionStatement(CatalogAndIdentifier(catalog, ident), ifExists, isTemp) => + val FunctionIdentifier(function, database) = + parseSessionCatalogFunctionIdentifier("DROP FUNCTION", catalog, ident) + DropFunctionCommand(database, function, ifExists, isTemp) + + case CreateFunctionStatement(CatalogAndIdentifier(catalog, ident), + className, resources, isTemp, ignoreIfExists, replace) => + val FunctionIdentifier(function, database) = + parseSessionCatalogFunctionIdentifier("CREATE FUNCTION", catalog, ident) + CreateFunctionCommand(database, function, className, resources, isTemp, ignoreIfExists, + replace) + } + + private def parseSessionCatalogFunctionIdentifier( + sql: String, + catalog: CatalogPlugin, + functionIdent: Identifier): FunctionIdentifier = { + if (isSessionCatalog(catalog)) { + functionIdent.asMultipartIdentifier match { + case Seq(db, fn) => FunctionIdentifier(fn, Some(db)) + case Seq(fn) => FunctionIdentifier(fn, None) + case _ => + throw new AnalysisException(s"Unsupported function name '${functionIdent.quoted}'") Review comment: In the show columns statement we decide this message > Namespace name should have only one part if specified How about the same message or similar? Both are clearer ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org