Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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,10 @@ 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"))
intercept[NoSuchFunctionException] {
Copy link
Member

@maropu maropu Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just in case, could you check the error message, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

sql("REFRESH FUNCTION default.md5")
}

withUserDefinedFunction("func1" -> true) {
sql("CREATE TEMPORARY FUNCTION func1 AS 'test.org.apache.spark.sql.MyDoubleAvg'")
Expand All @@ -3046,15 +3049,21 @@ 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))
intercept[NoSuchFunctionException] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

sql("REFRESH FUNCTION func2")
}
assert(spark.sessionState.catalog.isRegisteredFunction(func))

spark.sessionState.catalog.externalCatalog.dropFunction("default", "func1")
assert(spark.sessionState.catalog.isRegisteredFunction(func))
Expand All @@ -3073,6 +3082,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