Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
[SPARK-16804][SQL] Correlated subqueries containing LIMIT return inco…
…rrect results

## What changes were proposed in this pull request?

This patch fixes the incorrect results in the rule ResolveSubquery in Catalyst's Analysis phase.

## How was this patch tested?
./dev/run-tests
a new unit test on the problematic pattern.
  • Loading branch information
nsyca committed Jul 29, 2016
commit b98865127a39bde885f9b1680cfe608629d59d51
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,16 @@ class Analyzer(
case e: Expand =>
failOnOuterReferenceInSubTree(e, "an EXPAND")
e
case l @ LocalLimit(_, child) =>
failOnOuterReferenceInSubTree(l, "LIMIT")
l
// Since LIMIT <n> is represented as GlobalLimit(<n>, (LocalLimit (<n>, child))
// and we are walking bottom up, we will fail on LocalLimit before
// reaching GlobalLimit.
// The code below is just a safety net.
case g @ GlobalLimit(_, child) =>
failOnOuterReferenceInSubTree(g, "LIMIT")
g
case p =>
failOnOuterReference(p)
p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,5 +533,13 @@ class AnalysisErrorSuite extends AnalysisTest {
Exists(Union(LocalRelation(b), Filter(EqualTo(OuterReference(a), c), LocalRelation(c)))),
LocalRelation(a))
assertAnalysisError(plan3, "Accessing outer query column is not allowed in" :: Nil)

val plan4 = Filter(
Exists(
Limit(1,
Filter(EqualTo(OuterReference(a), b), LocalRelation(b)))
),
LocalRelation(a))
assertAnalysisError(plan4, "Accessing outer query column is not allowed in LIMIT" :: Nil)
}
}