diff --git a/benchmarks/src/main/java/org/apache/druid/benchmark/query/GroupByBenchmark.java b/benchmarks/src/main/java/org/apache/druid/benchmark/query/GroupByBenchmark.java index f96aef616c1..4fd2c1e70b1 100644 --- a/benchmarks/src/main/java/org/apache/druid/benchmark/query/GroupByBenchmark.java +++ b/benchmarks/src/main/java/org/apache/druid/benchmark/query/GroupByBenchmark.java @@ -563,10 +563,7 @@ public class GroupByBenchmark ); List results = GroupByBenchmark.runQuery(factory, runner, query); - - for (Row result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @Benchmark @@ -581,10 +578,7 @@ public class GroupByBenchmark ); List results = GroupByBenchmark.runQuery(factory, runner, query); - - for (Row result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @Benchmark @@ -602,10 +596,7 @@ public class GroupByBenchmark Sequence queryResult = theRunner.run(QueryPlus.wrap(query), new HashMap<>()); List results = queryResult.toList(); - - for (Row result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @Benchmark @@ -626,10 +617,7 @@ public class GroupByBenchmark ); Sequence queryResult = theRunner.run(QueryPlus.wrap(spillingQuery), new HashMap<>()); List results = queryResult.toList(); - - for (Row result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @Benchmark @@ -653,10 +641,7 @@ public class GroupByBenchmark Sequence queryResult = theRunner.run(QueryPlus.wrap(query), new HashMap<>()); List results = queryResult.toList(); - - for (Row result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } private List> makeMultiRunners() diff --git a/benchmarks/src/main/java/org/apache/druid/benchmark/query/SearchBenchmark.java b/benchmarks/src/main/java/org/apache/druid/benchmark/query/SearchBenchmark.java index 122914ba00e..2c5617e937b 100644 --- a/benchmarks/src/main/java/org/apache/druid/benchmark/query/SearchBenchmark.java +++ b/benchmarks/src/main/java/org/apache/druid/benchmark/query/SearchBenchmark.java @@ -418,10 +418,7 @@ public class SearchBenchmark ); List> results = SearchBenchmark.runQuery(factory, runner, query); - List hits = results.get(0).getValue().getValue(); - for (SearchHit hit : hits) { - blackhole.consume(hit); - } + blackhole.consume(results); } @Benchmark @@ -436,10 +433,7 @@ public class SearchBenchmark ); List> results = SearchBenchmark.runQuery(factory, runner, query); - List hits = results.get(0).getValue().getValue(); - for (SearchHit hit : hits) { - blackhole.consume(hit); - } + blackhole.consume(results); } @@ -472,12 +466,6 @@ public class SearchBenchmark new HashMap<>() ); List> results = queryResult.toList(); - - for (Result result : results) { - List hits = result.getValue().getValue(); - for (SearchHit hit : hits) { - blackhole.consume(hit); - } - } + blackhole.consume(results); } } diff --git a/benchmarks/src/main/java/org/apache/druid/benchmark/query/SelectBenchmark.java b/benchmarks/src/main/java/org/apache/druid/benchmark/query/SelectBenchmark.java index b802ba0cb23..28bbb1ff4a8 100644 --- a/benchmarks/src/main/java/org/apache/druid/benchmark/query/SelectBenchmark.java +++ b/benchmarks/src/main/java/org/apache/druid/benchmark/query/SelectBenchmark.java @@ -336,9 +336,7 @@ public class SelectBenchmark if (result.getEvents().size() == 0) { done = true; } else { - for (EventHolder eh : result.getEvents()) { - blackhole.consume(eh); - } + blackhole.consume(result); queryCopy = incrementQueryPagination(queryCopy, result); } } @@ -382,9 +380,7 @@ public class SelectBenchmark if (result.getEvents().size() == 0) { done = true; } else { - for (EventHolder eh : result.getEvents()) { - blackhole.consume(eh); - } + blackhole.consume(result); queryCopy = incrementQueryPagination(queryCopy, result); } } diff --git a/benchmarks/src/main/java/org/apache/druid/benchmark/query/SqlBenchmark.java b/benchmarks/src/main/java/org/apache/druid/benchmark/query/SqlBenchmark.java index 1f515882753..529886a96f6 100644 --- a/benchmarks/src/main/java/org/apache/druid/benchmark/query/SqlBenchmark.java +++ b/benchmarks/src/main/java/org/apache/druid/benchmark/query/SqlBenchmark.java @@ -173,10 +173,7 @@ public class SqlBenchmark { final Sequence resultSequence = QueryPlus.wrap(groupByQuery).run(walker, new HashMap<>()); final List resultList = resultSequence.toList(); - - for (Row row : resultList) { - blackhole.consume(row); - } + blackhole.consume(resultList); } @Benchmark diff --git a/benchmarks/src/main/java/org/apache/druid/benchmark/query/TimeseriesBenchmark.java b/benchmarks/src/main/java/org/apache/druid/benchmark/query/TimeseriesBenchmark.java index 5c58c94ff87..ac413c49ae4 100644 --- a/benchmarks/src/main/java/org/apache/druid/benchmark/query/TimeseriesBenchmark.java +++ b/benchmarks/src/main/java/org/apache/druid/benchmark/query/TimeseriesBenchmark.java @@ -342,9 +342,7 @@ public class TimeseriesBenchmark ); List> results = TimeseriesBenchmark.runQuery(factory, runner, query); - for (Result result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @Benchmark @@ -359,9 +357,7 @@ public class TimeseriesBenchmark ); List> results = TimeseriesBenchmark.runQuery(factory, runner, query); - for (Result result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @Benchmark @@ -379,9 +375,7 @@ public class TimeseriesBenchmark Query filteredQuery = query.withDimFilter(filter); List> results = TimeseriesBenchmark.runQuery(factory, runner, filteredQuery); - for (Result result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @Benchmark @@ -414,8 +408,6 @@ public class TimeseriesBenchmark ); List> results = queryResult.toList(); - for (Result result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } } diff --git a/benchmarks/src/main/java/org/apache/druid/benchmark/query/TopNBenchmark.java b/benchmarks/src/main/java/org/apache/druid/benchmark/query/TopNBenchmark.java index 566ebe326b2..fee4d429264 100644 --- a/benchmarks/src/main/java/org/apache/druid/benchmark/query/TopNBenchmark.java +++ b/benchmarks/src/main/java/org/apache/druid/benchmark/query/TopNBenchmark.java @@ -326,9 +326,7 @@ public class TopNBenchmark ); List> results = TopNBenchmark.runQuery(factory, runner, query); - for (Result result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @Benchmark @@ -343,9 +341,7 @@ public class TopNBenchmark ); List> results = TopNBenchmark.runQuery(factory, runner, query); - for (Result result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @Benchmark @@ -377,9 +373,6 @@ public class TopNBenchmark new HashMap<>() ); List> results = queryResult.toList(); - - for (Result result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } } diff --git a/benchmarks/src/main/java/org/apache/druid/benchmark/query/timecompare/TimeCompareBenchmark.java b/benchmarks/src/main/java/org/apache/druid/benchmark/query/timecompare/TimeCompareBenchmark.java index 85ef6007af8..e50dde04471 100644 --- a/benchmarks/src/main/java/org/apache/druid/benchmark/query/timecompare/TimeCompareBenchmark.java +++ b/benchmarks/src/main/java/org/apache/druid/benchmark/query/timecompare/TimeCompareBenchmark.java @@ -422,10 +422,7 @@ public class TimeCompareBenchmark { Sequence> queryResult = topNRunner.run(QueryPlus.wrap(topNQuery), new HashMap<>()); List> results = queryResult.toList(); - - for (Result result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } @@ -439,9 +436,6 @@ public class TimeCompareBenchmark new HashMap<>() ); List> results = queryResult.toList(); - - for (Result result : results) { - blackhole.consume(result); - } + blackhole.consume(results); } } diff --git a/core/src/main/java/org/apache/druid/java/util/common/guava/Sequence.java b/core/src/main/java/org/apache/druid/java/util/common/guava/Sequence.java index 8e04f9f4cee..c5eded22d0f 100644 --- a/core/src/main/java/org/apache/druid/java/util/common/guava/Sequence.java +++ b/core/src/main/java/org/apache/druid/java/util/common/guava/Sequence.java @@ -71,6 +71,10 @@ public interface Sequence return new MappedSequence<>(this, mapper); } + /** + * Several benchmarks rely on this method to eagerly accumulate Sequences to ArrayLists. e.g. + * GroupByBenchmark. + */ default List toList() { return accumulate(new ArrayList<>(), Accumulators.list());