File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -50,18 +50,18 @@ abstract class RuleExecutor[TreeType <: TreeNode[_]] extends Logging {
5050 var curPlan = plan
5151
5252 batches.foreach { batch =>
53+ val batchStartPlan = curPlan
5354 var iteration = 1
5455 var lastPlan = curPlan
55- curPlan = batch.rules.foldLeft(curPlan) { case (plan, rule) => rule(plan) }
56+ var continue = true
5657
5758 // Run until fix point (or the max number of iterations as specified in the strategy.
58- while (iteration < batch.strategy.maxIterations && ! curPlan.fastEquals(lastPlan)) {
59- lastPlan = curPlan
59+ while (continue) {
6060 curPlan = batch.rules.foldLeft(curPlan) {
6161 case (plan, rule) =>
6262 val result = rule(plan)
6363 if (! result.fastEquals(plan)) {
64- logger.debug (
64+ logger.trace (
6565 s """
6666 |=== Applying Rule ${rule.ruleName} ===
6767 | ${sideBySide(plan.treeString, result.treeString).mkString(" \n " )}
@@ -71,6 +71,26 @@ abstract class RuleExecutor[TreeType <: TreeNode[_]] extends Logging {
7171 result
7272 }
7373 iteration += 1
74+ if (iteration > batch.strategy.maxIterations) {
75+ logger.info(s " Max iterations ( $iteration) reached for batch ${batch.name}" )
76+ continue = false
77+ }
78+
79+ if (curPlan.fastEquals(lastPlan)) {
80+ logger.trace(s " Fixed point reached for batch ${batch.name} after $iteration iterations. " )
81+ continue = false
82+ }
83+ lastPlan = curPlan
84+ }
85+
86+ if (! batchStartPlan.fastEquals(curPlan)) {
87+ logger.debug(
88+ s """
89+ |=== Result of Batch ${batch.name} ===
90+ | ${sideBySide(plan.treeString, curPlan.treeString).mkString(" \n " )}
91+ """ .stripMargin)
92+ } else {
93+ logger.trace(s " Batch ${batch.name} has no effect. " )
7494 }
7595 }
7696
You can’t perform that action at this time.
0 commit comments