Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ case class RefreshFunctionCommand(

override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
if (FunctionRegistry.builtin.functionExists(FunctionIdentifier(functionName))) {
throw new AnalysisException(s"Cannot refresh builtin function $functionName")
if (FunctionRegistry.builtin.functionExists(FunctionIdentifier(functionName, databaseName))) {
throw new AnalysisException(s"Cannot refresh built-in function $functionName")
}
if (catalog.isTemporaryFunction(FunctionIdentifier(functionName, databaseName))) {
throw new AnalysisException(s"Cannot refresh temporary function $functionName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,12 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
val msg = intercept[AnalysisException] {
sql("REFRESH FUNCTION md5")
}.getMessage
assert(msg.contains("Cannot refresh builtin function"))
assert(msg.contains("Cannot refresh built-in function"))
val msg2 = intercept[NoSuchFunctionException] {
sql("REFRESH FUNCTION default.md5")
}.getMessage
assert(msg2.contains(s"Undefined function: 'md5'. This function is neither a registered " +
s"temporary function nor a permanent function registered in the database 'default'."))

withUserDefinedFunction("func1" -> true) {
sql("CREATE TEMPORARY FUNCTION func1 AS 'test.org.apache.spark.sql.MyDoubleAvg'")
Expand All @@ -3046,15 +3051,23 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
}

withUserDefinedFunction("func1" -> false) {
val func = FunctionIdentifier("func1", Some("default"))
assert(!spark.sessionState.catalog.isRegisteredFunction(func))
intercept[NoSuchFunctionException] {
sql("REFRESH FUNCTION func1")
}
assert(!spark.sessionState.catalog.isRegisteredFunction(func))

val func = FunctionIdentifier("func1", Some("default"))
sql("CREATE FUNCTION func1 AS 'test.org.apache.spark.sql.MyDoubleAvg'")
assert(!spark.sessionState.catalog.isRegisteredFunction(func))
sql("REFRESH FUNCTION func1")
assert(spark.sessionState.catalog.isRegisteredFunction(func))
val msg = intercept[NoSuchFunctionException] {
sql("REFRESH FUNCTION func2")
}.getMessage
assert(msg.contains(s"Undefined function: 'func2'. This function is neither a registered " +
s"temporary function nor a permanent function registered in the database 'default'."))
assert(spark.sessionState.catalog.isRegisteredFunction(func))

spark.sessionState.catalog.externalCatalog.dropFunction("default", "func1")
assert(spark.sessionState.catalog.isRegisteredFunction(func))
Expand All @@ -3073,6 +3086,21 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
assert(!spark.sessionState.catalog.isRegisteredFunction(func))
}
}

test("REFRESH FUNCTION persistent function with the same name as the built-in function") {
withUserDefinedFunction("default.rand" -> false) {
val rand = FunctionIdentifier("rand", Some("default"))
sql("CREATE FUNCTION rand AS 'test.org.apache.spark.sql.MyDoubleAvg'")
assert(!spark.sessionState.catalog.isRegisteredFunction(rand))
val msg = intercept[AnalysisException] {
sql("REFRESH FUNCTION rand")
}.getMessage
assert(msg.contains("Cannot refresh built-in function"))
assert(!spark.sessionState.catalog.isRegisteredFunction(rand))
sql("REFRESH FUNCTION default.rand")
assert(spark.sessionState.catalog.isRegisteredFunction(rand))
}
}
}

object FakeLocalFsFileSystem {
Expand Down