Skip to content

Commit

Permalink
fix qualified name
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysses-you committed Aug 18, 2020
1 parent 3633d89 commit 69b45be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ case class RefreshFunctionCommand(

override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
if (FunctionRegistry.builtin.functionExists(FunctionIdentifier(functionName))) {
if (FunctionRegistry.builtin.functionExists(FunctionIdentifier(functionName, databaseName))) {
throw new AnalysisException(s"Cannot refresh built-in function $functionName")
}
if (catalog.isTemporaryFunction(FunctionIdentifier(functionName, databaseName))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,9 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
sql("REFRESH FUNCTION md5")
}.getMessage
assert(msg.contains("Cannot refresh built-in function"))
intercept[NoSuchFunctionException] {
sql("REFRESH FUNCTION default.md5")
}

withUserDefinedFunction("func1" -> true) {
sql("CREATE TEMPORARY FUNCTION func1 AS 'test.org.apache.spark.sql.MyDoubleAvg'")
Expand Down Expand Up @@ -3079,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("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

0 comments on commit 69b45be

Please sign in to comment.