Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b988651
[SPARK-16804][SQL] Correlated subqueries containing LIMIT return inco…
nsyca Jul 29, 2016
069ed8f
[SPARK-16804][SQL] Correlated subqueries containing LIMIT return inco…
nsyca Jul 29, 2016
edca333
New positive test cases
nsyca Jul 30, 2016
64184fd
Fix unit test case failure
nsyca Aug 1, 2016
29f82b0
blocking TABLESAMPLE
nsyca Aug 5, 2016
ac43ab4
Fixing code styling
nsyca Aug 5, 2016
631d396
Correcting Scala test style
nsyca Aug 7, 2016
7eb9b2d
One (last) attempt to correct the Scala style tests
nsyca Aug 8, 2016
1387cf5
Merge remote-tracking branch 'upstream/master'
nsyca Aug 12, 2016
6d9bade
Merge remote-tracking branch 'upstream/master'
nsyca Nov 4, 2016
9a1f80b
Merge remote-tracking branch 'upstream/master'
nsyca Nov 4, 2016
3fe9429
Merge remote-tracking branch 'upstream/master'
nsyca Nov 5, 2016
0757b81
Merge remote-tracking branch 'upstream/master'
nsyca Nov 11, 2016
35b77f0
Merge remote-tracking branch 'upstream/master'
nsyca Nov 12, 2016
c63b8c6
Merge remote-tracking branch 'upstream/master'
nsyca Nov 14, 2016
f3351d5
Merge remote-tracking branch 'upstream/master'
nsyca Nov 18, 2016
9fc5c33
Merge remote-tracking branch 'upstream/master'
nsyca Nov 18, 2016
402e1d9
Merge remote-tracking branch 'upstream/master'
nsyca Nov 22, 2016
b117281
Merge remote-tracking branch 'upstream/master'
nsyca Nov 23, 2016
3023399
Merge remote-tracking branch 'upstream/master'
nsyca Nov 24, 2016
099f75d
Fix FOJ bug/Window bug
nsyca Nov 24, 2016
5d6cc8e
FOJ:reduce to only one call
nsyca Nov 24, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,10 @@ class Analyzer(

// Simplify the predicates before pulling them out.
val transformed = BooleanSimplification(sub) transformUp {
// WARNING:
// Only Filter can host correlated expressions at this time
// Anyone adding a new "case" below needs to add the call to
// "failOnOuterReference" to disallow correlated expressions in it.
case f @ Filter(cond, child) =>
// Find all predicates with an outer reference.
val (correlated, local) = splitConjunctivePredicates(cond).partition(containsOuter)
Expand Down Expand Up @@ -1116,12 +1120,18 @@ class Analyzer(
a
}
case w : Window =>
failOnOuterReference(w)
failOnNonEqualCorrelatedPredicate(foundNonEqualCorrelatedPred, w)
w
case j @ Join(left, _, RightOuter, _) =>
failOnOuterReference(j)
failOnOuterReferenceInSubTree(left, "a RIGHT OUTER JOIN")
j
// SPARK-18578: Do not allow any correlated predicate
// in a Full (Outer) Join operator and its descendants
case j @ Join(_, _, FullOuter, _) =>
failOnOuterReferenceInSubTree(j, "a FULL OUTER JOIN")
j
case j @ Join(_, right, jt, _) if !jt.isInstanceOf[InnerLike] =>
failOnOuterReference(j)
failOnOuterReferenceInSubTree(right, "a LEFT (OUTER) JOIN")
Expand Down
45 changes: 45 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -744,4 +744,49 @@ class SubquerySuite extends QueryTest with SharedSQLContext {
}
}
}
// This restriction applies to
// the permutation of { LOJ, ROJ, FOJ } x { EXISTS, IN, scalar subquery }
// where correlated predicates appears in right operand of LOJ,
// or in left operand of ROJ, or in either operand of FOJ.
// The test cases below cover the representatives of the patterns
test("Correlated subqueries in outer joins") {
withTempView("t1", "t2", "t3") {
Seq(1).toDF("c1").createOrReplaceTempView("t1")
Seq(2).toDF("c1").createOrReplaceTempView("t2")
Seq(1).toDF("c1").createOrReplaceTempView("t3")

// Left outer join (LOJ) in IN subquery context
intercept[AnalysisException] {
sql(
"""
| select t1.c1
| from t1
| where 1 IN (select 1
| from t3 left outer join
| (select c1 from t2 where t1.c1 = 2) t2
| on t2.c1 = t3.c1)""".stripMargin).collect()
}
// Right outer join (ROJ) in EXISTS subquery context
intercept[AnalysisException] {
sql(
"""
| select t1.c1
| from t1
| where exists (select 1
| from (select c1 from t2 where t1.c1 = 2) t2
| right outer join t3
| on t2.c1 = t3.c1)""".stripMargin).collect()
}
// SPARK-18578: Full outer join (FOJ) in scalar subquery context
intercept[AnalysisException] {
sql(
"""
| select (select max(1)
| from (select c1 from t2 where t1.c1 = 2 and t1.c1=t2.c1) t2
| full join t3
| on t2.c1=t3.c1)
| from t1""".stripMargin).collect()
}
}
}
}