Skip to content

Commit 69b45be

Browse files
committed
fix qualified name
1 parent 3633d89 commit 69b45be

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ case class RefreshFunctionCommand(
251251

252252
override def run(sparkSession: SparkSession): Seq[Row] = {
253253
val catalog = sparkSession.sessionState.catalog
254-
if (FunctionRegistry.builtin.functionExists(FunctionIdentifier(functionName))) {
254+
if (FunctionRegistry.builtin.functionExists(FunctionIdentifier(functionName, databaseName))) {
255255
throw new AnalysisException(s"Cannot refresh built-in function $functionName")
256256
}
257257
if (catalog.isTemporaryFunction(FunctionIdentifier(functionName, databaseName))) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,6 +3036,9 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
30363036
sql("REFRESH FUNCTION md5")
30373037
}.getMessage
30383038
assert(msg.contains("Cannot refresh built-in function"))
3039+
intercept[NoSuchFunctionException] {
3040+
sql("REFRESH FUNCTION default.md5")
3041+
}
30393042

30403043
withUserDefinedFunction("func1" -> true) {
30413044
sql("CREATE TEMPORARY FUNCTION func1 AS 'test.org.apache.spark.sql.MyDoubleAvg'")
@@ -3079,6 +3082,21 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
30793082
assert(!spark.sessionState.catalog.isRegisteredFunction(func))
30803083
}
30813084
}
3085+
3086+
test("REFRESH FUNCTION persistent function with the same name as the built-in function") {
3087+
withUserDefinedFunction("rand" -> false) {
3088+
val rand = FunctionIdentifier("rand", Some("default"))
3089+
sql("CREATE FUNCTION rand AS 'test.org.apache.spark.sql.MyDoubleAvg'")
3090+
assert(!spark.sessionState.catalog.isRegisteredFunction(rand))
3091+
val msg = intercept[AnalysisException] {
3092+
sql("REFRESH FUNCTION rand")
3093+
}.getMessage
3094+
assert(msg.contains("Cannot refresh built-in function"))
3095+
assert(!spark.sessionState.catalog.isRegisteredFunction(rand))
3096+
sql("REFRESH FUNCTION default.rand")
3097+
assert(spark.sessionState.catalog.isRegisteredFunction(rand))
3098+
}
3099+
}
30823100
}
30833101

30843102
object FakeLocalFsFileSystem {

0 commit comments

Comments
 (0)