GroupingAggregation implements AggregationInstance { @Override public AggregationSession session( DateRange range, RetainQuotaWatcher quotaWatcher, BucketStrategy bucketStrategy ) { return new GroupSession(range, quotaWatcher, bucketStrategy); } GroupingAggregation(final Optional<List<String>> of, final AggregationInstance each); Optional<List<String>> getOf(); AggregationInstance getEach(); @Override AggregationSession session(
        DateRange range, RetainQuotaWatcher quotaWatcher, BucketStrategy bucketStrategy
    ); Set<String> requiredTags(); @Override long estimate(DateRange range); @Override long cadence(); @Override AggregationInstance distributed(); @Override AggregationInstance reducer(); @Override void hashTo(final ObjectHasher hasher); @Override String toString();  }
@Test public void testChainedSessions() { final GroupingAggregation g1 = new GroupInstance(Optional.of(ImmutableList.of("site", "host")), EmptyInstance.INSTANCE); final GroupingAggregation g2 = new GroupInstance(Optional.of(ImmutableList.of("site")), EmptyInstance.INSTANCE); final ChainInstance chain = new ChainInstance(ImmutableList.of(g1, g2)); final Set<Series> series = new HashSet<>(); final Series s1 = Series.of("foo", ImmutableMap.of("site", "sto", "host", "a")); final Series s2 = Series.of("foo", ImmutableMap.of("site", "sto", "host", "b")); final Series s3 = Series.of("foo", ImmutableMap.of("site", "lon", "host", "b")); final Series s4 = Series.of("foo", ImmutableMap.of("host", "c")); series.add(s1); series.add(s2); series.add(s3); series.add(s4); final AggregationSession session = chain.session(new DateRange(0, 10000)); session.updatePoints(s4.getTags(), ImmutableSet.of(s4), ImmutableList.of(new Point(4, 4.0))); session.updatePoints(s3.getTags(), ImmutableSet.of(s3), ImmutableList.of(new Point(3, 3.0))); session.updatePoints(s2.getTags(), ImmutableSet.of(s2), ImmutableList.of(new Point(2, 2.0))); session.updatePoints(s1.getTags(), ImmutableSet.of(s1), ImmutableList.of(new Point(1, 1.0))); final List<AggregationOutput> result = session.result().getResult(); assertEquals(3, result.size()); final Set<Map<String, String>> expected = result.stream().map(AggregationOutput::getKey).collect(Collectors.toSet()); for (final AggregationOutput data : result) { if (data.getKey().equals(ImmutableMap.of("site", "lon"))) { assertEquals(ImmutableList.of(new Point(3, 3.0)), data.getMetrics().data()); expected.remove(ImmutableMap.of("site", "lon")); continue; } if (data.getKey().equals(ImmutableMap.of("site", "sto"))) { assertEquals(ImmutableList.of(new Point(1, 1.0), new Point(2, 2.0)), data.getMetrics().data()); expected.remove(ImmutableMap.of("site", "sto")); continue; } if (data.getKey().equals(ImmutableMap.of())) { assertEquals(ImmutableList.of(new Point(4, 4.0)), data.getMetrics().data()); expected.remove(ImmutableMap.of()); continue; } Assert.fail("unexpected group: " + data.getKey()); } }