spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject git commit: [SQL] Better logging when applying rules.
Date Sun, 04 May 2014 01:38:48 GMT
Repository: spark
Updated Branches:
  refs/heads/master 4669a84ab -> b29571470


[SQL] Better logging when applying rules.

Author: Michael Armbrust <michael@databricks.com>

Closes #616 from marmbrus/ruleLogging and squashes the following commits:

39c09fe [Michael Armbrust] Fix off by one error.
5af3537 [Michael Armbrust] Better logging when applying rules.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/b2957147
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/b2957147
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/b2957147

Branch: refs/heads/master
Commit: b295714708476b2904e205ac6dc58867e205546e
Parents: 4669a84
Author: Michael Armbrust <michael@databricks.com>
Authored: Sat May 3 18:38:44 2014 -0700
Committer: Reynold Xin <rxin@apache.org>
Committed: Sat May 3 18:38:44 2014 -0700

----------------------------------------------------------------------
 .../spark/sql/catalyst/rules/RuleExecutor.scala | 28 +++++++++++++++++---
 1 file changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/b2957147/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
index 9db96f8..e32adb7 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
@@ -50,18 +50,18 @@ abstract class RuleExecutor[TreeType <: TreeNode[_]] extends Logging
{
     var curPlan = plan
 
     batches.foreach { batch =>
+      val batchStartPlan = curPlan
       var iteration = 1
       var lastPlan = curPlan
-      curPlan = batch.rules.foldLeft(curPlan) { case (plan, rule) => rule(plan) }
+      var continue = true
 
       // Run until fix point (or the max number of iterations as specified in the strategy.
-      while (iteration < batch.strategy.maxIterations && !curPlan.fastEquals(lastPlan))
{
-        lastPlan = curPlan
+      while (continue) {
         curPlan = batch.rules.foldLeft(curPlan) {
           case (plan, rule) =>
             val result = rule(plan)
             if (!result.fastEquals(plan)) {
-              logger.debug(
+              logger.trace(
                 s"""
                   |=== Applying Rule ${rule.ruleName} ===
                   |${sideBySide(plan.treeString, result.treeString).mkString("\n")}
@@ -71,6 +71,26 @@ abstract class RuleExecutor[TreeType <: TreeNode[_]] extends Logging
{
             result
         }
         iteration += 1
+        if (iteration > batch.strategy.maxIterations) {
+          logger.info(s"Max iterations ($iteration) reached for batch ${batch.name}")
+          continue = false
+        }
+
+        if (curPlan.fastEquals(lastPlan)) {
+          logger.trace(s"Fixed point reached for batch ${batch.name} after $iteration iterations.")
+          continue = false
+        }
+        lastPlan = curPlan
+      }
+
+      if (!batchStartPlan.fastEquals(curPlan)) {
+        logger.debug(
+          s"""
+          |=== Result of Batch ${batch.name} ===
+          |${sideBySide(plan.treeString, curPlan.treeString).mkString("\n")}
+        """.stripMargin)
+      } else {
+        logger.trace(s"Batch ${batch.name} has no effect.")
       }
     }
 


Mime
View raw message