use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryStartEndDateQueryGrouperA.
/**
* Splits in 4 queries for each period to satisfy optimal for a total
* of 4 queries, because all queries have different periods.
*/
@Test
public void planQueryStartEndDateQueryGrouperA() {
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB)).withOrganisationUnits(getList(ouA)).withPeriods(getList(createPeriod("200101"), createPeriod("200102"), createPeriod("200103"), createPeriod("200104"))).build();
List<Function<DataQueryParams, List<DataQueryParams>>> queryGroupers = Lists.newArrayList();
queryGroupers.add(q -> queryPlanner.groupByStartEndDate(q));
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableName(ANALYTICS_TABLE_NAME).withQueryGroupers(queryGroupers).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
List<DataQueryParams> queries = queryGroups.getAllQueries();
assertEquals(4, queries.size());
assertEquals(1, queryGroups.getSequentialQueries().size());
assertEquals(4, queryGroups.getLargestGroupSize());
for (DataQueryParams query : queries) {
assertNotNull(query.getStartDate());
assertNotNull(query.getEndDate());
assertDimensionNameNotNull(query);
DimensionalObject periodDim = query.getDimension(PERIOD_DIM_ID);
assertNotNull(periodDim.getDimensionName());
assertTrue(periodDim.isFixed());
}
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryH.
/**
* Query filters span 2 partitions. Splits in 2 queries on data elements,
* then 2 queries on organisation units to satisfy optimal for a total of 8
* queries.
*/
@Test
public void planQueryH() {
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC, deD)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).withFilterPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"), createPeriod("2000Q3"), createPeriod("2000Q4"), createPeriod("2001Q1"), createPeriod("2001Q2"))).build();
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableName(ANALYTICS_TABLE_NAME).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
assertEquals(8, queryGroups.getAllQueries().size());
assertEquals(2, queryGroups.getSequentialQueries().size());
assertEquals(4, queryGroups.getLargestGroupSize());
for (DataQueryParams query : queryGroups.getAllQueries()) {
assertDimensionNameNotNull(query);
assertTrue(query.spansMultiplePartitions());
}
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class QueryPlannerTest method testGroupByPartition.
@Test
public void testGroupByPartition() {
DataQueryParams params = DataQueryParams.newBuilder().withStartDate(getDate(2014, 4, 1)).withEndDate(getDate(2016, 8, 1)).build();
assertTrue(params.hasStartEndDate());
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withTableName(ANALYTICS_TABLE_NAME).build();
List<DataQueryParams> queries = queryPlanner.groupByPartition(params, plannerParams);
assertEquals(1, queries.size());
DataQueryParams query = queries.get(0);
List<String> partitions = query.getPartitions().getPartitions();
assertNotNull(partitions);
assertEquals(3, partitions.size());
assertEquals(ANALYTICS_TABLE_NAME + "_2014", partitions.get(0));
assertEquals(ANALYTICS_TABLE_NAME + "_2015", partitions.get(1));
assertEquals(ANALYTICS_TABLE_NAME + "_2016", partitions.get(2));
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class QueryPlannerTest method testGetDimensionOptionPermutations.
/**
* Ignores data element dimension and generates 2 x 3 = 6 combinations based
* on organisation unit and period dimensions.
*/
@Test
public void testGetDimensionOptionPermutations() {
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB)).withOrganisationUnits(getList(ouA, ouB, ouC)).withPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"))).build();
List<List<DimensionItem>> permutations = params.getDimensionItemPermutations();
assertNotNull(permutations);
assertEquals(6, permutations.size());
for (List<DimensionItem> permutation : permutations) {
assertNotNull(permutation);
assertEquals(2, permutation.size());
assertEquals(ORGUNIT_DIM_ID, permutation.get(0).getDimension());
assertEquals(PERIOD_DIM_ID, permutation.get(1).getDimension());
}
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryE.
/**
* Query spans 1 partition. 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
public 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).withTableName(ANALYTICS_TABLE_NAME).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()));
assertTrue(samePartition(query.getPeriods()));
assertDimensionNameNotNull(query);
}
}
Aggregations