use of org.apache.druid.query.topn.TopNResultValue in project druid by druid-io.
the class CachingQueryRunnerTest method makeTopNResults.
private List<Result> makeTopNResults(boolean cachedResults, Object... objects) {
List<Result> retVal = new ArrayList<>();
int index = 0;
while (index < objects.length) {
DateTime timestamp = (DateTime) objects[index++];
List<Map<String, Object>> values = new ArrayList<>();
while (index < objects.length && !(objects[index] instanceof DateTime)) {
if (objects.length - index < 3) {
throw new ISE("expect 3 values for each entry in the top list, had %d values left.", objects.length - index);
}
final double imps = ((Number) objects[index + 2]).doubleValue();
final double rows = ((Number) objects[index + 1]).doubleValue();
if (cachedResults) {
values.add(ImmutableMap.of("top_dim", objects[index], "rows", rows, "imps", imps, "impers", imps));
} else {
values.add(ImmutableMap.of("top_dim", objects[index], "rows", rows, "imps", imps, "impers", imps, "avg_imps_per_row", imps / rows));
}
index += 3;
}
retVal.add(new Result<>(timestamp, new TopNResultValue(values)));
}
return retVal;
}
use of org.apache.druid.query.topn.TopNResultValue in project druid by druid-io.
the class CachingClusteredClientTest method makeTopNResults.
private Iterable<Result<TopNResultValue>> makeTopNResults(List<String> names, Object... objects) {
Preconditions.checkArgument(names.size() == 7);
List<Result<TopNResultValue>> retVal = new ArrayList<>();
int index = 0;
while (index < objects.length) {
DateTime timestamp = (DateTime) objects[index++];
List<Map<String, Object>> values = new ArrayList<>();
while (index < objects.length && !(objects[index] instanceof DateTime)) {
if (objects.length - index < 3) {
throw new ISE("expect 3 values for each entry in the top list, had %d values left.", objects.length - index);
}
final double imps = ((Number) objects[index + 2]).doubleValue();
final double rows = ((Number) objects[index + 1]).doubleValue();
values.add(ImmutableMap.<String, Object>builder().put(names.get(0), objects[index]).put(names.get(1), rows).put(names.get(2), imps).put(names.get(3), imps).put(names.get(4), imps / rows).put(names.get(5), ((imps * 2) / rows)).put(names.get(6), (imps / (rows * 2))).build());
index += 3;
}
retVal.add(new Result<>(timestamp, new TopNResultValue(values)));
}
return retVal;
}
Aggregations