Skip to content

Commit

Permalink
[SPARK-15199][SQL] Disallow Dropping Build-in Functions
Browse files Browse the repository at this point in the history
#### What changes were proposed in this pull request?
As Hive and the major RDBMS behave, the built-in functions are not allowed to drop. In the current implementation, users can drop the built-in functions. However, after dropping the built-in functions, users are unable to add them back.

#### How was this patch tested?
Added a test case.

Author: gatorsmile <gatorsmile@gmail.com>

Closes #12975 from gatorsmile/dropBuildInFunction.
  • Loading branch information
gatorsmile authored and Andrew Or committed May 9, 2016
1 parent beb16ec commit b1e01fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.sql.execution.command

import org.apache.spark.sql.{AnalysisException, Row, SparkSession}
import org.apache.spark.sql.catalyst.FunctionIdentifier
import org.apache.spark.sql.catalyst.analysis.NoSuchFunctionException
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, NoSuchFunctionException}
import org.apache.spark.sql.catalyst.catalog.CatalogFunction
import org.apache.spark.sql.catalyst.expressions.{Attribute, ExpressionInfo}
import org.apache.spark.sql.types.{StringType, StructField, StructType}
Expand Down Expand Up @@ -157,6 +157,9 @@ case class DropFunction(
throw new AnalysisException(s"Specifying a database in DROP TEMPORARY FUNCTION " +
s"is not allowed: '${databaseName.get}'")
}
if (FunctionRegistry.builtin.functionExists(functionName)) {
throw new AnalysisException(s"Cannot drop native function '$functionName'")
}
catalog.dropTempFunction(functionName, ifExists)
} else {
// We are dropping a permanent function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,28 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
}
}

test("drop build-in function") {
Seq("true", "false").foreach { caseSensitive =>
withSQLConf(SQLConf.CASE_SENSITIVE.key -> caseSensitive) {
// partition to add already exists
var e = intercept[AnalysisException] {
sql("DROP TEMPORARY FUNCTION year")
}
assert(e.getMessage.contains("Cannot drop native function 'year'"))

e = intercept[AnalysisException] {
sql("DROP TEMPORARY FUNCTION YeAr")
}
assert(e.getMessage.contains("Cannot drop native function 'YeAr'"))

e = intercept[AnalysisException] {
sql("DROP TEMPORARY FUNCTION `YeAr`")
}
assert(e.getMessage.contains("Cannot drop native function 'YeAr'"))
}
}
}

test("describe function") {
checkAnswer(
sql("DESCRIBE FUNCTION log"),
Expand Down

0 comments on commit b1e01fd

Please sign in to comment.