Skip to content

fix: aggregate enrollment stage CTE projection#23868

Merged
luciano-fiandesio merged 3 commits into
masterfrom
DHIS2-21478_ENR_AGGR_DIMENSIONS_NO_FILTER
May 12, 2026
Merged

fix: aggregate enrollment stage CTE projection#23868
luciano-fiandesio merged 3 commits into
masterfrom
DHIS2-21478_ENR_AGGR_DIMENSIONS_NO_FILTER

Conversation

@luciano-fiandesio

Copy link
Copy Markdown
Contributor

Summary

When requesting an aggregated enrollment analytics query that combines a stage-specific dimension without a filter with other stage-specific dimensions that do have filters, the generated SQL was invalid.

Example:

API request (against /api/analytics/enrollments/aggregate/<programUid>):

dimension=A03MvHHogjR.EVENT_STATUS
dimension=A03MvHHogjR.EVENT_DATE:LAST_12_MONTHS
dimension=A03MvHHogjR.ou:USER_ORGUNIT

Postgres response:

SQL Error [42703]: ERROR: column uiogg.ev_eventstatus does not exist

The outer SELECT referenced uiogg.ev_eventstatus (where uiogg aliased the latest_events_A03MvHHogjR CTE), but that CTE did not project ev_eventstatus.

Fix

Make the per-stage filter CTE the "single source of truth" for every stage dimension requested in that stage's scope.
The aggregate branch no longer pre-filters items by hasFilter(). Instead it groups every stage item from both params.getItems() and params.getItemFilters() by program stage UID, then emits a latest_events_<stage> CTE only when at least
one item for that stage carries a filter.
Unfiltered stage items belonging to a stage that does have a filter get projected into the same CTE, sharing the "latest event matching the filter" row.

@luciano-fiandesio luciano-fiandesio added run-api-analytics-tests Enables analytics e2e tests run-api-analytics-tests-doris Enables analytics e2e tests on Doris labels May 11, 2026
@github-actions

Copy link
Copy Markdown

Surefire reports for analytics API tests against Doris have been pushed to the repository. View reports

2 similar comments
@github-actions

Copy link
Copy Markdown

Surefire reports for analytics API tests against Doris have been pushed to the repository. View reports

@github-actions

Copy link
Copy Markdown

Surefire reports for analytics API tests against Doris have been pushed to the repository. View reports

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Surefire reports for analytics API tests against Doris have been pushed to the repository. View reports

@luciano-fiandesio
luciano-fiandesio enabled auto-merge (squash) May 12, 2026 15:33
@luciano-fiandesio
luciano-fiandesio merged commit 33cc1d7 into master May 12, 2026
18 checks passed
@luciano-fiandesio
luciano-fiandesio deleted the DHIS2-21478_ENR_AGGR_DIMENSIONS_NO_FILTER branch May 12, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-api-analytics-tests Enables analytics e2e tests run-api-analytics-tests-doris Enables analytics e2e tests on Doris

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants