spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [spark] imback82 commented on a change in pull request #26890: [SPARK-30039][SQL] CREATE FUNCTION should do multi-catalog resolution
Date Sun, 15 Dec 2019 19:00:19 GMT
imback82 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_r357998169
 
 

 ##########
 File path: sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala
 ##########
 @@ -475,47 +475,47 @@ class ResolveSessionCatalog(
         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)
+      val (database, function) =
+        parseSessionCatalogFunctionIdentifier("DESCRIBE FUNCTION", catalog, functionIdent)
+      DescribeFunctionCommand(FunctionIdentifier(function, database), 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")
-          }
+          val (db, fn) =
+            parseSessionCatalogFunctionIdentifier("SHOW FUNCTIONS", catalog, functionIdent)
+          (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")
+      val (database, function) =
+        parseSessionCatalogFunctionIdentifier("DROP FUNCTION", catalog, functionIdent)
+      DropFunctionCommand(database, function, ifExists, isTemp)
+
+    case CreateFunctionStatement(CatalogAndIdentifier(catalog, functionIdent),
+      className, resources, isTemp, ignoreIfExists, replace) =>
+      val (database, function) =
+        parseSessionCatalogFunctionIdentifier("CREATE FUNCTION", catalog, functionIdent)
+      CreateFunctionCommand(database, function, className, resources, isTemp, ignoreIfExists,
+        replace)
+  }
+
+  private def parseSessionCatalogFunctionIdentifier(
 
 Review comment:
   I would return `FunctionIdentifier` to match the function name, and also using `FunctionIdentifier`
makes the intention / usage clear on the caller site.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message