Search in sources :

Example 6 with DataQueryGroups

use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.

the class QueryPlannerTest method planQueryD.

/**
 * 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.
 */
@Test
void planQueryD() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC)).withOrganisationUnits(getList(ouA)).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 7 with DataQueryGroups

use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.

the class QueryPlannerTest method planQueryA.

/**
 * Query spans two period types and two aggregation types. Splits in 2
 * queries for each period type, then splits in 4 queries on data elements
 * to satisfy optimal of 4 queries per query group.
 */
@Test
void planQueryA() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC, deD)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).withPeriods(getList(createPeriod("200101"), createPeriod("200103"), createPeriod("200105"), createPeriod("200107"), createPeriod("2002Q3"), createPeriod("2002Q4"))).build();
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableType(ANALYTICS_TABLE_TYPE).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    assertEquals(8, queryGroups.getAllQueries().size());
    assertEquals(2, queryGroups.getSequentialQueries().size());
    assertEquals(4, 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 8 with DataQueryGroups

use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.

the class QueryPlannerTest method planQueryDataElementGroupSetDisaggregation.

/**
 * Query is type disaggregation as aggregation period type for periods is
 * monthly and data element groups period type is yearly. Split on two org
 * units.
 */
@Test
void planQueryDataElementGroupSetDisaggregation() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElementGroupSet(dgsB).withOrganisationUnits(getList(ouA, ouB)).withPeriods(getList(createPeriod("201001"), createPeriod("201003"))).build();
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableType(ANALYTICS_TABLE_TYPE).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    assertEquals(2, queryGroups.getAllQueries().size());
    assertEquals(1, queryGroups.getSequentialQueries().size());
    assertEquals(2, queryGroups.getLargestGroupSize());
    for (DataQueryParams query : queryGroups.getAllQueries()) {
        assertTrue(samePeriodType(query.getPeriods()));
        assertDimensionNameNotNull(query);
        assertNotNull(query.getDataPeriodType());
        assertEquals(yearly, query.getDataPeriodType());
        assertTrue(query.isDisaggregation());
    }
}
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 9 with DataQueryGroups

use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.

the class QueryPlannerTest method planQueryDataElementDisaggregation.

/**
 * Query is type disaggregation as aggregation period type for periods is
 * monthly and data elements period type is yearly. Split on two data
 * elements.
 */
@Test
void planQueryDataElementDisaggregation() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deI, deJ)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD)).withPeriods(getList(createPeriod("201001"), createPeriod("201003"))).build();
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableType(ANALYTICS_TABLE_TYPE).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    assertEquals(4, queryGroups.getAllQueries().size());
    assertEquals(1, queryGroups.getSequentialQueries().size());
    assertEquals(4, queryGroups.getLargestGroupSize());
    for (DataQueryParams query : queryGroups.getAllQueries()) {
        assertTrue(samePeriodType(query.getPeriods()));
        assertDimensionNameNotNull(query);
        assertNotNull(query.getDataPeriodType());
        assertEquals(yearly, query.getDataPeriodType());
        assertTrue(query.isDisaggregation());
    }
}
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 10 with DataQueryGroups

use of org.hisp.dhis.analytics.DataQueryGroups in project dhis2-core by dhis2.

the class QueryPlannerTest method planQueryM.

/**
 * Splits in 4 queries for data elements to satisfy optimal for a total of 4
 * queries.
 */
@Test
void planQueryM() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deG, deH)).withOrganisationUnits(getList(ouA)).withPeriods(getList(createPeriod("200101"), createPeriod("200103"))).build();
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableType(ANALYTICS_TABLE_TYPE).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    assertEquals(4, queryGroups.getAllQueries().size());
    assertEquals(1, queryGroups.getSequentialQueries().size());
    assertEquals(4, 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)

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