use of org.hisp.dhis.analytics.QueryPlannerParams in project dhis2-core by dhis2.
the class DataHandler method addRawData.
/**
* Adds raw data to the grid for the given data query parameters.
*
* @param params the {@link DataQueryParams}.
* @param grid the grid.
*/
void addRawData(DataQueryParams params, Grid grid) {
if (!params.isSkipData()) {
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withTableType(DATA_VALUE).build();
params = queryPlanner.withTableNameAndPartitions(params, plannerParams);
rawAnalyticsManager.getRawDataValues(params, grid);
}
}
use of org.hisp.dhis.analytics.QueryPlannerParams in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryE.
/**
* Query spans 2 aggregation types. Splits on 2 aggregation types, then
* splits one query on 3 days in period to satisfy optimal for a total of 4
* queries. No organisation units specified.
*/
@Test
void planQueryE() {
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC)).withPeriods(getList(createPeriod("200001"), createPeriod("200002"), createPeriod("200003"), createPeriod("200004"), createPeriod("200005"), createPeriod("200006"), createPeriod("200007"), createPeriod("200008"), createPeriod("200009"))).build();
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableType(ANALYTICS_TABLE_TYPE).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
assertEquals(4, queryGroups.getAllQueries().size());
assertEquals(2, queryGroups.getSequentialQueries().size());
assertEquals(3, queryGroups.getLargestGroupSize());
for (DataQueryParams query : queryGroups.getAllQueries()) {
assertTrue(samePeriodType(query.getPeriods()));
assertDimensionNameNotNull(query);
}
}
use of org.hisp.dhis.analytics.QueryPlannerParams in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryI.
/**
* Query spans 3 period types. Splits in 3 queries for each period type,
* then splits in 2 queries on data type, then splits in 2 queries on data
* elements to satisfy optimal for a total of 12 queries, because query has
* 2 different aggregation types.
*/
@Test
void planQueryI() {
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deE, deF)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).withPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"), createPeriod("2000"), createPeriod("200002"), createPeriod("200003"), createPeriod("200004"))).build();
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(6).withTableType(ANALYTICS_TABLE_TYPE).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
assertEquals(12, queryGroups.getAllQueries().size());
assertEquals(2, queryGroups.getSequentialQueries().size());
assertEquals(6, queryGroups.getLargestGroupSize());
for (DataQueryParams query : queryGroups.getAllQueries()) {
assertTrue(samePeriodType(query.getPeriods()));
assertDimensionNameNotNull(query);
}
}
use of org.hisp.dhis.analytics.QueryPlannerParams in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryN.
/**
* Query spans 5 QueryModifiers minDate/MaxDate combinations.
*/
@Test
void planQueryN() {
QueryModifiers modsA = QueryModifiers.builder().minDate(parseDate("2022-01-01")).build();
QueryModifiers modsB = QueryModifiers.builder().minDate(parseDate("2022-02-01")).build();
QueryModifiers modsC = QueryModifiers.builder().maxDate(parseDate("2022-12-31")).build();
QueryModifiers modsD = QueryModifiers.builder().minDate(parseDate("2022-01-01")).maxDate(parseDate("2022-12-31")).build();
deC.setQueryMods(modsA);
deD.setQueryMods(modsB);
deG.setQueryMods(modsC);
deH.setQueryMods(modsD);
deI.setQueryMods(modsD);
deC.setAggregationType(AggregationType.SUM);
deD.setAggregationType(AggregationType.SUM);
deI.setAggregationType(AggregationType.SUM);
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC, deD, deG, deH, deI)).withPeriods(getList(createPeriod("2022"))).build();
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableType(ANALYTICS_TABLE_TYPE).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
assertEquals(5, queryGroups.getAllQueries().size());
assertEquals(1, queryGroups.getSequentialQueries().size());
assertEquals(5, queryGroups.getLargestGroupSize());
List<DataQueryParams> group = queryGroups.getAllQueries();
assertQueryMods(group, null, deA, deB);
assertQueryMods(group, modsA, deC);
assertQueryMods(group, modsB, deD);
assertQueryMods(group, modsC, deG);
assertQueryMods(group, modsD, deH, deI);
}
use of org.hisp.dhis.analytics.QueryPlannerParams in project dhis2-core by dhis2.
the class QueryPlannerTest method testWithTableTypeAndPartition.
@Test
void testWithTableTypeAndPartition() {
DataQueryParams params = DataQueryParams.newBuilder().withStartDate(getDate(2014, 4, 1)).withEndDate(getDate(2016, 8, 1)).build();
assertTrue(params.hasStartEndDate());
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withTableType(ANALYTICS_TABLE_TYPE).build();
DataQueryParams query = queryPlanner.withTableNameAndPartitions(params, plannerParams);
Partitions partitions = query.getPartitions();
Partitions expected = new Partitions(Sets.newHashSet(0, 2014, 2015, 2016));
assertNotNull(partitions);
assertEquals(4, partitions.getPartitions().size());
assertEquals(expected, partitions);
assertEquals(ANALYTICS_TABLE_TYPE.getTableName(), query.getTableName());
}
Aggregations