Skip to content

Commit c99011d

Browse files
committed
Address comment.
1 parent 9170ceb commit c99011d

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.apache.spark.sql.catalyst.plans.logical._
2929
import org.apache.spark.sql.catalyst.rules._
3030
import org.apache.spark.sql.internal.SQLConf
3131
import org.apache.spark.sql.types._
32+
import org.apache.spark.util.Utils
3233

3334
/**
3435
* Abstract class all optimizers should inherit of, contains the standard batches (extending
@@ -39,9 +40,9 @@ abstract class Optimizer(sessionCatalog: SessionCatalog)
3940

4041
// Check for structural integrity of the plan in test mode. Currently we only check if a plan is
4142
// still resolved after the execution of each rule.
42-
override protected def planChecker: Option[LogicalPlan => Boolean] = Some(
43-
(plan: LogicalPlan) => plan.resolved
44-
)
43+
override protected def planChecker(plan: LogicalPlan): Boolean = {
44+
Utils.isTesting && plan.resolved
45+
}
4546

4647
protected def fixedPoint = FixedPoint(SQLConf.get.optimizerMaxIterations)
4748

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ abstract class RuleExecutor[TreeType <: TreeNode[_]] extends Logging {
6464
protected def batches: Seq[Batch]
6565

6666
/**
67-
* Defines a check function which checks for structural integrity of the plan in test mode after
68-
* the execution of each rule. For example, we can check whether a plan is still resolved after
69-
* each rule in `Optimizer`, so we can catch rules that return invalid plans. The check function
70-
* returns `false` if the given plan doesn't pass the structural integrity check.
67+
* Defines a check function which checks for structural integrity of the plan after the execution
68+
* of each rule. For example, we can check whether a plan is still resolved after each rule in
69+
* `Optimizer`, so we can catch rules that return invalid plans. The check function will returns
70+
* `false` if the given plan doesn't pass the structural integrity check.
7171
*/
72-
protected def planChecker: Option[TreeType => Boolean] = None
72+
protected def planChecker(plan: TreeType): Boolean = true
7373

7474
/**
7575
* Executes the batches of rules defined by the subclass. The batches are executed serially
@@ -101,8 +101,8 @@ abstract class RuleExecutor[TreeType <: TreeNode[_]] extends Logging {
101101
""".stripMargin)
102102
}
103103

104-
// In test mode, run the structural integrity checker against the plan after each rule.
105-
if (Utils.isTesting && !planChecker.map(_.apply(result)).getOrElse(true)) {
104+
// Run the structural integrity checker against the plan after each rule.
105+
if (!planChecker(result)) {
106106
val message = s"After applying rule ${rule.ruleName} in batch ${batch.name}, " +
107107
"the structural integrity of the plan is broken."
108108
throw new TreeNodeException(result, message, null)

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,10 @@ class RuleExecutorSuite extends SparkFunSuite {
5959

6060
test("structural integrity checker") {
6161
object WithSIChecker extends RuleExecutor[Expression] {
62-
override protected def planChecker: Option[Expression => Boolean] = Some(
63-
(expr: Expression) => {
64-
expr match {
65-
case IntegerLiteral(_) => true
66-
case _ => false
67-
}
68-
}
69-
)
62+
override protected def planChecker(expr: Expression): Boolean = expr match {
63+
case IntegerLiteral(_) => true
64+
case _ => false
65+
}
7066
val batches = Batch("once", Once, DecrementLiterals) :: Nil
7167
}
7268

0 commit comments

Comments
 (0)