Search in sources :

Example 21 with DataQueryGroups

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

the class QueryPlannerTest method planQueryL.

/**
 * Splits in 2 queries for each data type, then 2 queries for each data
 * element, then 2 queries for each organisation unit to satisfy optimal for
 * a total of 8 queries with 4 queries across 2 sequential queries.
 */
@Test
void planQueryL() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deE, deF)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD)).withFilterPeriods(getList(createPeriod("2000Q1"))).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()) {
        assertDimensionNameNotNull(query);
        assertNotNull(query.getDataType());
    }
}
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 22 with DataQueryGroups

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

the class QueryPlannerTest method planQueryB.

/**
 * Query spans 3 period types. Splits in 3 queries for each period type,
 * then splits in 2 queries on organisation units to satisfy optimal for a
 * total of 6 queries.
 */
@Test
void planQueryB() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).withPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"), createPeriod("2000"), createPeriod("200002"), createPeriod("200003"), createPeriod("200004"))).build();
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(6).withTableType(ANALYTICS_TABLE_TYPE).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    assertEquals(6, queryGroups.getAllQueries().size());
    assertEquals(1, queryGroups.getSequentialQueries().size());
    assertEquals(6, 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 23 with DataQueryGroups

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

the class QueryPlannerTest method planQueryH.

/**
 * Splits in 4 queries on data elements, then 2 queries on organisation
 * units to satisfy optimal for a total of 8 queries.
 */
@Test
void planQueryH() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC, deD)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).withFilterPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"), createPeriod("2000Q3"), createPeriod("2000Q4"), createPeriod("2001Q1"), createPeriod("2001Q2"))).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()) {
        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 24 with DataQueryGroups

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

the class QueryPlannerTest method planQueryStartEndDateRestrictionQueryGrouperA.

/**
 * Splits in 4 queries for each period to satisfy optimal for a total of 4
 * queries, because all queries have different periods.
 */
@Test
void planQueryStartEndDateRestrictionQueryGrouperA() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB)).withOrganisationUnits(getList(ouA)).withPeriods(getList(createPeriod("200101"), createPeriod("200102"), createPeriod("200103"), createPeriod("200104"))).build();
    List<Function<DataQueryParams, List<DataQueryParams>>> queryGroupers = Lists.newArrayList();
    queryGroupers.add(q -> queryPlanner.groupByStartEndDateRestriction(q));
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableType(ANALYTICS_TABLE_TYPE).withQueryGroupers(queryGroupers).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    List<DataQueryParams> queries = queryGroups.getAllQueries();
    assertEquals(4, queries.size());
    assertEquals(1, queryGroups.getSequentialQueries().size());
    assertEquals(4, queryGroups.getLargestGroupSize());
    for (DataQueryParams query : queries) {
        assertNull(query.getStartDate());
        assertNull(query.getEndDate());
        assertNotNull(query.getStartDateRestriction());
        assertNotNull(query.getEndDateRestriction());
        assertDimensionNameNotNull(query);
        DimensionalObject periodDim = query.getDimension(PERIOD_DIM_ID);
        assertNotNull(periodDim.getDimensionName());
        assertTrue(periodDim.isFixed());
    }
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Function(java.util.function.Function) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 25 with DataQueryGroups

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

the class QueryPlannerTest method planQueryC.

/**
 * Query spans 3 organisation unit levels. Splits in 3 queries for each
 * level, then splits in 2 queries on organisation units to satisfy optimal
 * for a total of 5 queries, as there are only 5 organisation units in
 * total.
 */
@Test
void planQueryC() {
    ouB.setParent(ouA);
    ouC.setParent(ouA);
    ouD.setParent(ouB);
    ouE.setParent(ouC);
    ouA.getChildren().add(ouB);
    ouA.getChildren().add(ouC);
    ouD.getChildren().add(ouB);
    ouC.getChildren().add(ouE);
    organisationUnitService.updateOrganisationUnit(ouA);
    organisationUnitService.updateOrganisationUnit(ouB);
    organisationUnitService.updateOrganisationUnit(ouC);
    organisationUnitService.updateOrganisationUnit(ouD);
    organisationUnitService.updateOrganisationUnit(ouE);
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).withPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"), createPeriod("2000Q3"))).build();
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(6).withTableType(ANALYTICS_TABLE_TYPE).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    assertEquals(5, queryGroups.getAllQueries().size());
    assertEquals(1, queryGroups.getSequentialQueries().size());
    assertEquals(5, 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