| 34 | import org.apache.pig.impl.util.Pair; |
| 35 | |
| 36 | public abstract class BaseOperatorPlan implements OperatorPlan { |
| 37 | |
| 38 | protected List<Operator> ops; |
| 39 | protected PlanEdge fromEdges; |
| 40 | protected PlanEdge toEdges; |
| 41 | protected PlanEdge softFromEdges; |
| 42 | protected PlanEdge softToEdges; |
| 43 | |
| 44 | private List<Operator> roots; |
| 45 | private List<Operator> leaves; |
| 46 | protected static final Log log = |
| 47 | LogFactory.getLog(BaseOperatorPlan.class); |
| 48 | |
| 49 | public BaseOperatorPlan() { |
| 50 | ops = new ArrayList<Operator>(); |
| 51 | roots = new ArrayList<Operator>(); |
| 52 | leaves = new ArrayList<Operator>(); |
| 53 | fromEdges = new PlanEdge(); |
| 54 | toEdges = new PlanEdge(); |
| 55 | softFromEdges = new PlanEdge(); |
| 56 | softToEdges = new PlanEdge(); |
| 57 | } |
| 58 | |
| 59 | @SuppressWarnings("unchecked") |
| 60 | public BaseOperatorPlan(BaseOperatorPlan other) { |
| 61 | // (shallow) copy constructor |
| 62 | ops = (List<Operator>) ((ArrayList<Operator>) other.ops).clone(); |
| 63 | roots = (List<Operator>) ((ArrayList) other.roots).clone(); |
| 64 | leaves = (List<Operator>) ((ArrayList) other.leaves).clone(); |
| 65 | fromEdges = other.fromEdges.shallowClone(); |
| 66 | toEdges = other.toEdges.shallowClone(); |
| 67 | softFromEdges = other.softFromEdges.shallowClone(); |
| 68 | softToEdges = other.softToEdges.shallowClone(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Get number of nodes in the plan. |
| 73 | */ |
| 74 | public int size() { |
| 75 | return ops.size(); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get all operators in the plan that have no predecessors. |
| 80 | * @return all operators in the plan that have no predecessors, or |
| 81 | * an empty list if the plan is empty. |
| 82 | */ |
| 83 | public List<Operator> getSources() { |
| 84 | if (roots.size() == 0 && ops.size() > 0) { |
| 85 | for (Operator op : ops) { |
| 86 | if (toEdges.get(op) == null) { |
| 87 | roots.add(op); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | return roots; |
| 92 | } |
| 93 |
nothing calls this directly
no outgoing calls
no test coverage detected