Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11190#discussion_r53546940
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala ---
    @@ -122,7 +125,35 @@ 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[(ScalarSubquery, 
Future[Array[InternalRow]])]()
    +      val allSubqueries = expressions.flatMap(_.collect {case e: 
ScalarSubquery => 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}: " +
    +              s"${e.query.treeString}")
    +          }
    +          if (rows.length > 0) {
    +            assert(rows(0).numFields == 1, "Analyzer should make sure this 
only returns one column")
    +            e.updateResult(rows(0).get(0, e.dataType))
    +          } else {
    +            // the result should be null, since the expression already 
have null as default value,
    +            // we don't need to update that.
    --- End diff --
    
    why not set it explicitly here so the behavior is defined entirely in this 
tiny function?



---
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]

Reply via email to