org.apache.pig.newplan.optimizer
Class Rule

java.lang.Object
  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.


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

name

protected String name

pattern

protected OperatorPlan pattern

currentPlan

protected transient OperatorPlan currentPlan

log

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

Rule

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

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

Rule

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

buildPattern

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

Returns:
the pattern to look for by this rule

getNewTransformer

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.

Returns:
Transformer to use with this rule

getPattern

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

Returns:
the pattern to be matched for this rule

isSkipListener

protected boolean isSkipListener()

setSkipListener

protected void setSkipListener(boolean skip)

match

public List<OperatorPlan> match(OperatorPlan plan)
                         throws FrontendException
Search for all the sub-plans that matches the pattern defined by this rule.

Parameters:
plan - the OperatorPlan to look for matches to the pattern
Returns:
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.
Throws:
FrontendException

getName

public String getName()

isMandatory

public boolean isMandatory()


Copyright © ${year} The Apache Software Foundation