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-5650][SQL] Support optional 'FROM' clause
Date Fri, 06 Feb 2015 20:13:55 GMT
Repository: spark
Updated Branches:
  refs/heads/branch-1.3 ab0ffde3e -> 921121d57


[SPARK-5650][SQL] Support optional 'FROM' clause

In Hive, 'FROM' clause is optional. This pr supports it.

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

Closes #4426 from viirya/optional_from and squashes the following commits:

fe81f31 [Liang-Chi Hsieh] Support optional 'FROM' clause.

(cherry picked from commit d433816157bb3ae1f0fbe44efec43a0c906d9f82)
Signed-off-by: Michael Armbrust <michael@databricks.com>


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

Branch: refs/heads/branch-1.3
Commit: 921121d57eafdb18bc3df8420586cf531851910d
Parents: ab0ffde
Author: Liang-Chi Hsieh <viirya@gmail.com>
Authored: Fri Feb 6 12:13:44 2015 -0800
Committer: Michael Armbrust <michael@databricks.com>
Committed: Fri Feb 6 12:13:52 2015 -0800

----------------------------------------------------------------------
 .../scala/org/apache/spark/sql/hive/HiveQl.scala | 19 ++++++++++++++-----
 ...rom clause-0-b42b408a87b258921240058f880a721a |  1 +
 .../sql/hive/execution/HiveQuerySuite.scala      |  3 +++
 3 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/921121d5/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
----------------------------------------------------------------------
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 c19a091..6265c61 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
@@ -556,9 +556,14 @@ https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
     case Token("TOK_TRUNCATETABLE",
           Token("TOK_TABLE_PARTITION",table)::Nil) =>  NativePlaceholder
 
-    case Token("TOK_QUERY",
-           Token("TOK_FROM", fromClause :: Nil) ::
-           insertClauses) =>
+    case Token("TOK_QUERY", queryArgs)
+        if Seq("TOK_FROM", "TOK_INSERT").contains(queryArgs.head.getText) =>
+
+      val (fromClause: Option[ASTNode], insertClauses) = queryArgs match {
+        case Token("TOK_FROM", args: Seq[ASTNode]) :: insertClauses =>
+          (Some(args.head), insertClauses)
+        case Token("TOK_INSERT", _) :: Nil => (None, queryArgs)
+      }
 
       // Return one query for each insert clause.
       val queries = insertClauses.map { case Token("TOK_INSERT", singleInsert) =>
@@ -599,8 +604,12 @@ https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C
               "TOK_LATERAL_VIEW"),
             singleInsert)
         }
-
-        val relations = nodeToRelation(fromClause)
+ 
+        val relations = fromClause match {
+          case Some(f) => nodeToRelation(f)
+          case None => NoRelation
+        }
+ 
         val withWhere = whereClause.map { whereNode =>
           val Seq(whereExpr) = whereNode.getChildren.toSeq
           Filter(nodeToExpr(whereExpr), relations)

http://git-wip-us.apache.org/repos/asf/spark/blob/921121d5/sql/hive/src/test/resources/golden/no
from clause-0-b42b408a87b258921240058f880a721a
----------------------------------------------------------------------
diff --git a/sql/hive/src/test/resources/golden/no from clause-0-b42b408a87b258921240058f880a721a
b/sql/hive/src/test/resources/golden/no from clause-0-b42b408a87b258921240058f880a721a
new file mode 100644
index 0000000..390d344
--- /dev/null
+++ b/sql/hive/src/test/resources/golden/no from clause-0-b42b408a87b258921240058f880a721a

@@ -0,0 +1 @@
+1	1	-1

http://git-wip-us.apache.org/repos/asf/spark/blob/921121d5/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala
----------------------------------------------------------------------
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala
b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala
index bb73ff1..d16a1e0 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala
@@ -202,6 +202,9 @@ class HiveQuerySuite extends HiveComparisonTest with BeforeAndAfter {
   createQueryTest("having no references",
     "SELECT key FROM src GROUP BY key HAVING COUNT(*) > 1")
 
+  createQueryTest("no from clause",
+    "SELECT 1, +1, -1")
+
   createQueryTest("boolean = number",
     """
       |SELECT


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


Mime
View raw message