ThirdEyeAggregateFunction implements ThirdEyeFunction { @Override public MetricTimeSeries apply(StarTreeConfig config, ThirdEyeQuery query, MetricTimeSeries timeSeries) { MetricTimeSeries aggregate = ThirdEyeFunctionUtils.copyBlankSeriesSame(timeSeries.getSchema().getNames(), timeSeries.getSchema()); if (timeSeries.getTimeWindowSet().isEmpty()) { return aggregate; } long collectionWindow = config.getTime().getBucket().getUnit().convert(window.getSize(), window.getUnit()) / config.getTime().getBucket().getSize(); if (collectionWindow == 0) { throw new IllegalArgumentException("Minimum aggregation granularity is " + config.getTime().getBucket().getSize() + " " + config.getTime().getBucket().getUnit()); } Long minTime = Collections.min(timeSeries.getTimeWindowSet()); Long maxTime = Collections.max(timeSeries.getTimeWindowSet()); for (long i = minTime; i < maxTime; i += collectionWindow) { long alignedTime = (i / collectionWindow) * collectionWindow; for (long j = i; j < i + collectionWindow; j++) { for (String metricName : timeSeries.getSchema().getNames()) { Number metricValue = timeSeries.get(j, metricName); if (metricValue != null) { aggregate.increment(alignedTime, metricName, metricValue); } } } } return aggregate; } ThirdEyeAggregateFunction(TimeGranularity window); TimeGranularity getWindow(); @Override MetricTimeSeries apply(StarTreeConfig config, ThirdEyeQuery query, MetricTimeSeries timeSeries);  }
@Test public void testValid_simple() { MetricTimeSeries derived = new ThirdEyeAggregateFunction( new TimeGranularity(4, TimeUnit.HOURS)).apply(config, query, timeSeries); Assert.assertEquals(derived.getTimeWindowSet().size(), 4); for (long i = 0; i < 16; i += 4) { Assert.assertEquals(derived.get(i, "L"), 4L); Assert.assertEquals(derived.get(i, "D"), 4.0); } }