org.apache.pig.newplan
Class BaseOperatorPlan

java.lang.Object
  extended by org.apache.pig.newplan.BaseOperatorPlan
All Implemented Interfaces:
OperatorPlan
Direct Known Subclasses:
LogicalExpressionPlan, LogicalPlan, PatternPlan, PigStats.JobGraph

public abstract class BaseOperatorPlan
extends Object
implements OperatorPlan


Field Summary
protected  PlanEdge fromEdges
           
protected static org.apache.commons.logging.Log log
           
protected  List<Operator> ops
           
protected  PlanEdge softFromEdges
           
protected  PlanEdge softToEdges
           
protected  PlanEdge toEdges
           
 
Constructor Summary
BaseOperatorPlan()
           
BaseOperatorPlan(BaseOperatorPlan other)
           
 
Method Summary
 void add(Operator op)
          Add a new operator to the plan.
 void connect(Operator from, int fromPos, Operator to, int toPos)
          Connect two operators in the plan, controlling which position in the edge lists that the from and to edges are placed.
 void connect(Operator from, Operator to)
          Connect two operators in the plan.
 void createSoftLink(Operator from, Operator to)
          Create an soft edge between two nodes.
 Pair<Integer,Integer> disconnect(Operator from, Operator to)
          Disconnect two operators in the plan.
 void explain(PrintStream ps, String format, boolean verbose)
           
 Iterator<Operator> getOperators()
          Get an iterator of all operators in this plan
 List<Operator> getPredecessors(Operator op)
          For a given operator, get all operators immediately before it in the plan.
 List<Operator> getSinks()
          Get all operators in the plan that have no successors.
 List<Operator> getSoftLinkPredecessors(Operator op)
          For a given operator, get all operators softly immediately before it in the plan.
 List<Operator> getSoftLinkSuccessors(Operator op)
          For a given operator, get all operators softly immediately after it.
 List<Operator> getSources()
          Get all operators in the plan that have no predecessors.
 List<Operator> getSuccessors(Operator op)
          For a given operator, get all operators immediately after it.
 void insertBetween(Operator pred, Operator operatorToInsert, Operator succ)
          This method insert node operatorToInsert between pred and succ.
 boolean isConnected(Operator from, Operator to)
          Check if given two operators are directly connected.
 boolean isEqual(OperatorPlan other)
          This is like a shallow comparison.
protected static boolean isEqual(OperatorPlan p1, OperatorPlan p2)
           
 boolean pathExists(Operator from, Operator to)
          A method to check if there is a path from a given node to another node
 void remove(Operator op)
          Remove an operator from the plan.
 void removeAndReconnect(Operator operatorToRemove)
          This method remove a node operatorToRemove.
 void removeSoftLink(Operator from, Operator to)
          Remove an soft edge
 void replace(Operator oldOperator, Operator newOperator)
          This method replace the oldOperator with the newOperator, make all connection to the new operator in the place of old operator
 int size()
          Get number of nodes in the plan.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ops

protected List<Operator> ops

fromEdges

protected PlanEdge fromEdges

toEdges

protected PlanEdge toEdges

softFromEdges

protected PlanEdge softFromEdges

softToEdges

protected PlanEdge softToEdges

log

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

BaseOperatorPlan

public BaseOperatorPlan()

BaseOperatorPlan

public BaseOperatorPlan(BaseOperatorPlan other)
Method Detail

size

public int size()
Get number of nodes in the plan.

Specified by:
size in interface OperatorPlan
Returns:
number of nodes in the plan

getSources

public List<Operator> getSources()
Get all operators in the plan that have no predecessors.

Specified by:
getSources in interface OperatorPlan
Returns:
all operators in the plan that have no predecessors, or an empty list if the plan is empty.

getSinks

public List<Operator> getSinks()
Get all operators in the plan that have no successors.

Specified by:
getSinks in interface OperatorPlan
Returns:
all operators in the plan that have no successors, or an empty list if the plan is empty.

getPredecessors

public List<Operator> getPredecessors(Operator op)
For a given operator, get all operators immediately before it in the plan.

Specified by:
getPredecessors in interface OperatorPlan
Parameters:
op - operator to fetch predecessors of
Returns:
list of all operators imeediately before op, or an empty list if op is a root.

getSuccessors

public List<Operator> getSuccessors(Operator op)
For a given operator, get all operators immediately after it.

Specified by:
getSuccessors in interface OperatorPlan
Parameters:
op - operator to fetch successors of
Returns:
list of all operators imeediately after op, or an empty list if op is a leaf.

getSoftLinkPredecessors

public List<Operator> getSoftLinkPredecessors(Operator op)
For a given operator, get all operators softly immediately before it in the plan.

Specified by:
getSoftLinkPredecessors in interface OperatorPlan
Parameters:
op - operator to fetch predecessors of
Returns:
list of all operators immediately before op, or an empty list if op is a root.

