Default Ctor that constructs a TSQuery and TSSubQueries from the new Query POJO class. @param tsdb The TSDB to which we belong @param query The raw query to parse and use for output @throws IllegalArgumentException if we were unable to parse the Query into a TSQuery.
(final TSDB tsdb, final Query query)
| 118 | * a TSQuery. |
| 119 | */ |
| 120 | public QueryExecutor(final TSDB tsdb, final Query query) { |
| 121 | this.tsdb = tsdb; |
| 122 | this.query = query; |
| 123 | |
| 124 | // if metrics is null, this is a bad query |
| 125 | sub_queries = new HashMap<String, TSSubQuery>(query.getMetrics().size()); |
| 126 | sub_query_results = new HashMap<String, DataPoints[]>( |
| 127 | query.getMetrics().size()); |
| 128 | |
| 129 | if (query.getExpressions() != null) { |
| 130 | expressions = new HashMap<String, ExpressionIterator>( |
| 131 | query.getExpressions().size()); |
| 132 | } else { |
| 133 | expressions = null; |
| 134 | } |
| 135 | |
| 136 | final Timespan timespan = query.getTime(); |
| 137 | |
| 138 | // compile the ts_query |
| 139 | ts_query = new TSQuery(); |
| 140 | ts_query.setStart(timespan.getStart()); |
| 141 | ts_query.setTimezone(timespan.getTimezone()); |
| 142 | |
| 143 | if (timespan.getEnd() != null && !timespan.getEnd().isEmpty()) { |
| 144 | ts_query.setEnd(timespan.getEnd()); |
| 145 | } |
| 146 | |
| 147 | fills = new HashMap<String, NumericFillPolicy>(query.getMetrics().size()); |
| 148 | for (final Metric mq : query.getMetrics()) { |
| 149 | if (mq.getFillPolicy() != null) { |
| 150 | fills.put(mq.getId(), mq.getFillPolicy()); |
| 151 | } |
| 152 | final TSSubQuery sub = new TSSubQuery(); |
| 153 | sub_queries.put(mq.getId(), sub); |
| 154 | |
| 155 | sub.setMetric(mq.getMetric()); |
| 156 | |
| 157 | if (timespan.getDownsampler() != null) { |
| 158 | sub.setDownsample(timespan.getDownsampler().getInterval() + "-" + |
| 159 | timespan.getDownsampler().getAggregator()); |
| 160 | } |
| 161 | |
| 162 | // filters |
| 163 | if (mq.getFilter() != null && !mq.getFilter().isEmpty()) { |
| 164 | List<TagVFilter> filters = null; |
| 165 | boolean explicit_tags = false; |
| 166 | if (query.getFilters() == null || query.getFilters().isEmpty()) { |
| 167 | throw new IllegalArgumentException("No filter defined: " + mq.getFilter()); |
| 168 | } |
| 169 | for (final Filter filter : query.getFilters()) { |
| 170 | if (filter.getId().equals(mq.getFilter())) { |
| 171 | // TODO - it'd be more efficient if we could share the filters but |
| 172 | // for now, this is the only way to avoid concurrent modifications. |
| 173 | filters = new ArrayList<TagVFilter>(filter.getTags().size()); |
| 174 | for (final TagVFilter f : filter.getTags()) { |
| 175 | filters.add(f.getCopy()); |
| 176 | } |
| 177 | explicit_tags = filter.getExplicitTags(); |
nothing calls this directly
no test coverage detected