From a95614456685c5a12a95b6a1c3e64615a80ee28f Mon Sep 17 00:00:00 2001 From: ulysses Date: Tue, 14 Jul 2020 20:48:49 +0800 Subject: [PATCH] fix --- .../org/apache/spark/sql/execution/command/functions.scala | 5 +++-- .../org/apache/spark/sql/execution/command/DDLSuite.scala | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala index 05c44e37419cb..c63d214caba0f 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala @@ -265,9 +265,10 @@ case class RefreshFunctionCommand( // register overwrite function. val func = catalog.getFunctionMetadata(identifier) catalog.registerFunction(func, true) - } else { - // function is not exists, clear cached function. + } else if (catalog.isRegisteredFunction(identifier)) { + // clear cached function. catalog.unregisterFunction(identifier, true) + } else { throw new NoSuchFunctionException(identifier.database.get, functionName) } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index faafcb721008f..ad54d5d8b568b 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -3058,9 +3058,7 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils { spark.sessionState.catalog.externalCatalog.dropFunction("default", "func1") assert(spark.sessionState.catalog.isRegisteredFunction(func)) - intercept[NoSuchFunctionException] { - sql("REFRESH FUNCTION func1") - } + sql("REFRESH FUNCTION func1") assert(!spark.sessionState.catalog.isRegisteredFunction(func)) val function = CatalogFunction(func, "test.non.exists.udf", Seq.empty)