aboutsummaryrefslogtreecommitdiff
path: root/sql/hive
diff options
context:
space:
mode:
authorWenchen Fan <wenchen@databricks.com>2016-03-16 10:52:36 -0700
committerReynold Xin <rxin@databricks.com>2016-03-16 10:52:36 -0700
commitd9e8f26d0334f393e3b02d7a3b607be54a2a5efe (patch)
tree9790f502141132cf03c860411031f59cacd366ae /sql/hive
parenteacd9d8eda68260bbda7b0cd07410321dffaf428 (diff)
downloadspark-d9e8f26d0334f393e3b02d7a3b607be54a2a5efe.tar.gz
spark-d9e8f26d0334f393e3b02d7a3b607be54a2a5efe.tar.bz2
spark-d9e8f26d0334f393e3b02d7a3b607be54a2a5efe.zip
[SPARK-13924][SQL] officially support multi-insert
## What changes were proposed in this pull request? There is a feature of hive SQL called multi-insert. For example: ``` FROM src INSERT OVERWRITE TABLE dest1 SELECT key + 1 INSERT OVERWRITE TABLE dest2 SELECT key WHERE key > 2 INSERT OVERWRITE TABLE dest3 SELECT col EXPLODE(arr) exp AS col ... ``` We partially support it currently, with some limitations: 1) WHERE can't reference columns produced by LATERAL VIEW. 2) It's not executed eagerly, i.e. `sql("...multi-insert clause...")` won't take place right away like other commands, e.g. CREATE TABLE. This PR removes these limitations and make us fully support multi-insert. ## How was this patch tested? new tests in `SQLQuerySuite` Author: Wenchen Fan <wenchen@databricks.com> Closes #11754 from cloud-fan/lateral-view.
Diffstat (limited to 'sql/hive')
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala29
1 files changed, 29 insertions, 0 deletions
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 21dfb82876..d6c10d6ed9 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
@@ -1777,4 +1777,33 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
|FROM (SELECT '{"f1": "value1", "f2": 12}' json, 'hello' as str) test
""".stripMargin), Row("value1", "12", BigDecimal("3.14"), "hello"))
}
+
+ test("multi-insert with lateral view") {
+ withTempTable("t1") {
+ sqlContext.range(10)
+ .select(array($"id", $"id" + 1).as("arr"), $"id")
+ .registerTempTable("source")
+ withTable("dest1", "dest2") {
+ sql("CREATE TABLE dest1 (i INT)")
+ sql("CREATE TABLE dest2 (i INT)")
+ sql(
+ """
+ |FROM source
+ |INSERT OVERWRITE TABLE dest1
+ |SELECT id
+ |WHERE id > 3
+ |INSERT OVERWRITE TABLE dest2
+ |select col LATERAL VIEW EXPLODE(arr) exp AS col
+ |WHERE col > 3
+ """.stripMargin)
+
+ checkAnswer(
+ sqlContext.table("dest1"),
+ sql("SELECT id FROM source WHERE id > 3"))
+ checkAnswer(
+ sqlContext.table("dest2"),
+ sql("SELECT col FROM source LATERAL VIEW EXPLODE(arr) exp AS col WHERE col > 3"))
+ }
+ }
+ }
}