Skip to content

Commit

Permalink
Merge pull request #3334 from ingef/feature/properly-count-rows
Browse files Browse the repository at this point in the history
properly count entities/lines
  • Loading branch information
awildturtok authored Mar 11, 2024
2 parents 8a388e0 + 9e84864 commit fe16a40
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public static ResultStatistics collectResultStatistics(ManagedQuery managedQuery
// Span date-column
final ListenableFuture<Range<LocalDate>> futureSpan = executorService.submit(() -> calculateDateSpan(managedQuery, dateInfo, dateIndex));

// Count result lines (may differ in case of form or SecondaryIdQuery)
final ListenableFuture<Integer>
futureLines =
executorService.submit(() -> managedQuery.streamResults(OptionalLong.empty()).mapToInt(result -> result.listResultLines().size()).sum());
// Count result lines and entities (may differ in case of form or SecondaryIdQuery)
final ListenableFuture<Integer> futureLines =
executorService.submit(() -> (int) managedQuery.getQuery().countResults(managedQuery.streamResults(OptionalLong.empty())));

final ListenableFuture<Integer> futureEntities =
executorService.submit(() -> (int) managedQuery.streamResults(OptionalLong.empty()).count());

// compute ResultColumnStatistics for each column
final List<ListenableFuture<ColumnStatsCollector.ResultColumnStatistics>>
Expand Down Expand Up @@ -77,7 +79,11 @@ public static ResultStatistics collectResultStatistics(ManagedQuery managedQuery
final Range<LocalDate> span = futureSpan.get();
final List<ColumnStatsCollector.ResultColumnStatistics> descriptions = Futures.allAsList(futureDescriptions).get();
final int lines = futureLines.get();
return new ResultStatistics(managedQuery.getLastResultCount().intValue(), lines, descriptions, span);
final int entities = futureEntities.get();

executorService.shutdown();

return new ResultStatistics(entities, lines, descriptions, span);
}

private static Range<LocalDate> calculateDateSpan(SingleTableResult managedQuery, Optional<ResultInfo> dateInfo, int dateIndex) {
Expand Down

0 comments on commit fe16a40

Please sign in to comment.