getSoftLinkSuccessors

public List<Operator> getSoftLinkSuccessors(Operator op)
For a given operator, get all operators softly immediately after it.

Specified by:
getSoftLinkSuccessors in interface OperatorPlan
Parameters:
op - operator to fetch successors of
Returns:
list of all operators immediately after op, or an empty list if op is a leaf.

add

public void add(Operator op)
Add a new operator to the plan. It will not be connected to any existing operators.

Specified by:
add in interface OperatorPlan
Parameters:
op - operator to add

remove

public void remove(Operator op)
            throws FrontendException
Remove an operator from the plan.

Specified by:
remove in interface OperatorPlan
Parameters:
op - Operator to be removed
Throws:
FrontendException - if the remove operation attempts to remove an operator that is still connected to other operators.

connect

public void connect(Operator from,
                    int fromPos,
                    Operator to,
                    int toPos)
Connect two operators in the plan, controlling which position in the edge lists that the from and to edges are placed.

Specified by:
connect in interface OperatorPlan
Parameters:
from - Operator edge will come from
fromPos - Position in the array for the from edge
to - Operator edge will go to
toPos - Position in the array for the to edge

isConnected

public boolean isConnected(Operator from,
                           Operator to)
Check if given two operators are directly connected.

Parameters:
from - Operator edge will come from
to - Operator edge will go to

connect

public void connect(Operator from,
                    Operator to)
Connect two operators in the plan.

Specified by:
connect in interface OperatorPlan
Parameters:
from - Operator edge will come from
to - Operator edge will go to

createSoftLink

public void createSoftLink(Operator from,
                           Operator to)
Create an soft edge between two nodes.

Specified by:
createSoftLink in interface OperatorPlan
Parameters:
from - Operator dependent upon
to - Operator having the dependency

removeSoftLink

public void removeSoftLink(Operator from,
                           Operator to)
Remove an soft edge

Specified by:
removeSoftLink in interface OperatorPlan
Parameters:
from - Operator dependent upon
to - Operator having the dependency

disconnect

public Pair<Integer,Integer> disconnect(Operator from,
                                        Operator to)
                                 throws FrontendException
Disconnect two operators in the plan.

Specified by:
disconnect in interface OperatorPlan
Parameters:
from - Operator edge is coming from
to - Operator edge is going to
Returns:
pair of positions, indicating the position in the from and to arrays.
Throws:
FrontendException - if the two operators aren't connected.

getOperators

public Iterator<Operator> getOperators()
Description copied from interface: OperatorPlan
Get an iterator of all operators in this plan

Specified by:
getOperators in interface OperatorPlan
Returns:
an iterator of all operators in this plan

isEqual

public boolean isEqual(OperatorPlan other)
                throws FrontendException
Description copied from interface: OperatorPlan
This is like a shallow comparison. Two plans are equal if they have equivalent operators and equivalent structure.

Specified by:
isEqual in interface OperatorPlan
Parameters:
other - object to compare
Returns:
boolean if both the plans are equivalent
Throws:
FrontendException

isEqual

protected static boolean isEqual(OperatorPlan p1,
                                 OperatorPlan p2)
                          throws FrontendException
Throws:
FrontendException

explain

public void explain(PrintStream ps,
                    String format,
                    boolean verbose)
             throws FrontendException
Throws:
FrontendException

toString

public String toString()
Overrides:
toString in class Object

replace

public void replace(Operator oldOperator,
                    Operator newOperator)
             throws FrontendException
Description copied from interface: OperatorPlan
This method replace the oldOperator with the newOperator, make all connection to the new operator in the place of old operator

Specified by:
replace in interface OperatorPlan
Parameters:
oldOperator - operator to be replaced
newOperator - operator to replace
Throws:
FrontendException

removeAndReconnect

public void removeAndReconnect(Operator operatorToRemove)
                        throws FrontendException
Description copied from interface: OperatorPlan
This method remove a node operatorToRemove. It also Connect all its successors to predecessor/connect all it's predecessors to successor

Specified by:
removeAndReconnect in interface OperatorPlan
Parameters:
operatorToRemove - operator to remove
Throws:
FrontendException

insertBetween

public void insertBetween(Operator pred,
                          Operator operatorToInsert,
                          Operator succ)
                   throws FrontendException
Description copied from interface: OperatorPlan
This method insert node operatorToInsert between pred and succ. Both pred and succ cannot be null

Specified by:
insertBetween in interface OperatorPlan
Parameters:
pred - predecessor of inserted node after this method
operatorToInsert - operato to insert
succ - successor of inserted node after this method
Throws:
FrontendException

pathExists

public boolean pathExists(Operator from,
                          Operator to)
A method to check if there is a path from a given node to another node

Specified by:
pathExists in interface OperatorPlan
Parameters:
from - the start node for checking
to - the end node for checking
Returns:
true if path exists, false otherwise


Copyright © 2007-2012 The Apache Software Foundation