Search in sources :

Example 6 with Partitions

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

the class EventQueryPlannerTest method testPlanAggregateQueryA.

@Test
public void testPlanAggregateQueryA() {
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 6, 1, 0, 0).toDate()).withEndDate(new DateTime(2012, 3, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouA)).build();
    List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
    assertEquals(1, queries.size());
    EventQueryParams query = queries.get(0);
    assertEquals(new DateTime(2010, 6, 1, 0, 0).toDate(), query.getStartDate());
    assertEquals(new DateTime(2012, 3, 20, 0, 0).toDate(), query.getEndDate());
    Partitions partitions = query.getPartitions();
    assertEquals(3, partitions.getPartitions().size());
    assertEquals("analytics_event_2010_programuida", partitions.getPartitions().get(0));
    assertEquals("analytics_event_2011_programuida", partitions.getPartitions().get(1));
    assertEquals("analytics_event_2012_programuida", partitions.getPartitions().get(2));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) Partitions(org.hisp.dhis.analytics.Partitions) DateTime(org.joda.time.DateTime) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with Partitions

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

the class PartitionUtils method getPartitions.

public static Partitions getPartitions(Period period, String tablePrefix, String tableSuffix, Set<String> validPartitions) {
    tablePrefix = StringUtils.trimToEmpty(tablePrefix);
    tableSuffix = StringUtils.trimToEmpty(tableSuffix);
    Partitions partitions = new Partitions();
    int startYear = PeriodType.getCalendar().fromIso(period.getStartDate()).getYear();
    int endYear = PeriodType.getCalendar().fromIso(period.getEndDate()).getYear();
    while (startYear <= endYear) {
        String name = tablePrefix + SEP + startYear + tableSuffix;
        partitions.add(name.toLowerCase());
        startYear++;
    }
    return partitions.prunePartitions(validPartitions);
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions)

Example 8 with Partitions

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

the class DefaultQueryPlanner method groupByPartition.

// -------------------------------------------------------------------------
// Supportive - group by methods
// -------------------------------------------------------------------------
@Override
public List<DataQueryParams> groupByPartition(DataQueryParams params, QueryPlannerParams plannerParams) {
    Set<String> validPartitions = partitionManager.getDataValueAnalyticsPartitions();
    String tableName = plannerParams.getTableName();
    String tableSuffix = plannerParams.getTableSuffix();
    List<DataQueryParams> queries = new ArrayList<>();
    if (params.isSkipPartitioning()) {
        DataQueryParams query = DataQueryParams.newBuilder(params).withPartitions(new Partitions().add(tableName)).build();
        queries.add(query);
    } else if (!params.getPeriods().isEmpty()) {
        ListMap<Partitions, DimensionalItemObject> partitionPeriodMap = PartitionUtils.getPartitionPeriodMap(params.getPeriods(), tableName, tableSuffix, validPartitions);
        for (Partitions partitions : partitionPeriodMap.keySet()) {
            if (partitions.hasAny()) {
                DataQueryParams query = DataQueryParams.newBuilder(params).withPeriods(partitionPeriodMap.get(partitions)).withPartitions(partitions).build();
                queries.add(query);
            }
        }
    } else if (!params.getFilterPeriods().isEmpty()) {
        Partitions partitions = PartitionUtils.getPartitions(params.getFilterPeriods(), tableName, tableSuffix, validPartitions);
        if (partitions.hasAny()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).withPartitions(partitions).build();
            queries.add(query);
        }
    } else if (params.hasStartEndDate()) {
        Partitions partitions = PartitionUtils.getPartitions(params.getStartDate(), params.getEndDate(), tableName, tableSuffix, validPartitions);
        if (partitions.hasAny()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).withPartitions(partitions).build();
            queries.add(query);
        }
    } else {
        throw new IllegalQueryException("Query does not contain any period dimension items");
    }
    if (queries.size() > 1) {
        log.debug(String.format("Split on partition: %d", queries.size()));
    }
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Partitions(org.hisp.dhis.analytics.Partitions) ArrayList(java.util.ArrayList) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ListMap(org.hisp.dhis.common.ListMap)

Example 9 with Partitions

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

the class EventQueryParams method instance.

@Override
protected EventQueryParams instance() {
    EventQueryParams params = new EventQueryParams();
    params.dimensions = new ArrayList<>(this.dimensions);
    params.filters = new ArrayList<>(this.filters);
    params.includeNumDen = this.includeNumDen;
    params.displayProperty = this.displayProperty;
    params.aggregationType = this.aggregationType;
    params.skipRounding = this.skipRounding;
    params.startDate = this.startDate;
    params.endDate = this.endDate;
    params.apiVersion = this.apiVersion;
    params.partitions = new Partitions(this.partitions);
    params.periodType = this.periodType;
    params.program = this.program;
    params.programStage = this.programStage;
    params.items = new ArrayList<>(this.items);
    params.itemFilters = new ArrayList<>(this.itemFilters);
    params.value = this.value;
    params.itemProgramIndicators = new ArrayList<>(this.itemProgramIndicators);
    params.programIndicator = this.programIndicator;
    params.asc = new ArrayList<>(this.asc);
    params.desc = new ArrayList<>(this.desc);
    params.completedOnly = this.completedOnly;
    params.organisationUnitMode = this.organisationUnitMode;
    params.page = this.page;
    params.pageSize = this.pageSize;
    params.sortOrder = this.sortOrder;
    params.limit = this.limit;
    params.outputType = this.outputType;
    params.eventStatus = this.eventStatus;
    params.collapseDataDimensions = this.collapseDataDimensions;
    params.coordinatesOnly = this.coordinatesOnly;
    params.geometryOnly = this.geometryOnly;
    params.aggregateData = this.aggregateData;
    params.clusterSize = this.clusterSize;
    params.coordinateField = this.coordinateField;
    params.bbox = this.bbox;
    params.includeClusterPoints = this.includeClusterPoints;
    params.programStatus = this.programStatus;
    params.periodType = this.periodType;
    return params;
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions)

Example 10 with Partitions

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

the class PartitionUtilsTest method getGetPartitionsMultiplePeriods.

@Test
public void getGetPartitionsMultiplePeriods() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(createPeriod("200011"));
    periods.add(createPeriod("200105"));
    periods.add(createPeriod("200108"));
    assertEquals(new Partitions().add(TBL + "_2000").add(TBL + "_2001"), PartitionUtils.getPartitions(periods, TBL, null, null));
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Partitions (org.hisp.dhis.analytics.Partitions)15 Test (org.junit.Test)11 DateTime (org.joda.time.DateTime)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)4 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 DhisConvenienceTest.createPeriod (org.hisp.dhis.DhisConvenienceTest.createPeriod)2 Period (org.hisp.dhis.period.Period)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)1 ListMap (org.hisp.dhis.common.ListMap)1