| 1 | package felix.dstruct; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.HashMap; |
| 5 | import java.util.HashSet; |
| 6 | |
| 7 | import felix.optimizer.CostModel; |
| 8 | |
| 9 | |
| 10 | |
| 11 | /** |
| 12 | * The class of an execution plan, which is an |
| 13 | * ordered list of {@link ConcurrentOperatorsBucket} |
| 14 | * with parameters. |
| 15 | * |
| 16 | * @author Ce Zhang |
| 17 | * |
| 18 | */ |
| 19 | public class ExecutionPlan { |
| 20 | |
| 21 | /** |
| 22 | * Cost model used in this execution plan. |
| 23 | */ |
| 24 | CostModel cm; |
| 25 | |
| 26 | /** |
| 27 | * Set CostModel. |
| 28 | * @param _cm |
| 29 | */ |
| 30 | public void setCostModel(CostModel _cm){ |
| 31 | cm = _cm; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get CostModel. |
| 36 | * @return |
| 37 | */ |
| 38 | public CostModel getCostModel(){ |
| 39 | return cm; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * List of buckets which are organized in physical execution order. |
| 44 | */ |
| 45 | public ArrayList<ConcurrentOperatorsBucket> operators = new ArrayList<ConcurrentOperatorsBucket>(); |
| 46 | |
| 47 | /** |
| 48 | * Set of predicates that are shared between different operators |
| 49 | * via dual decomposition. |
| 50 | */ |
| 51 | public HashSet<FelixPredicate> dd_CommonPredicates = new HashSet<FelixPredicate>(); |
| 52 | |
| 53 | /** |
| 54 | * Map from predicates in {@link #dd_CommonPredicates} to |
| 55 | * their parents operators. |
| 56 | */ |
| 57 | public HashMap<FelixPredicate, HashSet<ConcurrentOperatorsBucket>> |
| 58 | dd_Predicate2OperatorBucket = new HashMap<FelixPredicate, HashSet<ConcurrentOperatorsBucket>>(); |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * Add a bucket in the end of the execution plan. |
| 63 | * @param sop |
| 64 | */ |
| 65 | public void addOperatorAfter(ConcurrentOperatorsBucket sop){ |
| 66 | operators.add(sop); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Add a bucket before the end of the execution plan. |
| 71 | * @param sop |
| 72 | */ |
| 73 | public void addOperatorBefore(ConcurrentOperatorsBucket sop){ |
| 74 | operators.add(operators.size()-1, sop); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get all statistical operators in this execution plan. |
| 79 | * @return |
| 80 | */ |
| 81 | public ArrayList<StatOperator> getAllStatOperator(){ |
| 82 | ArrayList<StatOperator> ret = new ArrayList<StatOperator>(); |
| 83 | |
| 84 | for(ConcurrentOperatorsBucket cob : this.operators){ |
| 85 | for(StatOperator sop : cob.concurrentOperators){ |
| 86 | ret.add(sop); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | |
| 91 | return ret; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Returns string representation of this execution plan. |
| 96 | */ |
| 97 | public String toString(){ |
| 98 | |
| 99 | String ret = ""; |
| 100 | |
| 101 | for(int i = operators.size()-1;i>=0; i--){ |
| 102 | ret += operators.get(i); |
| 103 | ret += "\n"; |
| 104 | } |
| 105 | |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @deprecated |
| 111 | * Returns HTML representation of this execution plan |
| 112 | * (for a very preliminary online demo). |
| 113 | * @return |
| 114 | */ |
| 115 | public String toHTMLString(){ |
| 116 | /* |
| 117 | String ret = ""; |
| 118 | boolean flag = false; |
| 119 | ret += "<UL CLASS=\"mktree\" ID=\"tree1\">\n"; |
| 120 | |
| 121 | for(int i = operators.size()-1;i>=0; i--){ |
| 122 | |
| 123 | ConcurrentOperatorsBucket cob = operators.get(i); |
| 124 | |
| 125 | ret += "<LI>" + cob.toNoParString() + " " + "with " + |
| 126 | cob.concurrentOperators.size() + " Concurrent Sub-Operators\n"; |
| 127 | ret += "<UL>\n"; |
| 128 | |
| 129 | for(StatOperator sop : cob.getOperators()){ |
| 130 | ret += "<LI> Op" + sop.getId() + ": "; |
| 131 | if(sop.dataCrackerSignature == null){ |
| 132 | ret += "Work on all data"; |
| 133 | }else{ |
| 134 | ret += "Partitioned by " + sop.dataCrackerSignature; |
| 135 | } |
| 136 | |
| 137 | ret += "\n"; |
| 138 | |
| 139 | ret += "<UL>"; |
| 140 | |
| 141 | ret += "<LI> " + sop.inputPredicates.size() + " Input Open Predicates"; |
| 142 | ret += "<UL>"; |
| 143 | for(FelixPredicate fc : sop.inputPredicates){ |
| 144 | ret += "<LI>" + fc + "\n"; |
| 145 | } |
| 146 | ret += "</UL>"; |
| 147 | |
| 148 | ret += "<LI> " + sop.outputPredicates.size() + " Output Open Predicates"; |
| 149 | ret += "<UL>"; |
| 150 | for(FelixPredicate fc : sop.outputPredicates){ |
| 151 | ret += "<LI>" + fc + "\n"; |
| 152 | } |
| 153 | ret += "</UL>"; |
| 154 | |
| 155 | |
| 156 | ret += "<LI> " + sop.allRelevantFelixClause.size() + " Relevant Clauses"; |
| 157 | ret += "<UL>"; |
| 158 | for(FelixClause fc : sop.allRelevantFelixClause){ |
| 159 | if(flag == false){ |
| 160 | flag = true; |
| 161 | ret += "<LI ID=\"node234\">" + fc + "\n"; |
| 162 | }else{ |
| 163 | ret += "<LI ID=\"node234\">" + fc + "\n"; |
| 164 | } |
| 165 | } |
| 166 | ret += "</UL>"; |
| 167 | |
| 168 | ret += "</UL>"; |
| 169 | |
| 170 | } |
| 171 | |
| 172 | ret +="</UL>\n"; |
| 173 | |
| 174 | ret += "<br/>"; |
| 175 | |
| 176 | } |
| 177 | |
| 178 | ret += "</UL>\n"; |
| 179 | return ret; |
| 180 | */ |
| 181 | return null; |
| 182 | } |
| 183 | |
| 184 | } |