Processes the expression tree, including sub expressions, and returns the results. TODO(cl) - More tests around indices, etc. This can likely be cleaned up. @param query_results The result set to pass to the expressions @return The result set or an exception will bubble up if something wasn't config
(final List<DataPoints[]> query_results)
| 149 | * configured properly. |
| 150 | */ |
| 151 | public DataPoints[] evaluate(final List<DataPoints[]> query_results) { |
| 152 | // TODO - size the array |
| 153 | final List<DataPoints[]> materialized = Lists.newArrayList(); |
| 154 | List<Integer> metric_query_keys = null; |
| 155 | if (sub_metric_queries != null && sub_metric_queries.size() > 0) { |
| 156 | metric_query_keys = Lists.newArrayList(sub_metric_queries.keySet()); |
| 157 | Collections.sort(metric_query_keys); |
| 158 | } |
| 159 | |
| 160 | int metric_pointer = 0; |
| 161 | int sub_expression_pointer = 0; |
| 162 | for (int i = 0; i < parameter_index.size(); i++) { |
| 163 | final Parameter param = parameter_index.get(i); |
| 164 | |
| 165 | if (param == Parameter.METRIC_QUERY) { |
| 166 | if (metric_query_keys == null) { |
| 167 | throw new RuntimeException("Attempt to read metric " + |
| 168 | "results when none exist"); |
| 169 | } |
| 170 | |
| 171 | final int ix = metric_query_keys.get(metric_pointer++); |
| 172 | materialized.add(query_results.get(ix)); |
| 173 | } else if (param == Parameter.SUB_EXPRESSION) { |
| 174 | final ExpressionTree st = sub_expressions.get(sub_expression_pointer++); |
| 175 | materialized.add(st.evaluate(query_results)); |
| 176 | } else { |
| 177 | throw new IllegalDataException("Unknown parameter type: " + param |
| 178 | + " in tree: " + this); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | return expression.evaluate(data_query, materialized, func_params); |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public String toString() { |