Repository: spark
Updated Branches:
  refs/heads/branch-2.0 5cdb7bea5 -> 29bc8d2ec


[SPARK-15199][SQL] Disallow Dropping Build-in Functions

#### 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 <gatorsm...@gmail.com>

Closes #12975 from gatorsmile/dropBuildInFunction.

(cherry picked from commit b1e01fd519d4d1bc6d9bd2270f9504d757dbd0d2)
Signed-off-by: Andrew Or <and...@databricks.com>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/29bc8d2e
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/29bc8d2e
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/29bc8d2e

Branch: refs/heads/branch-2.0
Commit: 29bc8d2ec4cae8ba0234fde24d00e18c6e82733a
Parents: 5cdb7be
Author: gatorsmile <gatorsm...@gmail.com>
Authored: Mon May 9 10:49:54 2016 -0700
Committer: Andrew Or <and...@databricks.com>
Committed: Mon May 9 10:50:02 2016 -0700

----------------------------------------------------------------------
 .../spark/sql/execution/command/functions.scala |  5 ++++-
 .../spark/sql/execution/command/DDLSuite.scala  | 22 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/29bc8d2e/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala
----------------------------------------------------------------------
diff --git 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala
 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala
index 79c3648..a9aa8d7 100644
--- 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala
+++ 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala
@@ -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}
@@ -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.

http://git-wip-us.apache.org/repos/asf/spark/blob/29bc8d2e/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
----------------------------------------------------------------------
diff --git 
a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala 
b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
index 13074a6..d115567 100644
--- 
a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
+++ 
b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
@@ -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"),


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to