use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.
the class QueryPlannerTest method planQueryAggregationTypeB.
/**
* Split on two data elements. Set aggregation type average and value type
* boolean on query. Convert aggregation type from data elements to average
* and then to average boolean.
*/
@Test
void planQueryAggregationTypeB() {
DataElement deA = createDataElement('A', ValueType.BOOLEAN, AggregationType.SUM);
DataElement deB = createDataElement('B', ValueType.BOOLEAN, 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.BOOLEAN, query.getAggregationType().getDataType());
}
}
use of org.hisp.dhis.analytics.DataQueryGroups 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.DataQueryGroups in project dhis2-core by dhis2.
the class QueryPlannerGroupByAggregationTypeTest method verifyASingleDataElementAsFilterRetainAggregationTypeAndAggregationDataType.
@Test
void verifyASingleDataElementAsFilterRetainAggregationTypeAndAggregationDataType() {
// DataQueryParams with **one** DataElement as filter
DataQueryParams queryParams = createDataQueryParams(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', ValueType.INTEGER, AggregationType.MAX))));
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.MAX));
// Expect the datatype = NUMERIC (which will allow the SQL generator to
// pick-up
// the proper SQL function)
assertThat(dataQueryParam.getAggregationType().getDataType(), is(DataType.NUMERIC));
assertThat(dataQueryParam.getPeriods(), hasSize(1));
assertThat(dataQueryParam.getFilterDataElements(), hasSize(1));
assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.
the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterHavingDifferentAggTypeRetainAggregationType.
@Test
void verifyMultipleDataElementAsFilterHavingDifferentAggTypeRetainAggregationType() {
// DataQueryParams with **two** DataElement as filter
// Both have DataType NUMERIC but different AggregationType
// 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.INTEGER, 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 verifyMultipleDataElementIsAggregatedWithTwoQueryGroupWhenDataTypeIsDifferent.
@Test
void verifyMultipleDataElementIsAggregatedWithTwoQueryGroupWhenDataTypeIsDifferent() {
List<DimensionalItemObject> periods = new ArrayList<>();
periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
// DataQueryParams with **two** DataElement with different data type as
// dimension
DataQueryParams queryParams = DataQueryParams.newBuilder().withDimensions(// PERIOD DIMENSION
Lists.newArrayList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods), new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.TEXT, AggregationType.COUNT, DataElementDomain.AGGREGATE))))).withFilters(Lists.newArrayList(// OU FILTER
new BaseDimensionalObject("ou", DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, ImmutableList.of(new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))))).withAggregationType(AnalyticsAggregationType.AVERAGE).build();
DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
assertThat(dataQueryGroups.getAllQueries(), hasSize(2));
assertThat(dataQueryGroups.getAllQueries(), hasItem(both(hasProperty("aggregationType", hasProperty("aggregationType", is(AggregationType.AVERAGE)))).and(hasProperty("aggregationType", hasProperty("dataType", is(DataType.NUMERIC))))));
assertThat(dataQueryGroups.getAllQueries(), hasItem(both(hasProperty("aggregationType", hasProperty("aggregationType", is(AggregationType.AVERAGE)))).and(hasProperty("aggregationType", hasProperty("dataType", is(DataType.TEXT))))));
}
Aggregations