use of org.hisp.dhis.commons.collection.PaginatedList in project dhis2-core by dhis2.
the class DefaultQueryPlanner method splitByDimension.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Splits the given list of queries in sub queries on the given dimension.
*/
private DataQueryGroups splitByDimension(DataQueryGroups queryGroups, String dimension, int optimalQueries) {
int optimalForSubQuery = MathUtils.divideToFloor(optimalQueries, queryGroups.getLargestGroupSize());
List<DataQueryParams> subQueries = new ArrayList<>();
for (DataQueryParams query : queryGroups.getAllQueries()) {
DimensionalObject dim = query.getDimension(dimension);
List<DimensionalItemObject> values = null;
if (dim == null || (values = dim.getItems()) == null || values.isEmpty()) {
subQueries.add(DataQueryParams.newBuilder(query).build());
continue;
}
List<List<DimensionalItemObject>> valuePages = new PaginatedList<>(values).setNumberOfPages(optimalForSubQuery).getPages();
for (List<DimensionalItemObject> valuePage : valuePages) {
DataQueryParams subQuery = DataQueryParams.newBuilder(query).withDimensionOptions(dim.getDimension(), valuePage).build();
subQueries.add(subQuery);
}
}
if (subQueries.size() > queryGroups.getAllQueries().size()) {
log.debug(String.format("Split on dimension %s: %d", dimension, (subQueries.size() / queryGroups.getAllQueries().size())));
}
return DataQueryGroups.newBuilder().withQueries(subQueries).build();
}
Aggregations