Skip to content

Commit fe317dc

Browse files
mgaido91HyukjinKwon
authored andcommitted
[SPARK-27243][SQL] RuleExecutor.dumpTimeSpent should not throw exception when empty
## What changes were proposed in this pull request? `RuleExecutor.dumpTimeSpent` currently throws an exception when invoked before any rule is run or immediately after `RuleExecutor.reset`. The PR makes it returning an empty summary, which is the expected output instead. ## How was this patch tested? added UT Closes apache#24180 from mgaido91/SPARK-27243. Authored-by: Marco Gaido <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent 68abf77 commit fe317dc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/QueryExecutionMetering.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ case class QueryExecutionMetering() {
6464
/** Dump statistics about time spent running specific rules. */
6565
def dumpTimeSpent(): String = {
6666
val map = timeMap.asMap().asScala
67-
val maxLengthRuleNames = map.keys.map(_.toString.length).max
67+
val maxLengthRuleNames = if (map.isEmpty) {
68+
0
69+
} else {
70+
map.keys.map(_.toString.length).max
71+
}
6872

6973
val colRuleName = "Rule".padTo(maxLengthRuleNames, " ").mkString
7074
val colRunTime = "Effective Time / Total Time".padTo(len = 47, " ").mkString

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/trees/RuleExecutorSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,10 @@ class RuleExecutorSuite extends SparkFunSuite {
9191
}.getMessage
9292
assert(message.contains("the structural integrity of the plan is broken"))
9393
}
94+
95+
test("SPARK-27243: dumpTimeSpent when no rule has run") {
96+
RuleExecutor.resetMetrics()
97+
// This should not throw an exception
98+
RuleExecutor.dumpTimeSpent()
99+
}
94100
}

0 commit comments

Comments
 (0)