Search in sources :

Example 26 with DataQueryGroups

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());
    }
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 27 with DataQueryGroups

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);
    }
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 28 with DataQueryGroups

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));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Test(org.junit.jupiter.api.Test)

Example 29 with DataQueryGroups

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));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Test(org.junit.jupiter.api.Test)

Example 30 with DataQueryGroups

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))))));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Aggregations

DataQueryGroups (org.hisp.dhis.analytics.DataQueryGroups)31 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)31 Test (org.junit.jupiter.api.Test)25 QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)24 DhisSpringTest (org.hisp.dhis.DhisSpringTest)20 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)11 Function (java.util.function.Function)5 CategoryCombo (org.hisp.dhis.category.CategoryCombo)5 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)5 DimensionalObject (org.hisp.dhis.common.DimensionalObject)5 ArrayList (java.util.ArrayList)4 DataElement (org.hisp.dhis.dataelement.DataElement)3 HashMap (java.util.HashMap)2 QueryModifiers (org.hisp.dhis.common.QueryModifiers)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)2 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)2 Timer (org.hisp.dhis.util.Timer)2 DateTime (org.joda.time.DateTime)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1