Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/11190#discussion_r53545811
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala ---
@@ -122,7 +125,32 @@ abstract class SparkPlan extends QueryPlan[SparkPlan]
with Logging with Serializ
final def prepare(): Unit = {
if (prepareCalled.compareAndSet(false, true)) {
doPrepare()
+
+ // collect all the subqueries and submit jobs to execute them in
background
+ val queryResults = ArrayBuffer[(SparkScalarSubquery,
Future[Array[InternalRow]])]()
+ val allSubqueries = expressions.flatMap(_.collect {case e:
SparkScalarSubquery => e})
+ allSubqueries.foreach { e =>
+ val futureResult = Future {
+ e.plan.executeCollect()
+ }(SparkPlan.subqueryExecutionContext)
+ queryResults += e -> futureResult
+ }
+
children.foreach(_.prepare())
+
+ // fill in the result of subqueries
+ queryResults.foreach {
+ case (e, futureResult) =>
+ val rows = Await.result(futureResult, Duration.Inf)
+ if (rows.length > 1) {
+ sys.error(s"Scalar subquery should return at most one row, but
got ${rows.length}: " +
--- End diff --
we can use postgres' error message: "more than one row returned by a
subquery used as an expression"
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]