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;
}
Aggregations