Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove unnecessary subquery for event data value [DHIS2-18417] #19273

Merged
merged 177 commits into from
Nov 25, 2024

Conversation

larshelge
Copy link
Member

@larshelge larshelge commented Nov 24, 2024

This PR relates to event analytics table population. For pivoting event data element values to separate columns, a sub-query against the event table was used. This is unnecessary as the event table is the base table for the select statement, and the event data value can be retrieved directly using a JSON expression.

This change makes:

  • The SQL query simpler.
  • The insert into operation faster.
  • The SQL query more standard and easier to map to other analytics database engines.

As an example, to retrieve a data value for a specific data element, instead of using a subquery against the event table, the SQL will check the value type (number, date, etc) and retrieve the value directly:

case
    when eventdatavalues #>> '{GieVkTxp4HH, value}' ~* '^(-?[0-9]+)(\.[0-9]+)?$' 
    then cast(eventdatavalues #>> '{GieVkTxp4HH, value}' as double precision)
    else null
end as "GieVkTxp4HH",

@larshelge larshelge marked this pull request as ready for review November 25, 2024 10:06
@maikelarabori maikelarabori added the run-api-analytics-tests Enables analytics e2e tests label Nov 25, 2024
@larshelge larshelge merged commit cb10abb into master Nov 25, 2024
18 checks passed
@larshelge larshelge deleted the DHIS2-18417 branch November 25, 2024 11:38
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants