aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala9
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala6
2 files changed, 14 insertions, 1 deletions
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
index 077e64133f..0bdaf5f7ef 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
@@ -20,6 +20,8 @@ package org.apache.spark.sql.hive
import java.sql.Date
+import org.apache.hadoop.hive.ql.exec.{FunctionRegistry, FunctionInfo}
+
import scala.collection.mutable.ArrayBuffer
import org.apache.hadoop.hive.conf.HiveConf
@@ -1284,8 +1286,13 @@ https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
Explode(attributes, nodeToExpr(child))
case Token("TOK_FUNCTION", Token(functionName, Nil) :: children) =>
+ val functionInfo: FunctionInfo =
+ Option(FunctionRegistry.getFunctionInfo(functionName.toLowerCase)).getOrElse(
+ sys.error(s"Couldn't find function $functionName"))
+ val functionClassName = functionInfo.getFunctionClass.getName
+
HiveGenericUdtf(
- new HiveFunctionWrapper(functionName),
+ new HiveFunctionWrapper(functionClassName),
attributes,
children.map(nodeToExpr))
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 4c369c0634..47b4cb9ca6 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
@@ -51,6 +51,12 @@ case class Order(
* valid, but Hive currently cannot execute it.
*/
class SQLQuerySuite extends QueryTest {
+ test("SPARK-6835: udtf in lateral view") {
+ val df = Seq((1, 1)).toDF("c1", "c2")
+ df.registerTempTable("table1")
+ val query = sql("SELECT c1, v FROM table1 LATERAL VIEW stack(3, 1, c1 + 1, c1 + 2) d AS v")
+ checkAnswer(query, Row(1, 1) :: Row(1, 2) :: Row(1, 3) :: Nil)
+ }
test("SPARK-6851: Self-joined converted parquet tables") {
val orders = Seq(