org.apache.pig.newplan.optimizer
Class PlanOptimizer

java.lang.Object
  extended by org.apache.pig.newplan.optimizer.PlanOptimizer
Direct Known Subclasses:
LogicalPlanOptimizer

public abstract class PlanOptimizer
extends Object

The core class of the optimizer. The basic design of this class is that it is provided a list of RuleSets. RuleSets represent all of the optimizer rules that can be run together. The rules in the RuleSet will be run repeatedly until either no rule in the RuleSet passes check and calls transform or until maxIter iterations (default 500) has been made over the RuleSet. Then the next RuleSet will be moved to. Once finished, a given RuleSet is never returned to. Each rule is has two parts: a pattern and and associated transformer. Transformers have two important functions: check(), and transform(). The pattern describes a pattern of node types that the optimizer will look to match. If that match is found anywhere in the plan, then check() will be called. check() allows the rule to look more in depth at the matched pattern and decide whether the rule should be run or not. For example, one might design a rule to push filters above join that would look for the pattern filter(join) (meaning a filter followed by a join). But only certain types of filters can be pushed. The check() function would need to decide whether the filter that it found was pushable or not. If check() returns true, the rule is said to have matched, and transform() is then called. This function is responsible for making changes in the logical plan. Once transform is complete PlanPatcher.patchUp will be called to do any necessary cleanup in the plan, such as resetting schemas, etc.


Field Summary
protected  List<PlanTransformListener> listeners
           
protected  int maxIter
           
protected  OperatorPlan plan
           
protected  List<Set<Rule>> ruleSets
           
 
Constructor Summary
protected PlanOptimizer(OperatorPlan p, List<Set<Rule>> rs, int iterations)
           
 
Method Summary
protected  void addPlanTransformListener(PlanTransformListener listener)
          Adds a listener to the optimization.
 void optimize()
          Run the optimizer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ruleSets

protected List<Set<Rule>> ruleSets

plan

protected OperatorPlan plan

listeners

protected List<PlanTransformListener> listeners

maxIter

protected int maxIter
Constructor Detail

PlanOptimizer

protected PlanOptimizer(OperatorPlan p,
                        List<Set<Rule>> rs,
                        int iterations)
Parameters:
p - Plan to optimize
rs - List of RuleSets to use to optimize
iterations - maximum number of optimization iterations, set to -1 for default
Method Detail

addPlanTransformListener

protected void addPlanTransformListener(PlanTransformListener listener)
Adds a listener to the optimization. This listener will be fired after each rule transforms a plan. Listeners are guaranteed to be fired in the order they are added.

Parameters:
listener -

optimize

public void optimize()
              throws FrontendException
Run the optimizer. This method attempts to match each of the Rules against the plan. If a Rule matches, it then calls the check method of the associated Transformer to give the it a chance to check whether it really wants to do the optimization. If that returns true as well, then Transformer.transform is called.

Throws:
FrontendException


Copyright © 2007-2012 The Apache Software Foundation