RuleExecutor Contract — Tree Transformation Rule Executor
RuleExecutor
is the base of rule executors that are responsible for executing a collection of batches (of rules) to transform a TreeNode.
1 2 3 4 5 6 7 8 9 10 11 |
package org.apache.spark.sql.catalyst.rules abstract class RuleExecutor[TreeType <: TreeNode[_]] { // only required properties (vals and methods) that have no implementation // the others follow protected def batches: Seq[Batch] } |
Property | Description | ||
---|---|---|---|
|
Collection of rule batches, i.e. a sequence of a collection of rules with a name and a strategy that |
Note
|
TreeType is the type of the TreeNode implementation that a RuleExecutor can be executed on, i.e. LogicalPlan, SparkPlan, Expression or a combination thereof.
|
RuleExecutor | Description |
---|---|
|
|
Applying Rule Batches to TreeNode — execute
Method
1 2 3 4 5 |
execute(plan: TreeType): TreeType |
execute
iterates over rule batches and applies rules sequentially to the input plan
.
execute
tracks the number of iterations and the time of executing each rule (with a plan).
When a rule changes a plan, you should see the following TRACE message in the logs:
1 2 3 4 5 6 7 |
TRACE HiveSessionStateBuilder$$anon$1: === Applying Rule [ruleName] === [currentAndModifiedPlansSideBySide] |
After the number of iterations has reached the number of iterations for the batch’s Strategy
it stops execution and prints out the following WARN message to the logs:
1 2 3 4 5 |
WARN HiveSessionStateBuilder$$anon$1: Max iterations ([iteration]) reached for batch [batchName] |
When the plan has not changed (after applying rules), you should see the following TRACE message in the logs and execute
moves on to applying the rules in the next batch. The moment is called fixed point (i.e. when the execution converges).
1 2 3 4 5 |
TRACE HiveSessionStateBuilder$$anon$1: Fixed point reached for batch [batchName] after [iteration] iterations. |
After the batch finishes, if the plan has been changed by the rules, you should see the following DEBUG message in the logs:
1 2 3 4 5 6 7 |
DEBUG HiveSessionStateBuilder$$anon$1: === Result of Batch [batchName] === [currentAndModifiedPlansSideBySide] |
Otherwise, when the rules had no changes to a plan, you should see the following TRACE message in the logs:
1 2 3 4 5 |
TRACE HiveSessionStateBuilder$$anon$1: Batch [batchName] has no effect. |
Batch Execution Strategy
Strategy
is the base of the batch execution strategies that indicate the maximum number of executions (aka maxIterations).
1 2 3 4 5 6 7 |
abstract class Strategy { def maxIterations: Int } |
Strategy | Description |
---|---|
|
|
|
A strategy that runs until fix point (i.e. converge) or |
isPlanIntegral
Method
1 2 3 4 5 |
isPlanIntegral(plan: TreeType): Boolean |
isPlanIntegral
simply returns true
.
Note
|
isPlanIntegral is used exclusively when RuleExecutor is requested to execute.
|