@@ -301,100 +301,60 @@ case class CometExecRule(session: SparkSession)
301301 }
302302 }
303303
304- // scalastyle:off println
305304 plan.transformUp { case op =>
306- val hasSubqueryExpr = op.expressions.exists(_.exists {
307- case _ : InSubqueryExec => true
308- case _ => false
309- })
310- if (hasSubqueryExpr) {
311- println(s " [RULE-DEBUG] convertNode on ${op.getClass.getSimpleName} " +
312- s " which HAS InSubqueryExec expressions " )
313- op.expressions.foreach { expr =>
314- expr.foreach {
315- case sub : InSubqueryExec =>
316- println(s " [RULE-DEBUG] InSubqueryExec.plan: ${sub.plan.getClass.getSimpleName}" )
317- sub.plan match {
318- case sb : SubqueryBroadcastExec =>
319- println(s " [RULE-DEBUG] SubqueryBroadcast.child: " +
320- s " ${sb.child.getClass.getSimpleName}" )
321- sb.child match {
322- case b : BroadcastExchangeExec =>
323- println(s " [RULE-DEBUG] BroadcastExchange.child: " +
324- s " ${b.child.getClass.getSimpleName}" )
325- println(s " [RULE-DEBUG] BroadcastExchange.child is CometNative? " +
326- s " ${b.child.isInstanceOf [CometNativeExec ]}" )
327- println(s " [RULE-DEBUG] BroadcastExchange.children all CometNative? " +
328- s " ${b.children.forall(_.isInstanceOf [CometNativeExec ])}" )
329- case other =>
330- println(s " [RULE-DEBUG] SubqueryBroadcast.child is: " +
331- s " ${other.getClass.getSimpleName}" )
332- }
333- case other =>
334- println(s " [RULE-DEBUG] sub.plan is: ${other.getClass.getSimpleName}" )
335- }
336- case _ =>
337- }
338- }
339- }
340305 val converted = convertNode(op)
341306 // Replace SubqueryBroadcastExec with CometSubqueryBroadcastExec in DPP expressions
342307 // when the broadcast child has a Comet plan underneath. This enables exchange reuse
343308 // between the DPP subquery and the join's CometBroadcastExchangeExec because both
344309 // will have the same CometBroadcastExchangeExec type and canonical form.
345310 convertSubqueryBroadcasts(converted)
346311 }
347- // scalastyle:on println
348312 }
349313
350314 /**
351315 * Replace SubqueryBroadcastExec with CometSubqueryBroadcastExec in a node's expressions.
352316 *
353- * When CometExecRule converts BroadcastExchangeExec to CometBroadcastExchangeExec on the
354- * join side, the DPP subquery still references the original BroadcastExchangeExec.
355- * ReuseExchangeAndSubquery (which runs after Comet rules) can't match them because they
356- * have different types. By replacing SubqueryBroadcastExec with CometSubqueryBroadcastExec
357- * (which wraps a CometBroadcastExchangeExec), both sides have the same exchange type and
358- * reuse works.
317+ * When CometExecRule converts BroadcastExchangeExec to CometBroadcastExchangeExec on the join
318+ * side, the DPP subquery still references the original BroadcastExchangeExec.
319+ * ReuseExchangeAndSubquery (which runs after Comet rules) can't match them because they have
320+ * different types. By replacing SubqueryBroadcastExec with CometSubqueryBroadcastExec (which
321+ * wraps a CometBroadcastExchangeExec), both sides have the same exchange type and reuse works.
359322 *
360- * The BroadcastExchangeExec in the subquery has a CometNativeColumnarToRowExec child
361- * (inserted by ApplyColumnarRulesAndInsertTransitions because BroadcastExchangeExec expects
362- * row input). We strip this transition and create CometBroadcastExchangeExec with the
363- * underlying Comet plan directly.
323+ * The BroadcastExchangeExec in the subquery has a CometNativeColumnarToRowExec child (inserted
324+ * by ApplyColumnarRulesAndInsertTransitions because BroadcastExchangeExec expects row input).
325+ * We strip this transition and create CometBroadcastExchangeExec with the underlying Comet plan
326+ * directly.
364327 */
365328 private def convertSubqueryBroadcasts (plan : SparkPlan ): SparkPlan = {
366- plan.transformExpressionsUp {
367- case inSub : InSubqueryExec =>
368- inSub.plan match {
369- case sub : SubqueryBroadcastExec =>
370- sub.child match {
371- case b : BroadcastExchangeExec =>
372- // The BroadcastExchangeExec child is CometNativeColumnarToRowExec wrapping
373- // a Comet plan. Strip the row transition to get the columnar Comet plan.
374- val cometChild = b.child match {
375- case c2r : CometNativeColumnarToRowExec => c2r.child
376- case other => other
377- }
378- if (cometChild.isInstanceOf [CometNativeExec ]) {
379- // scalastyle:off println
380- println(s " [RULE-DEBUG] Converting SubqueryBroadcastExec to " +
381- s " CometSubqueryBroadcastExec, cometChild= ${cometChild.getClass.getSimpleName}" )
382- // scalastyle:on println
383- val cometBroadcast = CometBroadcastExchangeExec (
384- b, b.output, b.mode, cometChild)
385- val cometSub = CometSubqueryBroadcastExec (
386- sub.name,
387- getSubqueryBroadcastExecIndices(sub),
388- sub.buildKeys,
389- cometBroadcast)
390- inSub.withNewPlan(cometSub)
391- } else {
392- inSub
393- }
394- case _ => inSub
395- }
396- case _ => inSub
397- }
329+ plan.transformExpressionsUp { case inSub : InSubqueryExec =>
330+ inSub.plan match {
331+ case sub : SubqueryBroadcastExec =>
332+ sub.child match {
333+ case b : BroadcastExchangeExec =>
334+ // The BroadcastExchangeExec child is CometNativeColumnarToRowExec wrapping
335+ // a Comet plan. Strip the row transition to get the columnar Comet plan.
336+ val cometChild = b.child match {
337+ case c2r : CometNativeColumnarToRowExec => c2r.child
338+ case other => other
339+ }
340+ if (cometChild.isInstanceOf [CometNativeExec ]) {
341+ logInfo(
342+ s " Converting SubqueryBroadcastExec to " +
343+ s " CometSubqueryBroadcastExec for DPP exchange reuse " )
344+ val cometBroadcast = CometBroadcastExchangeExec (b, b.output, b.mode, cometChild)
345+ val cometSub = CometSubqueryBroadcastExec (
346+ sub.name,
347+ getSubqueryBroadcastExecIndices(sub),
348+ sub.buildKeys,
349+ cometBroadcast)
350+ inSub.withNewPlan(cometSub)
351+ } else {
352+ inSub
353+ }
354+ case _ => inSub
355+ }
356+ case _ => inSub
357+ }
398358 }
399359 }
400360
0 commit comments