spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marmb...@apache.org
Subject spark git commit: [SPARK-5908][SQL] Resolve UdtfsAlias when only single Alias is used
Date Wed, 18 Mar 2015 01:59:06 GMT
Repository: spark
Updated Branches:
  refs/heads/master a012e0863 -> 5c80643d1


[SPARK-5908][SQL] Resolve UdtfsAlias when only single Alias is used

`ResolveUdtfsAlias` in `hiveUdfs` only considers the `HiveGenericUdtf` with multiple alias.
When only single alias is used with `HiveGenericUdtf`, the alias is not working.

Author: Liang-Chi Hsieh <viirya@gmail.com>

Closes #4692 from viirya/udft_alias and squashes the following commits:

8a3bae4 [Liang-Chi Hsieh] No need to test selected column from DataFrame since DataFrame API
is updated.
160a379 [Liang-Chi Hsieh] Merge remote-tracking branch 'upstream/master' into udft_alias
e6531cc [Liang-Chi Hsieh] Selected column from DataFrame should not re-analyze logical plan.
a45cc2a [Liang-Chi Hsieh] Resolve UdtfsAlias when only single Alias is used.


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

Branch: refs/heads/master
Commit: 5c80643d137008ce8a0ac7467b31d8d52383c105
Parents: a012e08
Author: Liang-Chi Hsieh <viirya@gmail.com>
Authored: Tue Mar 17 18:58:52 2015 -0700
Committer: Michael Armbrust <michael@databricks.com>
Committed: Tue Mar 17 18:58:52 2015 -0700

----------------------------------------------------------------------
 .../src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala   | 2 ++
 .../org/apache/spark/sql/hive/execution/SQLQuerySuite.scala   | 7 +++++++
 2 files changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/5c80643d/sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala
----------------------------------------------------------------------
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala
index 34c21c1..4a702d9 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala
@@ -333,6 +333,8 @@ private[spark] object ResolveUdtfsAlias extends Rule[LogicalPlan] {
       if projectList.exists(_.isInstanceOf[MultiAlias]) && projectList.size != 1
=>
       throw new TreeNodeException(p, "only single Generator supported for SELECT clause")
 
+    case Project(Seq(Alias(udtf @ HiveGenericUdtf(_, _, _), name)), child) =>
+        Generate(udtf.copy(aliasNames = Seq(name)), join = false, outer = false, None, child)
     case Project(Seq(MultiAlias(udtf @ HiveGenericUdtf(_, _, _), names)), child) =>
         Generate(udtf.copy(aliasNames = names), join = false, outer = false, None, child)
   }

http://git-wip-us.apache.org/repos/asf/spark/blob/5c80643d/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
----------------------------------------------------------------------
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 22ea19b..1187228 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
@@ -397,6 +397,13 @@ class SQLQuerySuite extends QueryTest {
     dropTempTable("data")
   }
 
+  test("resolve udtf with single alias") {
+    val rdd = sparkContext.makeRDD((1 to 5).map(i => s"""{"a":[$i, ${i+1}]}"""))
+    jsonRDD(rdd).registerTempTable("data")
+    val df = sql("SELECT explode(a) AS val FROM data")
+    val col = df("val")
+  }
+
   test("logical.Project should not be resolved if it contains aggregates or generators")
{
     // This test is used to test the fix of SPARK-5875.
     // The original issue was that Project's resolved will be true when it contains


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


Mime
View raw message