viirya commented on a change in pull request #25452: [SPARK-28710][SQL]to fix 
replace function, spark should call drop and create function
URL: https://github.com/apache/spark/pull/25452#discussion_r358336153
 
 

 ##########
 File path: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala
 ##########
 @@ -1282,7 +1282,16 @@ private[spark] class HiveExternalCatalog(conf: 
SparkConf, hadoopConf: Configurat
     val functionName = 
funcDefinition.identifier.funcName.toLowerCase(Locale.ROOT)
     requireFunctionExists(db, functionName)
     val functionIdentifier = funcDefinition.identifier.copy(funcName = 
functionName)
-    client.alterFunction(db, funcDefinition.copy(identifier = 
functionIdentifier))
+    val newDefinition = funcDefinition.copy(identifier = functionIdentifier)
+    isResourceChanged(db, newDefinition) match {
+      // as of now Hive only alter name, owner, class name, type but not 
resource URI
+      // So in order to replace function with resource spark needs to delete 
and create the function
+      case true => client.dropFunction(db, functionName)
+        client.createFunction(db, newDefinition)
+      // replace the function in the metastore if there is no change in the 
resource
+      case _ =>
+        client.alterFunction(db, newDefinition)
 
 Review comment:
   From Hive 
[DDL](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create/Drop/ReloadFunction),
 looks like it does not have "replace" in create function:
   
   ```
   CREATE FUNCTION [db_name.]function_name AS class_name
     [USING JAR|FILE|ARCHIVE 'file_uri' [, JAR|FILE|ARCHIVE 'file_uri'] ];
   ```
   
   Maybe it is why this API does not do resource replacement?
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to