Search in sources :

Example 11 with DataQueryParams

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

the class QueryPlannerTest method validateSuccesA.

@Test
public void validateSuccesA() {
    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))).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deB))).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 12 with DataQueryParams

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

the class QueryPlannerTest method validateSuccesSingleIndicatorFilter.

@Test
public void validateSuccesSingleIndicatorFilter() {
    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))).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 13 with DataQueryParams

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

the class DefaultDataQueryService method getFromUrl.

// -------------------------------------------------------------------------
// DataQueryService implementation
// -------------------------------------------------------------------------
@Override
public DataQueryParams getFromUrl(Set<String> dimensionParams, Set<String> filterParams, AggregationType aggregationType, String measureCriteria, String preAggregationMeasureCriteria, Date startDate, Date endDate, boolean skipMeta, boolean skipData, boolean skipRounding, boolean completedOnly, boolean hierarchyMeta, boolean ignoreLimit, boolean hideEmptyRows, boolean hideEmptyColumns, boolean showHierarchy, boolean includeNumDen, DisplayProperty displayProperty, IdScheme outputIdScheme, IdScheme inputIdScheme, boolean duplicatesOnly, String approvalLevel, Date relativePeriodDate, String userOrgUnit, boolean allowAllPeriods, DhisApiVersion apiVersion) {
    I18nFormat format = i18nManager.getI18nFormat();
    DataQueryParams.Builder params = DataQueryParams.newBuilder();
    inputIdScheme = ObjectUtils.firstNonNull(inputIdScheme, IdScheme.UID);
    if (dimensionParams != null && !dimensionParams.isEmpty()) {
        params.addDimensions(getDimensionalObjects(dimensionParams, relativePeriodDate, userOrgUnit, format, allowAllPeriods, inputIdScheme));
    }
    if (filterParams != null && !filterParams.isEmpty()) {
        params.addFilters(getDimensionalObjects(filterParams, relativePeriodDate, userOrgUnit, format, allowAllPeriods, inputIdScheme));
    }
    if (measureCriteria != null && !measureCriteria.isEmpty()) {
        params.withMeasureCriteria(DataQueryParams.getMeasureCriteriaFromParam(measureCriteria));
    }
    if (preAggregationMeasureCriteria != null && !preAggregationMeasureCriteria.isEmpty()) {
        params.withPreAggregationMeasureCriteria(DataQueryParams.getMeasureCriteriaFromParam(preAggregationMeasureCriteria));
    }
    return params.withAggregationType(aggregationType).withStartDate(startDate).withEndDate(endDate).withSkipMeta(skipMeta).withSkipData(skipData).withSkipRounding(skipRounding).withCompletedOnly(completedOnly).withIgnoreLimit(ignoreLimit).withHierarchyMeta(hierarchyMeta).withHideEmptyRows(hideEmptyRows).withHideEmptyColumns(hideEmptyColumns).withShowHierarchy(showHierarchy).withIncludeNumDen(includeNumDen).withDisplayProperty(displayProperty).withOutputIdScheme(outputIdScheme).withOutputFormat(OutputFormat.ANALYTICS).withDuplicatesOnly(duplicatesOnly).withApprovalLevel(approvalLevel).withApiVersion(apiVersion).build();
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 14 with DataQueryParams

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

the class DefaultQueryPlanner method groupByPeriodType.

/**
     * If periods appear as dimensions in the given query; groups the query into
     * sub queries based on the period type of the periods. Sets the period type
     * name on each query. If periods appear as filters; replaces the period filter
     * with one filter for each period type. Sets the dimension names and filter
     * names respectively.
     */
@Override
public List<DataQueryParams> groupByPeriodType(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (params.isSkipPartitioning()) {
        queries.add(params);
    } else if (!params.getPeriods().isEmpty()) {
        ListMap<String, DimensionalItemObject> periodTypePeriodMap = PartitionUtils.getPeriodTypePeriodMap(params.getPeriods());
        for (String periodType : periodTypePeriodMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).addOrSetDimensionOptions(PERIOD_DIM_ID, DimensionType.PERIOD, periodType.toLowerCase(), periodTypePeriodMap.get(periodType)).withPeriodType(periodType).build();
            queries.add(query);
        }
    } else if (!params.getFilterPeriods().isEmpty()) {
        DimensionalObject filter = params.getFilter(PERIOD_DIM_ID);
        ListMap<String, DimensionalItemObject> periodTypePeriodMap = PartitionUtils.getPeriodTypePeriodMap(filter.getItems());
        DataQueryParams.Builder query = DataQueryParams.newBuilder(params).removeFilter(PERIOD_DIM_ID).withPeriodType(// Using first period type
        periodTypePeriodMap.keySet().iterator().next());
        for (String periodType : periodTypePeriodMap.keySet()) {
            query.addFilter(new BaseDimensionalObject(filter.getDimension(), filter.getDimensionType(), periodType.toLowerCase(), filter.getDisplayName(), periodTypePeriodMap.get(periodType)));
        }
        queries.add(query.build());
    } else {
        queries.add(DataQueryParams.newBuilder(params).build());
        return queries;
    }
    if (queries.size() > 1) {
        log.debug(String.format("Split on period type: %d", queries.size()));
    }
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) ListMap(org.hisp.dhis.common.ListMap) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 15 with DataQueryParams

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

the class DefaultQueryPlanner method groupByDaysInPeriod.

/**
     * Groups the given query into sub queries based on the number of days in the
     * aggregation period. This only applies if the aggregation type is
     * {@link AggregationType#AVERAGE_SUM_INT} and the query has at least one period as 
     * dimension option. This is necessary since the number of days in the aggregation 
     * period is part of the expression for aggregating the value.
     * 
     * @param params the data query parameters.
     * @return a list of {@link DataQueryParams}.
     */
private List<DataQueryParams> groupByDaysInPeriod(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (params.getPeriods().isEmpty() || !params.isAggregationType(AggregationType.AVERAGE_SUM_INT)) {
        queries.add(DataQueryParams.newBuilder(params).build());
        return queries;
    }
    ListMap<Integer, DimensionalItemObject> daysPeriodMap = QueryPlannerUtils.getDaysPeriodMap(params.getPeriods());
    DimensionalObject periodDim = params.getDimension(PERIOD_DIM_ID);
    for (Integer days : daysPeriodMap.keySet()) {
        DataQueryParams query = DataQueryParams.newBuilder(params).addOrSetDimensionOptions(periodDim.getDimension(), periodDim.getDimensionType(), periodDim.getDimensionName(), daysPeriodMap.get(days)).build();
        queries.add(query);
    }
    if (queries.size() > 1) {
        log.debug(String.format("Split on days in period: %d", queries.size()));
    }
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

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