Search in sources :

Example 1 with QueryModifiers

use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.

the class DefaultQueryPlanner method groupByMinMaxDate.

/**
 * Groups queries by their minDate/MaxDate query modifiers.
 *
 * @param params the {@link DataQueryParams}.
 * @return a list of {@link DataQueryParams}.
 */
private List<DataQueryParams> groupByMinMaxDate(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (!params.getDataElements().isEmpty()) {
        ListMap<QueryModifiers, DimensionalItemObject> minMaxDateDateElementMap = QueryPlannerUtils.getMinMaxDateDateElementMap(params.getDataElements());
        for (QueryModifiers queryMods : minMaxDateDateElementMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).withDataElements(minMaxDateDateElementMap.get(queryMods)).withStartDate(getLatest(params.getStartDate(), queryMods.getMinDate())).withEndDate(getEarliest(params.getEndDate(), queryMods.getMaxDate())).build();
            queries.add(query);
        }
    } else {
        queries.add(params);
    }
    logQuerySplit(queries, "minDate/maxDate query modifiers");
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) QueryModifiers(org.hisp.dhis.common.QueryModifiers) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList)

Example 2 with QueryModifiers

use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.

the class QueryPlannerTest method assertQueryMods.

private void assertQueryMods(List<DataQueryParams> group, QueryModifiers mods, DataElement... elements) {
    List<DataElement> modElements = Arrays.asList(elements);
    for (DataQueryParams params : group) {
        List<DimensionalItemObject> groupElements = params.getDataElements();
        assertNotEquals(0, groupElements.size());
        QueryModifiers groupMods = groupElements.get(0).getQueryMods();
        if (Objects.equals(mods, groupMods)) {
            assertTrue(Objects.equals(params.getStartDate(), mods == null ? null : mods.getMinDate()));
            assertTrue(Objects.equals(params.getEndDate(), mods == null ? null : mods.getMaxDate()));
            assertEquals(modElements.size(), groupElements.size());
            assertTrue(groupElements.containsAll(modElements));
            groupElements.forEach(e -> {
                assertEquals(mods, e.getQueryMods());
            });
            return;
        }
    }
    throw new RuntimeException("No group found for queryMods " + mods);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) QueryModifiers(org.hisp.dhis.common.QueryModifiers) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject)

Example 3 with QueryModifiers

use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.

the class FunctionMaxDate method evaluate.

@Override
public Object evaluate(ExprContext ctx, CommonExpressionVisitor visitor) {
    Date maxDate = parseExpressionDate(ctx.maxDate.getText());
    QueryModifiers queryMods = visitor.getState().getQueryModsBuilder().maxDate(maxDate).build();
    return visitor.visitWithQueryMods(ctx.expr(0), queryMods);
}
Also used : QueryModifiers(org.hisp.dhis.common.QueryModifiers) Date(java.util.Date) ParserUtils.parseExpressionDate(org.hisp.dhis.parser.expression.ParserUtils.parseExpressionDate)

Example 4 with QueryModifiers

use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.

the class PeriodOffset method evaluate.

@Override
public Object evaluate(ExprContext ctx, CommonExpressionVisitor visitor) {
    ExpressionState state = visitor.getState();
    int existingPeriodOffset = (state.getQueryMods() == null) ? 0 : state.getQueryMods().getPeriodOffset();
    int parsedPeriodOffset = (ctx.period == null) ? 0 : firstNonNull(parseInt(ctx.period.getText()), 0);
    int periodOffset = existingPeriodOffset + parsedPeriodOffset;
    QueryModifiers queryMods = state.getQueryModsBuilder().periodOffset(periodOffset).build();
    return visitor.visitWithQueryMods(ctx.expr(0), queryMods);
}
Also used : QueryModifiers(org.hisp.dhis.common.QueryModifiers) ExpressionState(org.hisp.dhis.parser.expression.ExpressionState)

Example 5 with QueryModifiers

use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.

the class FunctionMinDate method evaluate.

@Override
public Object evaluate(ExprContext ctx, CommonExpressionVisitor visitor) {
    Date minDate = parseExpressionDate(ctx.minDate.getText());
    QueryModifiers queryMods = visitor.getState().getQueryModsBuilder().minDate(minDate).build();
    return visitor.visitWithQueryMods(ctx.expr(0), queryMods);
}
Also used : QueryModifiers(org.hisp.dhis.common.QueryModifiers) Date(java.util.Date) ParserUtils.parseExpressionDate(org.hisp.dhis.parser.expression.ParserUtils.parseExpressionDate)

Aggregations

QueryModifiers (org.hisp.dhis.common.QueryModifiers)10 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)3 Date (java.util.Date)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 ParserUtils.parseExpressionDate (org.hisp.dhis.parser.expression.ParserUtils.parseExpressionDate)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 AggregationType (org.hisp.dhis.analytics.AggregationType)1 DataQueryGroups (org.hisp.dhis.analytics.DataQueryGroups)1 QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)1 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)1 ListMap (org.hisp.dhis.common.ListMap)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 ExpressionState (org.hisp.dhis.parser.expression.ExpressionState)1