Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5330,6 +5330,11 @@
"<treeNode>"
]
},
"SCALAR_SUBQUERY_IN_VALUES" : {
"message" : [
"Scalar subqueries in the VALUES clause."
]
},
"UNSUPPORTED_CORRELATED_EXPRESSION_IN_JOIN_CONDITION" : {
"message" : [
"Correlated subqueries in the join predicate cannot reference both join inputs:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
context = u.origin.getQueryContext,
summary = u.origin.context.summary)

case u: UnresolvedInlineTable if unresolvedInlineTableContainsScalarSubquery(u) =>
throw QueryCompilationErrors.inlineTableContainsScalarSubquery(u)

case command: V2PartitionCommand =>
command.table match {
case r @ ResolvedTable(_, _, table, _) => table match {
Expand Down Expand Up @@ -1559,6 +1562,15 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
case _ =>
}
}

private def unresolvedInlineTableContainsScalarSubquery(
unresolvedInlineTable: UnresolvedInlineTable) = {
unresolvedInlineTable.rows.exists { row =>
row.exists { expression =>
expression.exists(_.isInstanceOf[ScalarSubquery])
}
}
}
}

// a heap of the preempted error that only keeps the top priority element, representing the sole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4112,4 +4112,12 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase with Compilat
"expr" -> expr.toString),
origin = expr.origin)
}

def inlineTableContainsScalarSubquery(inlineTable: LogicalPlan): Throwable = {
new AnalysisException(
errorClass = "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.SCALAR_SUBQUERY_IN_VALUES",
messageParameters = Map.empty,
origin = inlineTable.origin
)
}
}
15 changes: 15 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4909,6 +4909,21 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
)
}
}

test("SPARK-49659: Unsupported scalar subqueries in VALUES") {
checkError(
exception = intercept[AnalysisException](
sql("SELECT * FROM VALUES ((SELECT 1) + (SELECT 2))")
),
condition = "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.SCALAR_SUBQUERY_IN_VALUES",
parameters = Map(),
context = ExpectedContext(
fragment = "VALUES ((SELECT 1) + (SELECT 2))",
start = 14,
stop = 45
)
)
}
}

case class Foo(bar: Option[String])