Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,19 @@ package object debug {
*/
def codegenStringSeq(plan: SparkPlan): Seq[(String, String, ByteCodeStats)] = {
val codegenSubtrees = new collection.mutable.HashSet[WholeStageCodegenExec]()
plan transform {
case s: WholeStageCodegenExec =>
codegenSubtrees += s
s
case s => s

def findSubtrees(plan: SparkPlan): Unit = {
plan transform {
case s: WholeStageCodegenExec =>
codegenSubtrees += s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code below has the same issue?

val codegenSubtrees = new collection.mutable.HashSet[WholeStageCodegenExec]()
plan foreach {
case s: WholeStageCodegenExec =>
codegenSubtrees += s
case _ =>
}

s
case s =>
s.subqueries.foreach(findSubtrees)
s
}
}

findSubtrees(plan)
codegenSubtrees.toSeq.sortBy(_.codegenStageId).map { subtree =>
val (_, source) = subtree.doCodeGen()
val codeStats = try {
Expand Down
19 changes: 19 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/ExplainSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ class ExplainSuite extends ExplainSuiteHelper with DisableAdaptiveExecutionSuite
}
}

test("SPARK-33853: explain codegen - check presence of subquery") {
withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "true") {
withTable("df1") {
spark.range(1, 100)
.write
.format("parquet")
.mode("overwrite")
.saveAsTable("df1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for better test performance, could you use a temporary view instead?


val sqlText = "EXPLAIN CODEGEN SELECT (SELECT min(id) FROM df1)"
val expectedText = "Found 3 WholeStageCodegen subtrees."

withNormalizedExplain(sqlText) { normalizedOutput =>
assert(normalizedOutput.contains(expectedText))
}
}
}
}

test("explain formatted - check presence of subquery in case of DPP") {
withTable("df1", "df2") {
withSQLConf(SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key -> "true",
Expand Down