Search in sources :

Example 31 with QueryPlannerParams

use of org.hisp.dhis.analytics.QueryPlannerParams 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)

Aggregations

QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)31 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)29 DhisSpringTest (org.hisp.dhis.DhisSpringTest)24 DataQueryGroups (org.hisp.dhis.analytics.DataQueryGroups)24 Test (org.junit.jupiter.api.Test)19 Function (java.util.function.Function)5 DimensionalObject (org.hisp.dhis.common.DimensionalObject)5 Test (org.junit.Test)5 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)4 ArrayList (java.util.ArrayList)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Partitions (org.hisp.dhis.analytics.Partitions)2 QueryModifiers (org.hisp.dhis.common.QueryModifiers)2 Period (org.hisp.dhis.period.Period)2 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)2 Timer (org.hisp.dhis.util.Timer)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1