Skip to content

Commit 94fa132

Browse files
committed
fix
1 parent 5d4c152 commit 94fa132

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,8 +1344,8 @@ class SessionCatalog(
13441344
/**
13451345
* Unregister a temporary or permanent function from a session-specific [[FunctionRegistry]]
13461346
*/
1347-
def unregisterFunction(name: FunctionIdentifier): Unit = {
1348-
if (!functionRegistry.dropFunction(name)) {
1347+
def unregisterFunction(name: FunctionIdentifier, ignoreIfNotExists: Boolean): Unit = {
1348+
if (!functionRegistry.dropFunction(name) && !ignoreIfNotExists) {
13491349
throw new NoSuchFunctionException(
13501350
formatDatabaseName(name.database.getOrElse(currentDb)), name.funcName)
13511351
}

sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ case class RefreshFunctionCommand(
266266
val func = catalog.getFunctionMetadata(identifier)
267267
catalog.registerFunction(func, true)
268268
} else {
269-
// clear cached function.
270-
catalog.unregisterFunction(identifier)
269+
// clear cached function if exists.
270+
catalog.unregisterFunction(identifier, true)
271+
throw new NoSuchFunctionException(identifier.database.get, functionName)
271272
}
272273

273274
Seq.empty[Row]

sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3058,7 +3058,9 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
30583058

30593059
spark.sessionState.catalog.externalCatalog.dropFunction("default", "func1")
30603060
assert(spark.sessionState.catalog.isRegisteredFunction(func))
3061-
sql("REFRESH FUNCTION func1")
3061+
intercept[NoSuchFunctionException] {
3062+
sql("REFRESH FUNCTION func1")
3063+
}
30623064
assert(!spark.sessionState.catalog.isRegisteredFunction(func))
30633065

30643066
val function = CatalogFunction(func, "test.non.exists.udf", Seq.empty)

0 commit comments

Comments
 (0)