philo-he commented on code in PR #13747:
URL: https://github.com/apache/gluten/pull/13747#discussion_r4691584561
##########
gluten-substrait/src/main/scala/org/apache/spark/sql/execution/GlutenExplainUtils.scala:
##########
@@ -119,16 +119,19 @@ object GlutenExplainUtils extends AdaptiveSparkPlanHelper
{
* from physical or logical [[FallbackTags]], or a synthetic default
when no tag is present
* - nodes ignored by [[shouldIgnoreInFallbackStats]]: no callback
*
- * Recurses into AQE subqueries and query stages, and into each visited
operator's
- * `innerChildren`. Subqueries reached purely via expressions on a vanilla
Spark plan are not
- * visited here; callers that need full subquery coverage should use
[[processPlan]], which
- * performs an explicit subquery walk.
+ * Recurses into finalized AQE subqueries and query stages, and into each
visited operator's
+ * `innerChildren`. Unfinished AQE subqueries are skipped because their
columnar rules have not
+ * run yet; their plans are checked when AQE prepares their stages.
Subqueries reached purely via
+ * expressions on a vanilla Spark plan are not visited here; callers that
need full subquery
+ * coverage should use [[processPlan]], which performs an explicit subquery
walk.
*/
def visitFallbackNodes(
plan: QueryPlan[_],
onFallback: (SparkPlan, String) => Unit,
onGluten: SparkPlan => Unit = _ => ()): Unit = {
+ val visited = newSetFromMap[AnyRef](new util.IdentityHashMap())
Review Comment:
The dedup also changes `numGlutenNodes` and the fallback counts shown in the
UI whenever one node instance is reachable by more than one path. That seems
like the right behavior, but could the scaladoc above say each node instance is
visited at most once?
##########
gluten-substrait/src/main/scala/org/apache/spark/sql/execution/GlutenExplainUtils.scala:
##########
@@ -138,26 +141,35 @@ object GlutenExplainUtils extends AdaptiveSparkPlanHelper
{
def visit(tmp: QueryPlan[_]): Unit = {
tmp.foreachUp {
- case cmd: CommandResultExec => visit(cmd.commandPhysicalPlan)
- case p: V2CommandExec
- if !shouldIgnoreInFallbackStats(p) =>
- onFallback(p, fallbackReason(p))
- case sub: AdaptiveSparkPlanExec if sub.isSubquery =>
visit(sub.executedPlan)
- case p: QueryStageExec => visit(p.plan)
- case i: InMemoryTableScanExec =>
- if (PlanUtil.isGlutenTableCache(i)) {
- onGluten(i)
- } else {
- onFallback(i, "Columnar table cache is disabled")
+ node =>
+ if (visited.add(node.asInstanceOf[AnyRef])) {
+ node match {
+ case cmd: CommandResultExec => visit(cmd.commandPhysicalPlan)
+ case p: V2CommandExec
+ if !shouldIgnoreInFallbackStats(p) =>
+ onFallback(p, fallbackReason(p))
+ // AQE is a leaf, so foreachUp cannot enter its plan before this
guard.
+ case sub: AdaptiveSparkPlanExec if sub.isSubquery &&
sub.isFinalPlan =>
+ visit(sub.executedPlan)
+ case reused: ReusedSubqueryExec => visit(reused.child)
+ case p: QueryStageExec => visit(p.plan)
+ case i: InMemoryTableScanExec =>
+ if (PlanUtil.isGlutenTableCache(i)) {
+ onGluten(i)
+ } else {
+ onFallback(i, "Columnar table cache is disabled")
+ }
+ case p: SparkPlan if shouldIgnoreInFallbackStats(p) => // Ignore
+ case p: GlutenPlan =>
+ onGluten(p)
+ p.innerChildren.foreach(visit)
+ case _: BaseSubqueryExec =>
Review Comment:
This ignores every non-Gluten `BaseSubqueryExec`, not just the
`SubqueryExec` wrapper. That also covers vanilla `SubqueryBroadcastExec` (DPP).
If Gluten fails to convert it to `ColumnarSubqueryBroadcastExec`, that's a real
fallback, and it would no longer be reported. Its child exchange is still
visited, but the node itself is dropped. Could we narrow this to `case _:
SubqueryExec =>`? `ReusedSubqueryExec` is already handled above. If ignoring
all of them is intentional, please add a comment explaining why.
##########
gluten-substrait/src/main/scala/org/apache/spark/sql/execution/GlutenExplainUtils.scala:
##########
@@ -119,16 +119,19 @@ object GlutenExplainUtils extends AdaptiveSparkPlanHelper
{
* from physical or logical [[FallbackTags]], or a synthetic default
when no tag is present
* - nodes ignored by [[shouldIgnoreInFallbackStats]]: no callback
*
- * Recurses into AQE subqueries and query stages, and into each visited
operator's
- * `innerChildren`. Subqueries reached purely via expressions on a vanilla
Spark plan are not
- * visited here; callers that need full subquery coverage should use
[[processPlan]], which
- * performs an explicit subquery walk.
+ * Recurses into finalized AQE subqueries and query stages, and into each
visited operator's
Review Comment:
Could we note here that the fallback stats will now omit a subquery that
never executes, e.g. one skipped because of a LIMIT? It's an improvement over
counting it as a fallback, but it's a visible change in the UI and the
end-of-query summary from `GlutenQueryExecutionListener`.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]