Search in sources :

Example 6 with DataQueryParams

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

the class QueryPlannerTest method planQueryF.

/**
     * Splits on 3 queries on organisation units for an optimal of 3 queries. No
     * data elements specified.
     */
@Test
public void planQueryF() {
    DataQueryParams params = DataQueryParams.newBuilder().withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).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).withTableName(ANALYTICS_TABLE_NAME).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    assertEquals(3, queryGroups.getAllQueries().size());
    assertEquals(1, queryGroups.getSequentialQueries().size());
    assertEquals(3, queryGroups.getLargestGroupSize());
    for (DataQueryParams query : queryGroups.getAllQueries()) {
        assertTrue(samePeriodType(query.getPeriods()));
        assertTrue(samePartition(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.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with DataQueryParams

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

the class QueryPlannerTest method planQueryStartEndDateQueryGrouperB.

/**
     * Splits in 4 queries for each period to satisfy optimal for a total
     * of 4 queries, because all queries have different periods.
     */
@Test
public void planQueryStartEndDateQueryGrouperB() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB)).withOrganisationUnits(getList(ouA)).withFilterPeriods(getList(createPeriod("200101"), createPeriod("200102"), createPeriod("200103"), createPeriod("200104"))).build();
    List<Function<DataQueryParams, List<DataQueryParams>>> queryGroupers = Lists.newArrayList();
    queryGroupers.add(q -> queryPlanner.groupByStartEndDate(q));
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableName(ANALYTICS_TABLE_NAME).withQueryGroupers(queryGroupers).build();
    DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
    List<DataQueryParams> queries = queryGroups.getAllQueries();
    assertEquals(2, queries.size());
    assertEquals(1, queryGroups.getSequentialQueries().size());
    assertEquals(2, queryGroups.getLargestGroupSize());
    for (DataQueryParams query : queries) {
        assertNotNull(query.getStartDate());
        assertNotNull(query.getEndDate());
        assertDimensionNameNotNull(query);
        assertNull(query.getFilter(PERIOD_DIM_ID));
    }
}
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) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with DataQueryParams

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

the class QueryPlannerTest method planQueryM.

/**
     * Query spans 1 partition. Splits on 2 queries for data types, then splits
     * on 2 queries for data elements to satisfy optimal for a total of 4 queries.
     */
@Test
public 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).withTableName(ANALYTICS_TABLE_NAME).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()));
        assertTrue(samePartition(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.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 9 with DataQueryParams

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

the class QueryPlannerTest method validateFailureMultipleIndicatorsFilter.

@Test(expected = IllegalQueryException.class)
public void validateFailureMultipleIndicatorsFilter() {
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).addFilter(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(inA, inB))).build();
    queryPlanner.validate(params);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 10 with DataQueryParams

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

the class QueryPlannerTest method planQueryK.

/**
     * Query spans 2 partitions. Splits in 2 queries for each partition, then
     * splits in 2 queries on data sets to satisfy optimal for a total
     * of 4 queries.
     */
@Test
public void planQueryK() {
    DataQueryParams params = DataQueryParams.newBuilder().withReportingRates(getList(rrA, rrB, rrC, rrD)).withOrganisationUnits(getList(ouA, ouB, ouC, ouD, ouE)).withPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"), createPeriod("2000Q3"), createPeriod("2000Q4"), createPeriod("2001Q1"), createPeriod("2001Q2"))).build();
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).withTableName(ANALYTICS_TABLE_NAME).build();
    List<DataQueryParams> queries = queryPlanner.planQuery(params, plannerParams).getAllQueries();
    assertEquals(4, queries.size());
    for (DataQueryParams query : queries) {
        assertTrue(samePeriodType(query.getPeriods()));
        assertTrue(samePartition(query.getPeriods()));
        assertDimensionNameNotNull(query);
    }
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)81 Test (org.junit.Test)52 DhisSpringTest (org.hisp.dhis.DhisSpringTest)51 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)24 QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)22 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)19 DataQueryGroups (org.hisp.dhis.analytics.DataQueryGroups)17 ArrayList (java.util.ArrayList)16 DimensionalObject (org.hisp.dhis.common.DimensionalObject)15 HashSet (java.util.HashSet)14 LinkedHashSet (java.util.LinkedHashSet)13 HashMap (java.util.HashMap)7 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 List (java.util.List)6 Map (java.util.Map)6 OrganisationUnit.getParentGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap)6 OrganisationUnit.getParentNameGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap)6 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)5 Grid (org.hisp.dhis.common.Grid)5