Search in sources :

Example 21 with QueryPlannerParams

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

the class DataHandler method addRawData.

/**
 * Adds raw data to the grid for the given data query parameters.
 *
 * @param params the {@link DataQueryParams}.
 * @param grid the grid.
 */
void addRawData(DataQueryParams params, Grid grid) {
    if (!params.isSkipData()) {
        QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withTableType(DATA_VALUE).build();
        params = queryPlanner.withTableNameAndPartitions(params, plannerParams);
        rawAnalyticsManager.getRawDataValues(params, grid);
    }
}
Also used : QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams)

Example 22 with QueryPlannerParams

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

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

the class QueryPlannerTest method planQueryI.

/**
 * Query spans 3 period types. Splits in 3 queries for each period type,
 * then splits in 2 queries on data type, then splits in 2 queries on data
 * elements to satisfy optimal for a total of 12 queries, because query has
 * 2 different aggregation types.
 */
@Test
void planQueryI() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deE, deF)).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(12, queryGroups.getAllQueries().size());
    assertEquals(2, 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 24 with QueryPlannerParams

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

the class QueryPlannerTest method planQueryN.

/**
 * Query spans 5 QueryModifiers minDate/MaxDate combinations.
 */
@Test
void planQueryN() {
    QueryModifiers modsA = QueryModifiers.builder().minDate(parseDate("2022-01-01")).build();
    QueryModifiers modsB = QueryModifiers.builder().minDate(parseDate("2022-02-01")).build();
    QueryModifiers modsC = QueryModifiers.builder().maxDate(parseDate("2022-12-31")).build();
    QueryModifiers modsD = QueryModifiers.builder().minDate(parseDate("2022-01-01")).maxDate(parseDate("2022-12-31")).build();
    deC.setQueryMods(modsA);
    deD.setQueryMods(modsB);
    deG.setQueryMods(modsC);
    deH.setQueryMods(modsD);
    deI.setQueryMods(modsD);
    deC.setAggregationType(AggregationType.SUM);
    deD.setAggregationType(AggregationType.SUM);
    deI.setAggregationType(AggregationType.SUM);
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB, deC, deD, deG, deH, deI)).withPeriods(getList(createPeriod("2022"))).build();
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(4).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());
    List<DataQueryParams> group = queryGroups.getAllQueries();
    assertQueryMods(group, null, deA, deB);
    assertQueryMods(group, modsA, deC);
    assertQueryMods(group, modsB, deD);
    assertQueryMods(group, modsC, deG);
    assertQueryMods(group, modsD, deH, deI);
}
Also used : QueryModifiers(org.hisp.dhis.common.QueryModifiers) 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 25 with QueryPlannerParams

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

the class QueryPlannerTest method testWithTableTypeAndPartition.

@Test
void testWithTableTypeAndPartition() {
    DataQueryParams params = DataQueryParams.newBuilder().withStartDate(getDate(2014, 4, 1)).withEndDate(getDate(2016, 8, 1)).build();
    assertTrue(params.hasStartEndDate());
    QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withTableType(ANALYTICS_TABLE_TYPE).build();
    DataQueryParams query = queryPlanner.withTableNameAndPartitions(params, plannerParams);
    Partitions partitions = query.getPartitions();
    Partitions expected = new Partitions(Sets.newHashSet(0, 2014, 2015, 2016));
    assertNotNull(partitions);
    assertEquals(4, partitions.getPartitions().size());
    assertEquals(expected, partitions);
    assertEquals(ANALYTICS_TABLE_TYPE.getTableName(), query.getTableName());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Partitions(org.hisp.dhis.analytics.Partitions) 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