Class Rule

  extended by org.apache.pig.newplan.optimizer.Rule
Direct Known Subclasses:
DuplicateForEachColumnRewrite, FilterAboveForeach, GroupByConstParallelSetter, ImplicitSplitInserter, LimitOptimizer, LogicalExpressionSimplifier, MergeFilter, MergeForEach, PartitionFilterOptimizer, PushDownForEachFlatten, PushUpFilter, SplitFilter, TypeCastInserter, WholePlanRule

public abstract class Rule
extends Object

Rules describe a pattern of operators. They also reference a Transformer. If the pattern of operators is found one or more times in the provided plan, then the optimizer will use the associated Transformer to transform the plan. Note: the pattern matching logic implemented here has a limitation that it assumes that all the leaves in the pattern are siblings. See more detailed description here - If new rules use patterns that don't work with this limitation, the pattern match logic will need to be updated.

Field Summary
protected  OperatorPlan currentPlan
protected static org.apache.commons.logging.Log log
protected  String name
protected  OperatorPlan pattern
Constructor Summary
Rule(String n, boolean mandatory)
          Create this rule by using the default pattern that this rule provided
Rule(String n, OperatorPlan p)
Method Summary
protected abstract  OperatorPlan buildPattern()
          Build the pattern that this rule will look for
 String getName()
abstract  Transformer getNewTransformer()
          Get the transformer for this rule.
 OperatorPlan getPattern()
          Return the pattern to be matched for this rule
 boolean isMandatory()
protected  boolean isSkipListener()
 List<OperatorPlan> match(OperatorPlan plan)
          Search for all the sub-plans that matches the pattern defined by this rule.
protected  void setSkipListener(boolean skip)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected String name


protected OperatorPlan pattern


protected transient OperatorPlan currentPlan


protected static final org.apache.commons.logging.Log log
Constructor Detail


public Rule(String n,
            boolean mandatory)
Create this rule by using the default pattern that this rule provided

n - Name of this rule
mandatory - if it is set to false, this rule can be disabled by user


public Rule(String n,
            OperatorPlan p)
n - Name of this rule
p - Pattern to look for.
Method Detail


protected abstract OperatorPlan buildPattern()
Build the pattern that this rule will look for

the pattern to look for by this rule


public abstract Transformer getNewTransformer()
Get the transformer for this rule. Abstract because the rule may want to choose how to instantiate the transformer. This should never return a cached transformer, it should always return a fresh one with no state.

Transformer to use with this rule


public OperatorPlan getPattern()
Return the pattern to be matched for this rule

the pattern to be matched for this rule


protected boolean isSkipListener()


protected void setSkipListener(boolean skip)


public List<OperatorPlan> match(OperatorPlan plan)
                         throws FrontendException
Search for all the sub-plans that matches the pattern defined by this rule. See class description above for limitations on the patterns supported.

plan - the OperatorPlan to look for matches to the pattern
A list of all matched sub-plans. The returned plans are partial views of the original OperatorPlan. Each is a sub-set of the original plan and represents the same topology as the pattern, but operators in the returned plan are the same objects as the original plan. Therefore, a call getPlan() from any node in the return plan would return the original plan.


public String getName()


public boolean isMandatory()

Copyright © 2007-2012 The Apache Software Foundation