Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.hisp.dhis.analytics.table.ColumnRegex.NUMERIC_REGEXP;
import static org.hisp.dhis.analytics.table.model.AnalyticsValueType.FACT;
import static org.hisp.dhis.analytics.table.util.PartitionUtils.getLatestTablePartition;
import static org.hisp.dhis.commons.util.TextUtils.SPACE;
import static org.hisp.dhis.commons.util.TextUtils.emptyIfTrue;
import static org.hisp.dhis.commons.util.TextUtils.format;
import static org.hisp.dhis.commons.util.TextUtils.replace;
Expand Down Expand Up @@ -413,20 +414,29 @@ where des.valuetype in (${valTypes}) \
"startTime", toLongDate(params.getStartTime()),
"deletedClause", sqlBuilder.isFalse("dv", "deleted"))));

sql.append(getStartEndDatesCondition(respectStartEndDates));

if (whereClause != null) {
sql.append(" and " + whereClause + " ");
}

invokeTimeAndLog(sql.toString(), "Populating table: '{}' {}", tableName, valueTypes);
}

String getStartEndDatesCondition(boolean respectStartEndDates) {
StringBuilder condition = new StringBuilder("");

if (respectStartEndDates) {
sql.append(
condition.append(SPACE);
condition.append(
"""
and (aon.startdate is null or aon.startdate <= ps.startdate) \
and (aon.enddate is null or aon.enddate >= ps.enddate) \
and (con.startdate is null or con.startdate <= ps.startdate) \
and (con.enddate is null or con.enddate >= ps.enddate)\s""");
}

if (whereClause != null) {
sql.append(" and " + whereClause + " ");
}

invokeTimeAndLog(sql.toString(), "Populating table: '{}' {}", tableName, valueTypes);
return condition.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,10 @@ void testGetApprovalJoinClause() {

assertEquals(expected, subject.getApprovalJoinClause());
}

@Test
void testGetStartEndDatesCondition() {
assertTrue(subject.getStartEndDatesCondition(false).isEmpty());
assertTrue(subject.getStartEndDatesCondition(true).startsWith(" "));
}
}
Loading