Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
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
10 changes: 5 additions & 5 deletions core/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,11 @@
"A correlated outer name reference within a subquery expression body was not found in the enclosing query: <value>"
]
},
"CORRELATED_REFERENCE" : {
"message" : [
"Expressions '<sqlExprs>' referencing the outer query are not supported outside of WHERE/HAVING clauses."
]
},
"LATERAL_JOIN_CONDITION_NON_DETERMINISTIC" : {
"message" : [
"Lateral join condition cannot be non-deterministic: <condition>"
Expand All @@ -1302,11 +1307,6 @@
"Non-deterministic lateral subqueries are not supported when joining with outer relations that produce more than one row<treeNode>"
]
},
"UNSUPPORTED_CORRELATED_REFERENCE" : {
"message" : [
"Expressions referencing the outer query are not supported outside of WHERE/HAVING clauses<treeNode>"
]
},
"UNSUPPORTED_CORRELATED_REFERENCE_DATA_TYPE" : {
"message" : [
"Correlated column reference '<expr>' cannot be <dataType> type"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,8 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
if (!canHostOuter(p) && p.expressions.exists(containsOuter)) {
p.failAnalysis(
errorClass =
"UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_CORRELATED_REFERENCE",
messageParameters = Map("treeNode" -> planToString(p)))
"UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.CORRELATED_REFERENCE",
messageParameters = Map("sqlExprs" -> p.expressions.map(_.sql).mkString(",")))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ class ResolveSubquerySuite extends AnalysisTest {
test("SPARK-17251 Improve `OuterReference` to be `NamedExpression`") {
val expr = Filter(
InSubquery(Seq(a), ListQuery(Project(Seq(UnresolvedAttribute("a")), t2))), t1)
val m = intercept[AnalysisException] {
SimpleAnalyzer.checkAnalysis(SimpleAnalyzer.ResolveSubquery(expr))
}.getMessage
assert(m.contains(
"Expressions referencing the outer query are not supported outside of WHERE/HAVING clauses"))
checkError(
exception = intercept[AnalysisException] {
SimpleAnalyzer.checkAnalysis(SimpleAnalyzer.ResolveSubquery(expr))
},
errorClass = "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.CORRELATED_REFERENCE",
parameters = Map("sqlExprs" -> "outer(a)")
)
}

test("SPARK-29145 Support subquery in join condition") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_CORRELATED_REFERENCE",
"errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.CORRELATED_REFERENCE",
"messageParameters" : {
"treeNode" : "Aggregate [min(outer(t2a#x)) AS min(outer(t2.t2a))#x]\n+- SubqueryAlias t3\n +- View (`t3`, [t3a#x,t3b#x,t3c#x])\n +- Project [cast(t3a#x as int) AS t3a#x, cast(t3b#x as int) AS t3b#x, cast(t3c#x as int) AS t3c#x]\n +- Project [t3a#x, t3b#x, t3c#x]\n +- SubqueryAlias t3\n +- LocalRelation [t3a#x, t3b#x, t3c#x]\n"
"sqlExprs" : "min(outer(t2.t2a)) AS `min(outer(t2.t2a))`"
},
"queryContext" : [ {
"objectType" : "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,17 +964,14 @@ class SubquerySuite extends QueryTest
| WHERE t1.c1 = t2.c1)
""".stripMargin)
}
checkErrorMatchPVals(
checkError(
exception1,
errorClass = "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_CORRELATED_REFERENCE",
parameters = Map("treeNode" -> "(?s).*"),
sqlState = None,
errorClass = "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.CORRELATED_REFERENCE",
parameters = Map("sqlExprs" -> "explode(outer(t2.arr_c2)),c2"),
context = ExpectedContext(
fragment = "LATERAL VIEW explode(t2.arr_c2) q AS c2",
start = 68,
stop = 106))
assert(exception1.getMessage.contains(
"Expressions referencing the outer query are not supported outside of WHERE/HAVING"))
}
}

Expand Down