Builds the iterator by computing the intersection of all series in all sets and sets up the output. @throws IllegalArgumentException if there aren't any results, or we don't have a result for each variable, or something else is wrong. @throws IllegalDataException if no series were left after computi
()
| 235 | * intersection. |
| 236 | */ |
| 237 | public void compile() { |
| 238 | if (LOG.isDebugEnabled()) { |
| 239 | LOG.debug("Compiling " + this); |
| 240 | } |
| 241 | if (results.size() < 1) { |
| 242 | throw new IllegalArgumentException("No results for any variables in " |
| 243 | + "the expression: " + this); |
| 244 | } |
| 245 | if (results.size() < names.size()) { |
| 246 | throw new IllegalArgumentException("Not enough query results [" |
| 247 | + results.size() + " total results found] for the expression variables [" |
| 248 | + names.size() + " expected] " + this); |
| 249 | } |
| 250 | |
| 251 | // don't care if we have extra results, but we had darned well better make |
| 252 | // sure we have a result set for each variable |
| 253 | for (final String variable : names) { |
| 254 | // validation |
| 255 | final ITimeSyncedIterator it = results.get(variable.toLowerCase()); |
| 256 | if (it == null) { |
| 257 | throw new IllegalArgumentException("Missing results for variable " + variable); |
| 258 | } |
| 259 | |
| 260 | if (it instanceof ExpressionIterator) { |
| 261 | ((ExpressionIterator)it).compile(); |
| 262 | } |
| 263 | if (LOG.isDebugEnabled()) { |
| 264 | LOG.debug("Matched variable " + variable + " to " + it); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // TODO implement other set functions |
| 269 | switch (set_operator) { |
| 270 | case INTERSECTION: |
| 271 | iterator = new IntersectionIterator(id, results, intersect_on_query_tagks, |
| 272 | include_agg_tags); |
| 273 | break; |
| 274 | case UNION: |
| 275 | iterator = new UnionIterator(id, results, intersect_on_query_tagks, |
| 276 | include_agg_tags); |
| 277 | } |
| 278 | iteration_results = iterator.getResults(); |
| 279 | |
| 280 | dps = new ExpressionDataPoint[iterator.getSeriesSize()]; |
| 281 | for (int i = 0; i < iterator.getSeriesSize(); i++) { |
| 282 | final Iterator<Entry<String, ExpressionDataPoint[]>> it = |
| 283 | iteration_results.entrySet().iterator(); |
| 284 | Entry<String, ExpressionDataPoint[]> entry = it.next(); |
| 285 | |
| 286 | if (entry.getValue() == null || entry.getValue()[i] == null) { |
| 287 | dps[i] = new ExpressionDataPoint(); |
| 288 | } else { |
| 289 | dps[i] = new ExpressionDataPoint(entry.getValue()[i]); |
| 290 | } |
| 291 | while (it.hasNext()) { |
| 292 | entry = it.next(); |
| 293 | if (entry.getValue() != null && entry.getValue()[i] != null) { |
| 294 | dps[i].add(entry.getValue()[i]); |