Skip to content

Commit

Permalink
Merge pull request apache#35 from marmbrus/smallFixes
Browse files Browse the repository at this point in the history
A few small bug fixes and improvements.
  • Loading branch information
marmbrus committed Feb 7, 2014
2 parents 5479066 + ccdb07a commit 5e4d9b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/main/scala/catalyst/analysis/HiveTypeCoercion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ trait HiveTypeCoercion {
case Sum(e) if e.dataType == StringType =>
Sum(Cast(e, DoubleType))
case Average(e) if e.dataType == StringType =>
Sum(Cast(e, DoubleType))
Average(Cast(e, DoubleType))
}
}

Expand Down Expand Up @@ -252,7 +252,6 @@ trait HiveTypeCoercion {
case s @ Sum(e @ DecimalType()) => s // Decimal is already the biggest.
case Sum(e @ IntegralType()) if e.dataType != LongType => Sum(Cast(e, LongType))
case Sum(e @ FractionalType()) if e.dataType != DoubleType => Sum(Cast(e, DoubleType))

}
}
}
17 changes: 15 additions & 2 deletions src/main/scala/catalyst/rules/RuleExecutor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package catalyst
package rules

import trees._
import util._

abstract class RuleExecutor[TreeType <: TreeNode[_]] {
abstract class RuleExecutor[TreeType <: TreeNode[_]] extends Logging {

/**
* An execution strategy for rules that indicates the maximum number of executions. If the
Expand Down Expand Up @@ -38,7 +39,19 @@ abstract class RuleExecutor[TreeType <: TreeNode[_]] {
// 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
curPlan = batch.rules.foldLeft(curPlan) { case (curPlan, rule) => rule(curPlan) }
curPlan = batch.rules.foldLeft(curPlan) {
case (curPlan, rule) =>
val result = rule(curPlan)
if(!result.fastEquals(curPlan)) {
logger.debug(
s"""
|=== Applying Rule ${rule.ruleName} ===
|${sideBySide(curPlan.treeString, result.treeString).mkString("\n")}
""".stripMargin)
}

result
}
iteration += 1
}
}
Expand Down

0 comments on commit 5e4d9b4

Please sign in to comment.