Returns an alias if provided or the original metric name if not. The alias may optionally contain a template for tag replacement so that tags are advanced to the metric name for systems that require it. (e.g. flatten a name for Graphite). @since 2.3
| 31 | * @since 2.3 |
| 32 | */ |
| 33 | public class Alias implements Expression { |
| 34 | |
| 35 | static Joiner COMMA_JOINER = Joiner.on(',').skipNulls(); |
| 36 | |
| 37 | @Override |
| 38 | public DataPoints[] evaluate(final TSQuery data_query, |
| 39 | final List<DataPoints[]> query_results, final List<String> params) { |
| 40 | if (data_query == null) { |
| 41 | throw new IllegalArgumentException("Missing time series query"); |
| 42 | } |
| 43 | if (query_results == null || query_results.isEmpty()) { |
| 44 | return new DataPoints[]{}; |
| 45 | } |
| 46 | if (params == null || params.isEmpty()) { |
| 47 | throw new IllegalArgumentException("Missing the alias"); |
| 48 | } |
| 49 | final String alias_template = COMMA_JOINER.join(params); |
| 50 | |
| 51 | int num_results = 0; |
| 52 | for (DataPoints[] results: query_results) { |
| 53 | num_results += results.length; |
| 54 | } |
| 55 | |
| 56 | final DataPoints[] results = new DataPoints[num_results]; |
| 57 | int ix = 0; |
| 58 | // one or more sub queries (m=...&m=...&m=...) |
| 59 | for (final DataPoints[] sub_query_result : query_results) { |
| 60 | // group bys (m=sum:foo{host=*}) |
| 61 | for (final DataPoints dps : sub_query_result) { |
| 62 | // TODO(cl) - Using an array as the size function may not return the exact |
| 63 | // results and we should figure a way to avoid copying data anyway. |
| 64 | final List<DataPoint> new_dps_list = new ArrayList<DataPoint>(); |
| 65 | final SeekableView view = dps.iterator(); |
| 66 | while (view.hasNext()) { |
| 67 | DataPoint pt = view.next(); |
| 68 | if (pt.isInteger()) { |
| 69 | new_dps_list.add(MutableDataPoint.ofLongValue( |
| 70 | pt.timestamp(), Math.abs(pt.longValue()))); |
| 71 | } else { |
| 72 | new_dps_list.add(MutableDataPoint.ofDoubleValue( |
| 73 | pt.timestamp(), Math.abs(pt.doubleValue()))); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | final DataPoint[] new_dps = new DataPoint[dps.size()]; |
| 78 | new_dps_list.toArray(new_dps); |
| 79 | final PostAggregatedDataPoints padps = new PostAggregatedDataPoints( |
| 80 | dps, new_dps); |
| 81 | |
| 82 | padps.setAlias(alias_template); |
| 83 | results[ix++] = padps; |
| 84 | } |
| 85 | } |
| 86 | return results; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public String writeStringField(final List<String> query_params, |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…