Skip to content

Commit e945bf1

Browse files
committed
[SPARK-25278][SQL] Avoid duplicated Exec nodes when the same logical plan appears in the query
1 parent 3c67cb0 commit e945bf1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/QueryPlanner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ abstract class QueryPlanner[PhysicalPlan <: TreeNode[PhysicalPlan]] {
8181
childPlans.map { childPlan =>
8282
// Replace the placeholder by the child plan
8383
candidateWithPlaceholders.transformUp {
84-
case p if p == placeholder => childPlan
84+
case p if p.eq(placeholder) => childPlan
8585
}
8686
}
8787
}

sql/core/src/test/scala/org/apache/spark/sql/execution/metric/SQLMetricsSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,17 @@ class SQLMetricsSuite extends SparkFunSuite with SQLMetricsTestUtils with Shared
497497
}
498498
}
499499

500+
test("SPARK-25278: output metrics are wrong for plans repeated in the query") {
501+
val name = "demo_view"
502+
sql(s"CREATE OR REPLACE VIEW $name AS VALUES 1,2")
503+
val view = spark.table(name)
504+
val union = view.union(view)
505+
testSparkPlanMetrics(union, 1, Map(
506+
0L -> ("Union" -> Map()),
507+
1L -> ("LocalTableScan" -> Map("number of output rows" -> 2L)),
508+
2L -> ("LocalTableScan" -> Map("number of output rows" -> 2L))))
509+
}
510+
500511
test("writing data out metrics: parquet") {
501512
testMetricsNonDynamicPartition("parquet", "t1")
502513
}

0 commit comments

Comments
 (0)