use of org.hisp.dhis.analytics.DataQueryGroups 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
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(AnalyticsAggregationType.AVERAGE).build();
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableType(ANALYTICS_TABLE_TYPE).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
assertEquals(2, queryGroups.getAllQueries().size());
for (DataQueryParams query : queryGroups.getAllQueries()) {
assertNotNull(query.getAggregationType());
assertEquals(AggregationType.AVERAGE, query.getAggregationType().getAggregationType());
assertEquals(DataType.NUMERIC, query.getAggregationType().getDataType());
}
}
use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryF.
/**
* Splits on 3 queries on organisation units for an optimal of 3 queries.
*/
@Test
void planQueryF() {
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).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(3, queryGroups.getAllQueries().size());
assertEquals(1, queryGroups.getSequentialQueries().size());
assertEquals(3, queryGroups.getLargestGroupSize());
for (DataQueryParams query : queryGroups.getAllQueries()) {
assertTrue(samePeriodType(query.getPeriods()));
assertDimensionNameNotNull(query);
}
}
use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.
the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterHavingDifferentDataTypeDoNotRetainAggregationType.
@Test
void verifyMultipleDataElementAsFilterHavingDifferentDataTypeDoNotRetainAggregationType() {
// DataQueryParams with **two** DataElement as filter
// One Data Element has Type Numeric
// Aggregation type is overridden (COUNT)
DataQueryParams queryParams = createDataQueryParamsWithAggregationType(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.TEXT, AggregationType.COUNT))), AnalyticsAggregationType.COUNT);
DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
// Aggregation type defaults to SUM
assertDefaultAggregationType(dataQueryParam);
assertThat(dataQueryParam.getAggregationType().getDataType(), is(nullValue()));
assertThat(dataQueryParam.getPeriods(), hasSize(1));
assertThat(dataQueryParam.getFilterDataElements(), hasSize(2));
assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.
the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterRetainAggregationTypeAndAggregationDataType.
@Test
void verifyMultipleDataElementAsFilterRetainAggregationTypeAndAggregationDataType() {
// DataQueryParams with **two** DataElement as filter
// Both have DataType NUMERIC and AggregationType SUM
DataQueryParams queryParams = createDataQueryParams(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', new CategoryCombo()))));
DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
assertTrue(dataQueryParam.getAggregationType().isAggregationType(AggregationType.SUM));
assertThat(dataQueryParam.getAggregationType().getDataType(), is(DataType.NUMERIC));
assertThat(dataQueryParam.getPeriods(), hasSize(1));
assertThat(dataQueryParam.getFilterDataElements(), hasSize(2));
assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.
the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterHavingDifferentAggTypeDoNotRetainAggregationType.
@Test
void verifyMultipleDataElementAsFilterHavingDifferentAggTypeDoNotRetainAggregationType() {
// DataQueryParams with **two** DataElement as filter
// Both have DataType NUMERIC but different AggregationType
DataQueryParams queryParams = createDataQueryParams(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.INTEGER, AggregationType.COUNT))));
DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
// Aggregation type defaults to SUM
assertDefaultAggregationType(dataQueryParam);
assertThat(dataQueryParam.getAggregationType().getDataType(), is(nullValue()));
assertThat(dataQueryParam.getPeriods(), hasSize(1));
assertThat(dataQueryParam.getFilterDataElements(), hasSize(2));
assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
Aggregations