aboutsummaryrefslogtreecommitdiff
path: root/sql/hive
diff options
context:
space:
mode:
authorSandeep Singh <sandeep@techaddict.me>2016-06-13 21:58:52 -0700
committerYin Huai <yhuai@databricks.com>2016-06-13 21:58:52 -0700
commit1842cdd4ee9f30b0a5f579e26ff5194e81e3634c (patch)
treef499dc95ea2f0765dd89b69857a47fcee8fae433 /sql/hive
parentbaa3e633e18c47b12e79fe3ddc01fc8ec010f096 (diff)
downloadspark-1842cdd4ee9f30b0a5f579e26ff5194e81e3634c.tar.gz
spark-1842cdd4ee9f30b0a5f579e26ff5194e81e3634c.tar.bz2
spark-1842cdd4ee9f30b0a5f579e26ff5194e81e3634c.zip
[SPARK-15663][SQL] SparkSession.catalog.listFunctions shouldn't include the list of built-in functions
## What changes were proposed in this pull request? SparkSession.catalog.listFunctions currently returns all functions, including the list of built-in functions. This makes the method not as useful because anytime it is run the result set contains over 100 built-in functions. ## How was this patch tested? CatalogSuite Author: Sandeep Singh <sandeep@techaddict.me> Closes #13413 from techaddict/SPARK-15663.
Diffstat (limited to 'sql/hive')
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala48
1 files changed, 31 insertions, 17 deletions
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
index 8244ff4ce0..1a0eaa66c1 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
@@ -187,28 +187,42 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
}
test("show functions") {
- val allBuiltinFunctions = FunctionRegistry.builtin.listFunction().toSet[String].toList.sorted
- // The TestContext is shared by all the test cases, some functions may be registered before
- // this, so we check that all the builtin functions are returned.
- val allFunctions = sql("SHOW functions").collect().map(r => r(0))
- allBuiltinFunctions.foreach { f =>
- assert(allFunctions.contains(f))
- }
withTempDatabase { db =>
- checkAnswer(sql("SHOW functions abs"), Row("abs"))
- checkAnswer(sql("SHOW functions 'abs'"), Row("abs"))
- checkAnswer(sql(s"SHOW functions $db.abs"), Row("abs"))
- checkAnswer(sql(s"SHOW functions `$db`.`abs`"), Row("abs"))
- checkAnswer(sql(s"SHOW functions `$db`.`abs`"), Row("abs"))
- checkAnswer(sql("SHOW functions `~`"), Row("~"))
+ def createFunction(names: Seq[String]): Unit = {
+ names.foreach { name =>
+ sql(
+ s"""
+ |CREATE TEMPORARY FUNCTION $name
+ |AS '${classOf[PairUDF].getName}'
+ """.stripMargin)
+ }
+ }
+ def dropFunction(names: Seq[String]): Unit = {
+ names.foreach { name =>
+ sql(s"DROP TEMPORARY FUNCTION $name")
+ }
+ }
+ createFunction(Seq("temp_abs", "temp_weekofyear", "temp_sha", "temp_sha1", "temp_sha2"))
+
+ checkAnswer(sql("SHOW functions temp_abs"), Row("temp_abs"))
+ checkAnswer(sql("SHOW functions 'temp_abs'"), Row("temp_abs"))
+ checkAnswer(sql(s"SHOW functions $db.temp_abs"), Row("temp_abs"))
+ checkAnswer(sql(s"SHOW functions `$db`.`temp_abs`"), Row("temp_abs"))
+ checkAnswer(sql(s"SHOW functions `$db`.`temp_abs`"), Row("temp_abs"))
checkAnswer(sql("SHOW functions `a function doens't exist`"), Nil)
- checkAnswer(sql("SHOW functions `weekofyea*`"), Row("weekofyear"))
+ checkAnswer(sql("SHOW functions `temp_weekofyea*`"), Row("temp_weekofyear"))
+
// this probably will failed if we add more function with `sha` prefixing.
- checkAnswer(sql("SHOW functions `sha*`"), Row("sha") :: Row("sha1") :: Row("sha2") :: Nil)
+ checkAnswer(
+ sql("SHOW functions `temp_sha*`"),
+ List(Row("temp_sha"), Row("temp_sha1"), Row("temp_sha2")))
+
// Test '|' for alternation.
checkAnswer(
- sql("SHOW functions 'sha*|weekofyea*'"),
- Row("sha") :: Row("sha1") :: Row("sha2") :: Row("weekofyear") :: Nil)
+ sql("SHOW functions 'temp_sha*|temp_weekofyea*'"),
+ List(Row("temp_sha"), Row("temp_sha1"), Row("temp_sha2"), Row("temp_weekofyear")))
+
+ dropFunction(Seq("temp_abs", "temp_weekofyear", "temp_sha", "temp_sha1", "temp_sha2"))
}
}