private Collection<TimeSeries> convertToQueryResult(CubeQuery query, Table<Map<String, String>, String, Map<Long, Long>> resultTable) { List<TimeSeries> result = Lists.newArrayList(); // iterating each groupValue dimensions for (Map.Entry<Map<String, String>, Map<String, Map<Long, Long>>> row : resultTable.rowMap().entrySet()) { // iterating each measure for (Map.Entry<String, Map<Long, Long>> measureEntry : row.getValue().entrySet()) { // generating time series for a grouping and a measure int count = 0; List<TimeValue> timeValues = Lists.newArrayList(); for (Map.Entry<Long, Long> timeValue : measureEntry.getValue().entrySet()) { timeValues.add(new TimeValue(timeValue.getKey(), timeValue.getValue())); } Collections.sort(timeValues); PeekingIterator<TimeValue> timeValueItor = Iterators.peekingIterator( new TimeSeriesInterpolator(timeValues, query.getInterpolator(), query.getResolution()).iterator()); List<TimeValue> resultTimeValues = Lists.newArrayList(); while (timeValueItor.hasNext()) { TimeValue timeValue = timeValueItor.next(); resultTimeValues.add(new TimeValue(timeValue.getTimestamp(), timeValue.getValue())); if (++count >= query.getLimit()) { break; } } result.add(new TimeSeries(measureEntry.getKey(), row.getKey(), resultTimeValues)); } } return result; }
@Override public Collection<MetricTimeSeries> query(MetricDataQuery query) { Collection<TimeSeries> cubeResult = cube.get().query(buildCubeQuery(query)); List<MetricTimeSeries> result = Lists.newArrayList(); for (TimeSeries timeSeries : cubeResult) { result.add(new MetricTimeSeries(timeSeries.getMeasureName(), timeSeries.getDimensionValues(), timeSeries.getTimeValues())); } return result; }
Assert.assertEquals(1, data.size()); TimeSeries series = data.iterator().next(); List<TimeValue> timeValues = series.getTimeValues(); Assert.assertEquals(2, timeValues.size()); TimeValue timeValue = timeValues.get(0); Assert.assertEquals(1, data.size()); series = data.iterator().next(); timeValues = series.getTimeValues(); Assert.assertEquals(1, timeValues.size()); timeValue = timeValues.get(0);
@Override public Collection<MetricTimeSeries> query(MetricDataQuery query) { Collection<TimeSeries> cubeResult = cube.get().query(buildCubeQuery(query)); List<MetricTimeSeries> result = Lists.newArrayList(); for (TimeSeries timeSeries : cubeResult) { result.add(new MetricTimeSeries(timeSeries.getMeasureName(), timeSeries.getDimensionValues(), timeSeries.getTimeValues())); } return result; }
private Collection<TimeSeries> convertToQueryResult(CubeQuery query, Table<Map<String, String>, String, Map<Long, Long>> resultTable) { List<TimeSeries> result = Lists.newArrayList(); // iterating each groupValue dimensions for (Map.Entry<Map<String, String>, Map<String, Map<Long, Long>>> row : resultTable.rowMap().entrySet()) { // iterating each measure for (Map.Entry<String, Map<Long, Long>> measureEntry : row.getValue().entrySet()) { // generating time series for a grouping and a measure int count = 0; List<TimeValue> timeValues = Lists.newArrayList(); for (Map.Entry<Long, Long> timeValue : measureEntry.getValue().entrySet()) { timeValues.add(new TimeValue(timeValue.getKey(), timeValue.getValue())); } Collections.sort(timeValues); PeekingIterator<TimeValue> timeValueItor = Iterators.peekingIterator( new TimeSeriesInterpolator(timeValues, query.getInterpolator(), query.getResolution()).iterator()); List<TimeValue> resultTimeValues = Lists.newArrayList(); while (timeValueItor.hasNext()) { TimeValue timeValue = timeValueItor.next(); resultTimeValues.add(new TimeValue(timeValue.getTimestamp(), timeValue.getValue())); if (++count >= query.getLimit()) { break; } } result.add(new TimeSeries(measureEntry.getKey(), row.getKey(), resultTimeValues)); } } return result; }
ImmutableMap.of("dim1", "1"), new ArrayList<String>(), ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 9, 10, 6, 101, 7)))); new TimeSeries("metric1", new HashMap<String, String>(), timeValues(0, 15, 100, 7)))); new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 1, 10, 6, 101, 7)))); new TimeSeries("metric1", new HashMap<String, String>(), timeValues(0, 7, 100, 7))));
ImmutableMap.of("dim1", "1"), new ArrayList<String>(), ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 5, 10, 6, 101, 7)))); new TimeSeries("metric1", new HashMap<String, String>(), timeValues(0, 6, 100, 7)))); new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 1, 10, 6, 101, 7)))); new TimeSeries("metric1", new HashMap<String, String>(), timeValues(0, 6, 100, 7))));
agg1Dims, ImmutableList.of(), ImmutableList.of( new TimeSeries("metric1", new HashMap<>(), timeValues(1, 1)))); verifyCountQuery(cube, 0, 15, resolution, "metric2", AggregationFunction.SUM, agg2Dims, ImmutableList.of(), ImmutableList.of( new TimeSeries("metric2", new HashMap<>(), timeValues(3, 3)))); agg1Dims, ImmutableList.of(), ImmutableList.of( new TimeSeries("metric1", new HashMap<>(), timeValues(1, 1))));
ImmutableMap.of("dim1", "1"), ImmutableList.of("dim2"), ImmutableList.of( new TimeSeries("metric1", dimensionValues("dim2", "1"), timeValues(1, 2, 7, 3, 10, 2, 11, 3)), new TimeSeries("metric1", dimensionValues("dim2", "2"), timeValues(3, 8)))); new ArrayList<String>(), ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 2, 10, 2, 11, 3)))); new TimeSeries("metric1", dimensionValues("dim1", "1"), timeValues(1, 2, 3, 8, 4, 4, 6, 6, 7, 3, 10, 2, 11, 3)), new TimeSeries("metric1", dimensionValues("dim1", "2"), timeValues(3, 7, 12, 4)))); ImmutableMap.of("dim3", "3"), new ArrayList<String>(), ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), timeValues(3, 5)))); ImmutableList.of(new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 2, 3, 8, 7, 3, 10, 2, 11, 3)))); verifyCountQuery(cube, "agg2", 0, 15, resolution, "metric1", AggregationFunction.SUM, ImmutableMap.of("dim1", "1"), new ArrayList<String>(), ImmutableList.of(new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 2, 3, 8, 4, 4, 6, 6, 7, 3, 10, 2, 11, 3)))); ImmutableList.of(new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 2, 3, 5, 7, 3, 10, 2, 11, 3)))); verifyCountQuery(cube, "agg1", 0, 15, resolution, "metric1", AggregationFunction.MIN, ImmutableMap.of("dim1", "1"), new ArrayList<String>(),
new ArrayList<String>(), ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), expectedTimeValues)), new Interpolators.Step()); new ArrayList<String>(), ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 5, 2, 5, 3, 4, 4, 4, 5, 3))), new Interpolators.Linear()); new ArrayList<String>(), ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 100, 2, 200, 3, 300, 4, 400, 5, 500))), new Interpolators.Linear()); new ArrayList<String>(), ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), expectedTimeValues)), new Interpolators.Step(limit));
new HashMap<String, String>(), new ArrayList<String>(), ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), timeValues(1, 1))));