peter-toth commented on a change in pull request #28885:
URL: https://github.com/apache/spark/pull/28885#discussion_r467773298
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/ExchangeSuite.scala
##########
@@ -156,4 +158,46 @@ class ExchangeSuite extends SparkPlanTest with
SharedSparkSession {
val projection2 = cached.select("_1", "_3").queryExecution.executedPlan
assert(!projection1.sameResult(projection2))
}
+
+ test("Exchange reuse across the whole plan") {
+ val df = sql(
+ """
+ |SELECT
+ | (SELECT max(a.key) FROM testData AS a JOIN testData AS b ON b.key =
a.key),
+ | a.key
+ |FROM testData AS a
+ |JOIN testData AS b ON b.key = a.key
+ """.stripMargin)
+
+ val plan = df.queryExecution.executedPlan
+
+ val exchangeIds = plan.collectWithSubqueries { case e: Exchange => e.id }
+ val reusedExchangeIds = plan.collectWithSubqueries {
+ case re: ReusedExchangeExec => re.child.id
+ }
+
+ assert(exchangeIds.size == 2, "Whole plan exchange reusing not working
correctly")
+ assert(reusedExchangeIds.size == 3, "Whole plan exchange reusing not
working correctly")
+ assert(reusedExchangeIds.forall(exchangeIds.contains(_)),
+ "ReusedExchangeExec should reuse an existing exchange")
+
+ val df2 = sql(
Review comment:
> Back to your earlier comment:
>
> > * rule ReuseExchange inserted the ReusedExchange pointing to id=#761
into the plan
> > * rule ReuseExchange altered the exchange node id=#761 to id=X
> > * rule ReuseSubquery altered the exchange node id=X to id=#975
>
> Just checking:
>
> So the second bullet point is issue number 1 and the third bullet point is
issue number 2?
Yes.
> Also checking: did the ReuseSubquery alter the exchange node to #975 or
#979?
No, sorry this was a typo, I meant id=X to id=#979. (Fixed in my original
comment too.)
----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]