Github user lianhuiwang commented on the issue:
https://github.com/apache/spark/pull/14111
@cloud-fan At firstly I have implemented it with you said. But the
following situation that has broadcast join will have a error 'ScalarSubquery
has not finished', example (from SPARK-14791):
val df = (1 to 3).map(i => (i, i)).toDF("key", "value")
df.createOrReplaceTempView("t1")
df.createOrReplaceTempView("t2")
df.createOrReplaceTempView("t3")
val q = sql("select * from t1 join (select key, value from t2 " +
" where key > (select avg (key) from t3))t on (t1.key = t.key)")
Before:
'''
*BroadcastHashJoin [key#5], [key#26], Inner, BuildRight
:- *Project [_1#2 AS key#5, _2#3 AS value#6]
: +- *Filter (cast(_1#2 as double) > subquery#13)
: : +- Subquery subquery#13
: : +- *HashAggregate(keys=[], functions=[avg(cast(key#5 as
bigint))], output=[avg(key)#25])
: : +- Exchange SinglePartition
: : +- *HashAggregate(keys=[],
functions=[partial_avg(cast(key#5 as bigint))], output=[sum#30, count#31L])
: : +- LocalTableScan [key#5]
: +- LocalTableScan [_1#2, _2#3]
+- BroadcastExchange HashedRelationBroadcastMode(List(cast(input[0, int,
false] as bigint)))
+- *Project [_1#2 AS key#26, _2#3 AS value#27]
+- *Filter (cast(_1#2 as double) > subquery#13)
: +- Subquery subquery#13
: +- *HashAggregate(keys=[], functions=[avg(cast(key#5 as
bigint))], output=[avg(key)#25])
: +- Exchange SinglePartition
: +- *HashAggregate(keys=[],
functions=[partial_avg(cast(key#5 as bigint))], output=[sum#30, count#31L])
: +- LocalTableScan [key#5]
+- LocalTableScan [_1#2, _2#3]
'''
The steps are as follows:
1. BroadcastHashJoin.prepare()
2. t1.Filter.prepareSubqueries, it will prepare subquery.
3. BroadcastExchange.prepare()
4. t2.Filter.prepareSubqueries, it will prepare subquery.
5. BroadcastExchange.doPrepare()
6. t2.Filter.execute()
7. t2.Filter.waitForSubqueries(), it will wait for subquery.
8. BroadcastHashJoin.doExecute()
9. BroadcastExchange.executeBroadcast()
10. t1.Filter.execute()
11. t1.Filter.waitForSubqueries(), it will wait for subquery.
because before that there are two different subqueries, they cannot wait
for other's results.
But after this PR, they are the same subquery, the steps are as follows:
1. t1.Filter.prepareSubqueries, it will prepare subquery.
2. t2.Filter.prepareSubqueries, it will do not submit subquery's
execute().
3. t2.Filter.waitForSubqueries(), it will can wait for subquery that step-1
have submitted before.
4. t1.Filter.waitForSubqueries(), it do not await subquery's results
because step-3 have updated.
So I make some logical codes to ScalarSubquery in order to deal with it.
---
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]