Source:
public FullQuery end(int resolved, int failed, int cancelled) throws Exception { final QueryTrace trace = buildTrace(); final ImmutableList.Builder<RequestError> errorsBuilder = ImmutableList.builder(); errorsBuilder.addAll(requestErrors); dataInMemoryReporter.reportOperationEnded(); final ImmutableSet.Builder<ResultLimit> limitsBuilder = ImmutableSet.<ResultLimit>builder().addAll(this.limits.getLimits()); if (watcher.isRetainQuotaViolated()) { limitsBuilder.add(ResultLimit.AGGREGATION); } if (watcher.isReadQuotaViolated()) { limitsBuilder.add(ResultLimit.QUOTA); } if (watcher.isReadQuotaViolated() || failOnLimits && watcher.isRetainQuotaViolated()) { errorsBuilder.add(QueryError.fromMessage( checkIssues(failed, cancelled).orElse("Query exceeded quota"))); return new FullQuery(trace, errorsBuilder.build(), ImmutableList.of(), Statistics.empty(), new ResultLimits(limitsBuilder.build())); } checkIssues(failed, cancelled).map(RuntimeException::new).ifPresent(e -> { for (final Throwable t : errors) { e.addSuppressed(t); } throw e; }); final AggregationResult result = session.result(); final List<ResultGroup> groups = new ArrayList<>(); for (final AggregationOutput group : result.getResult()) { if (groupLimit.isGreaterOrEqual(groups.size())) { if (failOnLimits) { errorsBuilder.add(QueryError.fromMessage( "The number of result groups is more than the allowed limit of " + groupLimit)); return new FullQuery(trace, errorsBuilder.build(), ImmutableList.of(), Statistics.empty(), new ResultLimits(limitsBuilder.add(ResultLimit.GROUP).build())); } limitsBuilder.add(ResultLimit.GROUP); break; } groups.add(new ResultGroup(group.getKey(), group.getSeries(), group.getMetrics(), aggregation.cadence())); } return new FullQuery(trace, errorsBuilder.build(), groups, result.getStatistics(), new ResultLimits(limitsBuilder.build())); }

Target:
public FullQuery end(int resolved, int failed, int cancelled) throws Exception { final QueryTrace trace = buildTrace(); final ImmutableList.Builder<RequestError> errorsBuilder = ImmutableList.builder(); errorsBuilder.addAll(requestErrors); dataInMemoryReporter.reportOperationEnded(); final ImmutableSet.Builder<ResultLimit> limitsBuilder = ImmutableSet.<ResultLimit>builder().addAll(this.limits.getLimits()); if (watcher.isRetainQuotaViolated()) { limitsBuilder.add(ResultLimit.AGGREGATION); } if (watcher.isReadQuotaViolated()) { limitsBuilder.add(ResultLimit.QUOTA); } if (watcher.isReadQuotaViolated() || watcher.isRetainQuotaViolated()) { errorsBuilder.add(QueryError.fromMessage( checkIssues(failed, cancelled).orElse("Query exceeded quota"))); return new FullQuery(trace, errorsBuilder.build(), ImmutableList.of(), Statistics.empty(), new ResultLimits(limitsBuilder.build())); } checkIssues(failed, cancelled).map(RuntimeException::new).ifPresent(e -> { for (final Throwable t : errors) { e.addSuppressed(t); } throw e; }); final AggregationResult result = session.result(); final List<ResultGroup> groups = new ArrayList<>(); for (final AggregationOutput group : result.getResult()) { if (groupLimit.isGreaterOrEqual(groups.size())) { if (failOnLimits) { errorsBuilder.add(QueryError.fromMessage( "The number of result groups is more than the allowed limit of " + groupLimit)); return new FullQuery(trace, errorsBuilder.build(), ImmutableList.of(), Statistics.empty(), new ResultLimits(limitsBuilder.add(ResultLimit.GROUP).build())); } limitsBuilder.add(ResultLimit.GROUP); break; } groups.add(new ResultGroup(group.getKey(), group.getSeries(), group.getMetrics(), aggregation.cadence())); } return new FullQuery(trace, errorsBuilder.build(), groups, result.getStatistics(), new ResultLimits(limitsBuilder.build())); }