Search in sources :

Example 1 with DATA_X_DIM_ID

use of org.hisp.dhis.common.DimensionalObject.DATA_X_DIM_ID in project dhis2-core by dhis2.

the class DefaultQueryPlanner method planQuery.

// -------------------------------------------------------------------------
// QueryPlanner implementation
// -------------------------------------------------------------------------
@Override
public DataQueryGroups planQuery(DataQueryParams params, QueryPlannerParams plannerParams) {
    params = PeriodOffsetUtils.addShiftedPeriods(params);
    // ---------------------------------------------------------------------
    // Group queries which can be executed together
    // ---------------------------------------------------------------------
    params = withTableNameAndPartitions(params, plannerParams);
    partitionManager.filterNonExistingPartitions(params.getPartitions(), plannerParams.getTableName());
    final List<DataQueryParams> queries = Lists.newArrayList(params);
    List<Function<DataQueryParams, List<DataQueryParams>>> groupers = new ImmutableList.Builder<Function<DataQueryParams, List<DataQueryParams>>>().add(q -> groupByOrgUnitLevel(q)).add(q -> groupByPeriodType(q)).add(q -> groupByDataType(q)).add(q -> groupByMinMaxDate(q)).add(q -> groupByAggregationType(q)).add(q -> groupByDaysInPeriod(q)).add(q -> groupByDataPeriodType(q)).add(q -> groupByPeriod(q)).addAll(plannerParams.getQueryGroupers()).build();
    for (Function<DataQueryParams, List<DataQueryParams>> grouper : groupers) {
        List<DataQueryParams> currentQueries = Lists.newArrayList(queries);
        queries.clear();
        currentQueries.forEach(query -> queries.addAll(grouper.apply(query)));
    }
    // ---------------------------------------------------------------------
    // Split queries until optimal number
    // ---------------------------------------------------------------------
    DataQueryGroups queryGroups = DataQueryGroups.newBuilder().withQueries(queries).build();
    if (queryGroups.isOptimal(plannerParams.getOptimalQueries())) {
        return queryGroups;
    }
    List<String> splitDimensions = Lists.newArrayList(DATA_X_DIM_ID, ORGUNIT_DIM_ID);
    for (String dim : splitDimensions) {
        queryGroups = splitByDimension(queryGroups, dim, plannerParams.getOptimalQueries());
        if (queryGroups.isOptimal(plannerParams.getOptimalQueries())) {
            break;
        }
    }
    return queryGroups;
}
Also used : ORGUNIT_DIM_ID(org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID) ListMap(org.hisp.dhis.common.ListMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) LEVEL_PREFIX(org.hisp.dhis.analytics.DataQueryParams.LEVEL_PREFIX) DataType(org.hisp.dhis.analytics.DataType) DateUtils.getLatest(org.hisp.dhis.util.DateUtils.getLatest) Function(java.util.function.Function) PartitionManager(org.hisp.dhis.analytics.partition.PartitionManager) PartitionUtils(org.hisp.dhis.analytics.table.PartitionUtils) PeriodOffsetUtils(org.hisp.dhis.analytics.util.PeriodOffsetUtils) ArrayList(java.util.ArrayList) DataElement(org.hisp.dhis.dataelement.DataElement) PaginatedList(org.hisp.dhis.commons.collection.PaginatedList) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) DateUtils.getEarliest(org.hisp.dhis.util.DateUtils.getEarliest) AnalyticsAggregationType(org.hisp.dhis.analytics.AnalyticsAggregationType) DATA_X_DIM_ID(org.hisp.dhis.common.DimensionalObject.DATA_X_DIM_ID) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) ErrorCode(org.hisp.dhis.feedback.ErrorCode) AnalyticsTableType(org.hisp.dhis.analytics.AnalyticsTableType) Period(org.hisp.dhis.period.Period) Partitions(org.hisp.dhis.analytics.Partitions) DataDimensionItemType(org.hisp.dhis.common.DataDimensionItemType) QueryPlanner(org.hisp.dhis.analytics.QueryPlanner) PERIOD_DIM_ID(org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) AggregationType(org.hisp.dhis.analytics.AggregationType) AnalyticsUtils.throwIllegalQueryEx(org.hisp.dhis.analytics.util.AnalyticsUtils.throwIllegalQueryEx) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionType(org.hisp.dhis.common.DimensionType) QueryModifiers(org.hisp.dhis.common.QueryModifiers) ObjectUtils(org.hisp.dhis.util.ObjectUtils) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalObject(org.hisp.dhis.common.DimensionalObject) PeriodType(org.hisp.dhis.period.PeriodType) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) MathUtils(org.hisp.dhis.system.util.MathUtils) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PaginatedList(org.hisp.dhis.commons.collection.PaginatedList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Function (java.util.function.Function)1 Slf4j (lombok.extern.slf4j.Slf4j)1 AggregationType (org.hisp.dhis.analytics.AggregationType)1 AnalyticsAggregationType (org.hisp.dhis.analytics.AnalyticsAggregationType)1 AnalyticsTableType (org.hisp.dhis.analytics.AnalyticsTableType)1 DataQueryGroups (org.hisp.dhis.analytics.DataQueryGroups)1 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 LEVEL_PREFIX (org.hisp.dhis.analytics.DataQueryParams.LEVEL_PREFIX)1 DataType (org.hisp.dhis.analytics.DataType)1 Partitions (org.hisp.dhis.analytics.Partitions)1 QueryPlanner (org.hisp.dhis.analytics.QueryPlanner)1 QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)1 PartitionManager (org.hisp.dhis.analytics.partition.PartitionManager)1 PartitionUtils (org.hisp.dhis.analytics.table.PartitionUtils)1 AnalyticsUtils.throwIllegalQueryEx (org.hisp.dhis.analytics.util.AnalyticsUtils.throwIllegalQueryEx)1