Skip to content

Commit aff8f9e

Browse files
committed
fix.
1 parent 05e8168 commit aff8f9e

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveUDFSuite.scala

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,46 @@ class HiveUDFSuite extends QueryTest with TestHiveSingleton with SQLTestUtils {
596596
}
597597
}
598598
}
599+
600+
test("UDTF") {
601+
withUserDefinedFunction("udtf_count2" -> true) {
602+
sql(s"ADD JAR ${hiveContext.getHiveFile("TestUDTF.jar").getCanonicalPath}")
603+
// The function source code can be found at:
604+
// https://cwiki.apache.org/confluence/display/Hive/DeveloperGuide+UDTF
605+
sql(
606+
"""
607+
|CREATE TEMPORARY FUNCTION udtf_count2
608+
|AS 'org.apache.spark.sql.hive.execution.GenericUDTFCount2'
609+
""".stripMargin)
610+
611+
checkAnswer(
612+
sql("SELECT key, cc FROM src LATERAL VIEW udtf_count2(value) dd AS cc"),
613+
Row(97, 500) :: Row(97, 500) :: Nil)
614+
615+
checkAnswer(
616+
sql("SELECT udtf_count2(a) FROM (SELECT 1 AS a FROM src LIMIT 3) t"),
617+
Row(3) :: Row(3) :: Nil)
618+
}
619+
}
620+
621+
test("permanent UDTF") {
622+
withUserDefinedFunction("udtf_count_temp" -> false) {
623+
sql(
624+
s"""
625+
|CREATE FUNCTION udtf_count_temp
626+
|AS 'org.apache.spark.sql.hive.execution.GenericUDTFCount2'
627+
|USING JAR '${hiveContext.getHiveFile("TestUDTF.jar").toURI}'
628+
""".stripMargin)
629+
630+
checkAnswer(
631+
sql("SELECT key, cc FROM src LATERAL VIEW udtf_count_temp(value) dd AS cc"),
632+
Row(97, 500) :: Row(97, 500) :: Nil)
633+
634+
checkAnswer(
635+
sql("SELECT udtf_count_temp(a) FROM (SELECT 1 AS a FROM src LIMIT 3) t"),
636+
Row(3) :: Row(3) :: Nil)
637+
}
638+
}
599639
}
600640

601641
class TestPair(x: Int, y: Int) extends Writable with Serializable {

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.apache.hadoop.fs.Path
2828
import org.apache.spark.TestUtils
2929
import org.apache.spark.sql._
3030
import org.apache.spark.sql.catalyst.TableIdentifier
31-
import org.apache.spark.sql.catalyst.analysis.{EliminateSubqueryAliases, FunctionRegistry, NoSuchPartitionException}
31+
import org.apache.spark.sql.catalyst.analysis.{EliminateSubqueryAliases, FunctionRegistry}
3232
import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTableType, CatalogUtils}
3333
import org.apache.spark.sql.catalyst.parser.ParseException
3434
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, SubqueryAlias}
@@ -98,46 +98,6 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
9898
checkAnswer(query1, Row("x1_y1") :: Row("x2_y2") :: Nil)
9999
}
100100

101-
test("UDTF") {
102-
withUserDefinedFunction("udtf_count2" -> true) {
103-
sql(s"ADD JAR ${hiveContext.getHiveFile("TestUDTF.jar").getCanonicalPath()}")
104-
// The function source code can be found at:
105-
// https://cwiki.apache.org/confluence/display/Hive/DeveloperGuide+UDTF
106-
sql(
107-
"""
108-
|CREATE TEMPORARY FUNCTION udtf_count2
109-
|AS 'org.apache.spark.sql.hive.execution.GenericUDTFCount2'
110-
""".stripMargin)
111-
112-
checkAnswer(
113-
sql("SELECT key, cc FROM src LATERAL VIEW udtf_count2(value) dd AS cc"),
114-
Row(97, 500) :: Row(97, 500) :: Nil)
115-
116-
checkAnswer(
117-
sql("SELECT udtf_count2(a) FROM (SELECT 1 AS a FROM src LIMIT 3) t"),
118-
Row(3) :: Row(3) :: Nil)
119-
}
120-
}
121-
122-
test("permanent UDTF") {
123-
withUserDefinedFunction("udtf_count_temp" -> false) {
124-
sql(
125-
s"""
126-
|CREATE FUNCTION udtf_count_temp
127-
|AS 'org.apache.spark.sql.hive.execution.GenericUDTFCount2'
128-
|USING JAR '${hiveContext.getHiveFile("TestUDTF.jar").toURI}'
129-
""".stripMargin)
130-
131-
checkAnswer(
132-
sql("SELECT key, cc FROM src LATERAL VIEW udtf_count_temp(value) dd AS cc"),
133-
Row(97, 500) :: Row(97, 500) :: Nil)
134-
135-
checkAnswer(
136-
sql("SELECT udtf_count_temp(a) FROM (SELECT 1 AS a FROM src LIMIT 3) t"),
137-
Row(3) :: Row(3) :: Nil)
138-
}
139-
}
140-
141101
test("SPARK-6835: udtf in lateral view") {
142102
val df = Seq((1, 1)).toDF("c1", "c2")
143103
df.createOrReplaceTempView("table1")

0 commit comments

Comments
 (0)