dilipbiswal commented on issue #26039: [SPARK-29366][SQL] Subqueries created 
for DPP are not printed in EXPLAIN FORMATTED
URL: https://github.com/apache/spark/pull/26039#issuecomment-539248669
 
 
   @gatorsmile @cloud-fan 
   I was trying to find out why using flatMap causes the issue of missing 
subqueries. It turns out that `p.expressions` returns a immutable stream. And 
the result of `foreach` is different than `flatMap`. Here is what i tried.
   
   ```scala
   def printExpressionsFlatMap(p: SparkPlan, exprs: Seq[Expression]): Unit = {
     if (p.isInstanceOf[FileSourceScanExec]) {
        println("flatmap")
        exprs.flatMap { e =>
           println(s"SQL : ${e.sql} toString= ${e.toString}")
          e :: Nil
       }
     }
    return
   }
   
   def printExpressionsForEach(p: SparkPlan, exprs: Seq[Expression]): Unit = {
     if (p.isInstanceOf[FileSourceScanExec]) {
       println("foreach")
      exprs.foreach(e => println(s"SQL : ${e.sql} toString= ${e.toString}"))
     }
   }
   ```
   When i call the above methods for the same input `p.expressions` i get 
different output.
   But if i materialize the stream by calling `p.expressions.toList` then both 
the methods return the same output. It is not related to this PR. But just 
wanted to describe my observation.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to