aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test/scala
diff options
context:
space:
mode:
authorNattavut Sutyanyong <nsy.can@gmail.com>2016-08-08 12:14:11 +0200
committerHerman van Hovell <hvanhovell@databricks.com>2016-08-08 12:14:11 +0200
commit06f5dc841517e7156f5f445655d97ba541ebbd7e (patch)
tree2cafb3241c4845131956ed0880cd29cd0dc95d56 /sql/core/src/test/scala
parente10ca8de49206087b336c6db0c40868fa271b989 (diff)
downloadspark-06f5dc841517e7156f5f445655d97ba541ebbd7e.tar.gz
spark-06f5dc841517e7156f5f445655d97ba541ebbd7e.tar.bz2
spark-06f5dc841517e7156f5f445655d97ba541ebbd7e.zip
[SPARK-16804][SQL] Correlated subqueries containing non-deterministic operations return incorrect results
## What changes were proposed in this pull request? This patch fixes the incorrect results in the rule ResolveSubquery in Catalyst's Analysis phase by returning an error message when the LIMIT is found in the path from the parent table to the correlated predicate in the subquery. ## How was this patch tested? ./dev/run-tests a new unit test on the problematic pattern. Author: Nattavut Sutyanyong <nsy.can@gmail.com> Closes #14411 from nsyca/master.
Diffstat (limited to 'sql/core/src/test/scala')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
index afed342ff8..52387b4b72 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
@@ -571,4 +571,33 @@ class SubquerySuite extends QueryTest with SharedSQLContext {
Row(1.0, false) :: Row(1.0, false) :: Row(2.0, true) :: Row(2.0, true) ::
Row(3.0, false) :: Row(5.0, true) :: Row(null, false) :: Row(null, true) :: Nil)
}
+
+ test("SPARK-16804: Correlated subqueries containing LIMIT - 1") {
+ withTempView("onerow") {
+ Seq(1).toDF("c1").createOrReplaceTempView("onerow")
+
+ checkAnswer(
+ sql(
+ """
+ | select c1 from onerow t1
+ | where exists (select 1 from onerow t2 where t1.c1=t2.c1)
+ | and exists (select 1 from onerow LIMIT 1)""".stripMargin),
+ Row(1) :: Nil)
+ }
+ }
+
+ test("SPARK-16804: Correlated subqueries containing LIMIT - 2") {
+ withTempView("onerow") {
+ Seq(1).toDF("c1").createOrReplaceTempView("onerow")
+
+ checkAnswer(
+ sql(
+ """
+ | select c1 from onerow t1
+ | where exists (select 1
+ | from (select 1 from onerow t2 LIMIT 1)
+ | where t1.c1=t2.c1)""".stripMargin),
+ Row(1) :: Nil)
+ }
+ }
}