Search in sources :

Example 1 with PaginatedList

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();
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) PaginatedList(org.hisp.dhis.commons.collection.PaginatedList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DimensionalObjectUtils.asTypedList(org.hisp.dhis.common.DimensionalObjectUtils.asTypedList) PaginatedList(org.hisp.dhis.commons.collection.PaginatedList) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1 DimensionalObjectUtils.asTypedList (org.hisp.dhis.common.DimensionalObjectUtils.asTypedList)1 PaginatedList (org.hisp.dhis.commons.collection.PaginatedList)1