use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryAggregationTypeA.
/**
* Split on two data elements. Set aggregation type average and value type
* integer on query. Convert aggregation type from data elements to average
* and then to average integer.
*/
@Test
public void planQueryAggregationTypeA() {
DataElement deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM);
DataElement deB = createDataElement('B', ValueType.INTEGER, AggregationType.COUNT);
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB)).withOrganisationUnits(getList(ouA)).withPeriods(getList(createPeriod("200101"))).withAggregationType(AggregationType.AVERAGE).build();
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableName(ANALYTICS_TABLE_NAME).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
assertEquals(2, queryGroups.getAllQueries().size());
for (DataQueryParams query : queryGroups.getAllQueries()) {
assertNotNull(query.getAggregationType());
assertEquals(AggregationType.AVERAGE_INT, query.getAggregationType());
}
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class QueryPlannerTest method testGetDataPeriodAggregationPeriodMap.
@Test
public void testGetDataPeriodAggregationPeriodMap() {
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC, deD)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).withPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"), createPeriod("2000Q3"), createPeriod("2000Q4"), createPeriod("2001Q1"), createPeriod("2001Q2"))).withPeriodType(QuarterlyPeriodType.NAME).withDataPeriodType(new YearlyPeriodType()).build();
ListMap<DimensionalItemObject, DimensionalItemObject> map = params.getDataPeriodAggregationPeriodMap();
assertEquals(2, map.size());
assertTrue(map.keySet().contains(createPeriod("2000")));
assertTrue(map.keySet().contains(createPeriod("2001")));
assertEquals(4, map.get(createPeriod("2000")).size());
assertEquals(2, map.get(createPeriod("2001")).size());
assertTrue(map.get(createPeriod("2000")).contains(createPeriod("2000Q1")));
assertTrue(map.get(createPeriod("2000")).contains(createPeriod("2000Q2")));
assertTrue(map.get(createPeriod("2000")).contains(createPeriod("2000Q3")));
assertTrue(map.get(createPeriod("2000")).contains(createPeriod("2000Q4")));
assertTrue(map.get(createPeriod("2001")).contains(createPeriod("2001Q1")));
assertTrue(map.get(createPeriod("2001")).contains(createPeriod("2001Q2")));
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class QueryPlannerTest method validateMissingOrgUnitDimensionOutputFormatDataValueSet.
@Test(expected = IllegalQueryException.class)
public void validateMissingOrgUnitDimensionOutputFormatDataValueSet() {
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).withOutputFormat(OutputFormat.DATA_VALUE_SET).build();
queryPlanner.validate(params);
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryG.
/**
* Expected to fail because of no periods specified.
*/
@Test(expected = IllegalQueryException.class)
public void planQueryG() {
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).build();
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableName(ANALYTICS_TABLE_NAME).build();
queryPlanner.planQuery(params, plannerParams);
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class EventQueryPlannerTest method testFromDataQueryParams.
@Test
public void testFromDataQueryParams() {
DataQueryParams dataQueryParams = DataQueryParams.newBuilder().withProgramDataElements(getList(pdeA, pdeB, pdeC, pdeD)).withProgramAttributes(getList(patA, patB)).withOrganisationUnits(getList(ouA, ouB, ouC)).withPeriods(getList(createPeriod("200101"), createPeriod("200103"), createPeriod("200105"), createPeriod("200107"))).build();
EventQueryParams params = EventQueryParams.fromDataQueryParams(dataQueryParams);
assertEquals(6, params.getItems().size());
assertNull(params.getDimension(DimensionalObject.DATA_X_DIM_ID));
assertTrue(params.isAggregateData());
for (QueryItem item : params.getItems()) {
assertEquals(prA, item.getProgram());
}
}
Aggregations