aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/test
diff options
context:
space:
mode:
authorXiao Li <gatorsmile@gmail.com>2017-04-12 09:01:26 -0700
committerXiao Li <gatorsmile@gmail.com>2017-04-12 09:01:26 -0700
commit504e62e2f4b7df7e002ea014a855cebe1ff95193 (patch)
treee24fb9939cf38f1be5590882175a7d33961b81b8 /sql/catalyst/src/test
parentceaf77ae43a14e993ac6d1ff34b50256eacd6abb (diff)
downloadspark-504e62e2f4b7df7e002ea014a855cebe1ff95193.tar.gz
spark-504e62e2f4b7df7e002ea014a855cebe1ff95193.tar.bz2
spark-504e62e2f4b7df7e002ea014a855cebe1ff95193.zip
[SPARK-20303][SQL] Rename createTempFunction to registerFunction
### What changes were proposed in this pull request? Session catalog API `createTempFunction` is being used by Hive build-in functions, persistent functions, and temporary functions. Thus, the name is confusing. This PR is to rename it by `registerFunction`. Also we can move construction of `FunctionBuilder` and `ExpressionInfo` into the new `registerFunction`, instead of duplicating the logics everywhere. In the next PRs, the remaining Function-related APIs also need cleanups. ### How was this patch tested? Existing test cases. Author: Xiao Li <gatorsmile@gmail.com> Closes #17615 from gatorsmile/cleanupCreateTempFunction.
Diffstat (limited to 'sql/catalyst/src/test')
-rw-r--r--sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala40
1 files changed, 21 insertions, 19 deletions
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
index 9ba846fb25..be8903000a 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
@@ -1162,10 +1162,10 @@ abstract class SessionCatalogSuite extends PlanTest {
withBasicCatalog { catalog =>
val tempFunc1 = (e: Seq[Expression]) => e.head
val tempFunc2 = (e: Seq[Expression]) => e.last
- val info1 = new ExpressionInfo("tempFunc1", "temp1")
- val info2 = new ExpressionInfo("tempFunc2", "temp2")
- catalog.createTempFunction("temp1", info1, tempFunc1, ignoreIfExists = false)
- catalog.createTempFunction("temp2", info2, tempFunc2, ignoreIfExists = false)
+ catalog.registerFunction(
+ newFunc("temp1", None), ignoreIfExists = false, functionBuilder = Some(tempFunc1))
+ catalog.registerFunction(
+ newFunc("temp2", None), ignoreIfExists = false, functionBuilder = Some(tempFunc2))
val arguments = Seq(Literal(1), Literal(2), Literal(3))
assert(catalog.lookupFunction(FunctionIdentifier("temp1"), arguments) === Literal(1))
assert(catalog.lookupFunction(FunctionIdentifier("temp2"), arguments) === Literal(3))
@@ -1174,13 +1174,15 @@ abstract class SessionCatalogSuite extends PlanTest {
catalog.lookupFunction(FunctionIdentifier("temp3"), arguments)
}
val tempFunc3 = (e: Seq[Expression]) => Literal(e.size)
- val info3 = new ExpressionInfo("tempFunc3", "temp1")
// Temporary function already exists
- intercept[TempFunctionAlreadyExistsException] {
- catalog.createTempFunction("temp1", info3, tempFunc3, ignoreIfExists = false)
- }
+ val e = intercept[AnalysisException] {
+ catalog.registerFunction(
+ newFunc("temp1", None), ignoreIfExists = false, functionBuilder = Some(tempFunc3))
+ }.getMessage
+ assert(e.contains("Function temp1 already exists"))
// Temporary function is overridden
- catalog.createTempFunction("temp1", info3, tempFunc3, ignoreIfExists = true)
+ catalog.registerFunction(
+ newFunc("temp1", None), ignoreIfExists = true, functionBuilder = Some(tempFunc3))
assert(
catalog.lookupFunction(
FunctionIdentifier("temp1"), arguments) === Literal(arguments.length))
@@ -1193,8 +1195,8 @@ abstract class SessionCatalogSuite extends PlanTest {
assert(!catalog.isTemporaryFunction(FunctionIdentifier("temp1")))
val tempFunc1 = (e: Seq[Expression]) => e.head
- val info1 = new ExpressionInfo("tempFunc1", "temp1")
- catalog.createTempFunction("temp1", info1, tempFunc1, ignoreIfExists = false)
+ catalog.registerFunction(
+ newFunc("temp1", None), ignoreIfExists = false, functionBuilder = Some(tempFunc1))
// Returns true when the function is temporary
assert(catalog.isTemporaryFunction(FunctionIdentifier("temp1")))
@@ -1243,9 +1245,9 @@ abstract class SessionCatalogSuite extends PlanTest {
test("drop temp function") {
withBasicCatalog { catalog =>
- val info = new ExpressionInfo("tempFunc", "func1")
val tempFunc = (e: Seq[Expression]) => e.head
- catalog.createTempFunction("func1", info, tempFunc, ignoreIfExists = false)
+ catalog.registerFunction(
+ newFunc("func1", None), ignoreIfExists = false, functionBuilder = Some(tempFunc))
val arguments = Seq(Literal(1), Literal(2), Literal(3))
assert(catalog.lookupFunction(FunctionIdentifier("func1"), arguments) === Literal(1))
catalog.dropTempFunction("func1", ignoreIfNotExists = false)
@@ -1284,9 +1286,9 @@ abstract class SessionCatalogSuite extends PlanTest {
test("lookup temp function") {
withBasicCatalog { catalog =>
- val info1 = new ExpressionInfo("tempFunc1", "func1")
val tempFunc1 = (e: Seq[Expression]) => e.head
- catalog.createTempFunction("func1", info1, tempFunc1, ignoreIfExists = false)
+ catalog.registerFunction(
+ newFunc("func1", None), ignoreIfExists = false, functionBuilder = Some(tempFunc1))
assert(catalog.lookupFunction(
FunctionIdentifier("func1"), Seq(Literal(1), Literal(2), Literal(3))) == Literal(1))
catalog.dropTempFunction("func1", ignoreIfNotExists = false)
@@ -1298,14 +1300,14 @@ abstract class SessionCatalogSuite extends PlanTest {
test("list functions") {
withBasicCatalog { catalog =>
- val info1 = new ExpressionInfo("tempFunc1", "func1")
- val info2 = new ExpressionInfo("tempFunc2", "yes_me")
+ val funcMeta1 = newFunc("func1", None)
+ val funcMeta2 = newFunc("yes_me", None)
val tempFunc1 = (e: Seq[Expression]) => e.head
val tempFunc2 = (e: Seq[Expression]) => e.last
catalog.createFunction(newFunc("func2", Some("db2")), ignoreIfExists = false)
catalog.createFunction(newFunc("not_me", Some("db2")), ignoreIfExists = false)
- catalog.createTempFunction("func1", info1, tempFunc1, ignoreIfExists = false)
- catalog.createTempFunction("yes_me", info2, tempFunc2, ignoreIfExists = false)
+ catalog.registerFunction(funcMeta1, ignoreIfExists = false, functionBuilder = Some(tempFunc1))
+ catalog.registerFunction(funcMeta2, ignoreIfExists = false, functionBuilder = Some(tempFunc2))
assert(catalog.listFunctions("db1", "*").map(_._1).toSet ==
Set(FunctionIdentifier("func1"),
FunctionIdentifier("yes_me")))