diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java index 46d08ddf1860..2da271bc852d 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java @@ -374,7 +374,6 @@ private void populateTable( inner join analytics_rs_dataelementgroupsetstructure degs on dv.dataelementid=degs.dataelementid \ inner join analytics_rs_orgunitstructure ous on dv.sourceid=ous.organisationunitid \ inner join analytics_rs_organisationunitgroupsetstructure ougs on dv.sourceid=ougs.organisationunitid \ - and (ps.monthstartdate=ougs.startdate or ougs.startdate is null) \ inner join analytics_rs_categorystructure dcs on dv.categoryoptioncomboid=dcs.categoryoptioncomboid \ inner join analytics_rs_categorystructure acs on dv.attributeoptioncomboid=acs.categoryoptioncomboid \ inner join analytics_rs_categoryoptioncomboname aon on dv.attributeoptioncomboid=aon.categoryoptioncomboid \ @@ -395,6 +394,7 @@ private void populateTable( where des.valuetype in (${valTypes}) \ and des.domaintype = 'AGGREGATE' \ ${partitionClause} \ + and (ougs.startdate is null or ps.monthstartdate=ougs.startdate) \ and dv.lastupdated < '${startTime}' \ and dv.value is not null \ and dv.deleted = false\s""", diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java index 6751c6246f6b..53007549aae8 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java @@ -223,17 +223,15 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti inner join ${dataset} ds on cdr.datasetid=ds.datasetid \ inner join analytics_rs_periodstructure ps on cdr.periodid=ps.periodid \ inner join analytics_rs_organisationunitgroupsetstructure ougs on cdr.sourceid=ougs.organisationunitid \ - and (cast(${peStartDateMonth} as date)=ougs.startdate or ougs.startdate is null) \ left join analytics_rs_orgunitstructure ous on cdr.sourceid=ous.organisationunitid \ inner join analytics_rs_categorystructure acs on cdr.attributeoptioncomboid=acs.categoryoptioncomboid \ inner join ${categoryoptioncombo} ao on cdr.attributeoptioncomboid=ao.categoryoptioncomboid \ where cdr.date is not null \ ${partitionClause} \ + and (ougs.startdate is null or ps.monthstartdate=ougs.startdate) \ and cdr.lastupdated < '${startTime}' \ and cdr.completed = true""", Map.of( - "peStartDateMonth", - sqlBuilder.dateTrunc("month", "ps.startdate"), "partitionClause", partitionClause, "startTime", diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java index ef78344f07ff..1cc8f201622f 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java @@ -179,12 +179,12 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti sql += qualifyVariables( """ - from analytics_rs_datasetorganisationunitcategory doc - inner join ${dataset} ds on doc.datasetid=ds.datasetid - inner join ${organisationunit} ou on doc.organisationunitid=ou.organisationunitid - left join analytics_rs_orgunitstructure ous on doc.organisationunitid=ous.organisationunitid - left join analytics_rs_organisationunitgroupsetstructure ougs on doc.organisationunitid=ougs.organisationunitid - left join ${categoryoptioncombo} ao on doc.attributeoptioncomboid=ao.categoryoptioncomboid + from analytics_rs_datasetorganisationunitcategory doc \ + inner join ${dataset} ds on doc.datasetid=ds.datasetid \ + inner join ${organisationunit} ou on doc.organisationunitid=ou.organisationunitid \ + left join analytics_rs_orgunitstructure ous on doc.organisationunitid=ous.organisationunitid \ + left join analytics_rs_organisationunitgroupsetstructure ougs on doc.organisationunitid=ougs.organisationunitid \ + left join ${categoryoptioncombo} ao on doc.attributeoptioncomboid=ao.categoryoptioncomboid \ left join analytics_rs_categorystructure acs on doc.attributeoptioncomboid=acs.categoryoptioncomboid"""); invokeTimeAndLog(sql, "Populating table: '{}'", tableName); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOrgUnitTargetTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOrgUnitTargetTableManager.java index fc08941f3253..2f9a37940ec2 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOrgUnitTargetTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOrgUnitTargetTableManager.java @@ -154,9 +154,9 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti sql += qualifyVariables( """ - from ${orgunitgroupmembers} ougm - inner join ${orgunitgroup} oug on ougm.orgunitgroupid=oug.orgunitgroupid - left join analytics_rs_orgunitstructure ous on ougm.organisationunitid=ous.organisationunitid + from ${orgunitgroupmembers} ougm \ + inner join ${orgunitgroup} oug on ougm.orgunitgroupid=oug.orgunitgroupid \ + left join analytics_rs_orgunitstructure ous on ougm.organisationunitid=ous.organisationunitid \ left join analytics_rs_organisationunitgroupsetstructure ougs on ougm.organisationunitid=ougs.organisationunitid"""); invokeTimeAndLog(sql, "Populating table: '{}'", tableName); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcValidationResultTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcValidationResultTableManager.java index 5c2f21565f86..d8f4ddae85db 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcValidationResultTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcValidationResultTableManager.java @@ -188,15 +188,15 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti sql += replaceQualify( """ - from ${validationresult} vrs - inner join analytics_rs_periodstructure ps on vrs.periodid=ps.periodid - inner join ${validationrule} vr on vr.validationruleid=vrs.validationruleid - inner join analytics_rs_organisationunitgroupsetstructure ougs on vrs.organisationunitid=ougs.organisationunitid - and (cast(${peStartDateMonth} as date)=ougs.startdate or ougs.startdate is null) - left join analytics_rs_orgunitstructure ous on vrs.organisationunitid=ous.organisationunitid - inner join analytics_rs_categorystructure acs on vrs.attributeoptioncomboid=acs.categoryoptioncomboid - where vrs.created < '${startTime}' - and vrs.created is not null ${partitionClause}""", + from ${validationresult} vrs \ + inner join analytics_rs_periodstructure ps on vrs.periodid=ps.periodid \ + inner join ${validationrule} vr on vr.validationruleid=vrs.validationruleid \ + inner join analytics_rs_organisationunitgroupsetstructure ougs on vrs.organisationunitid=ougs.organisationunitid \ + left join analytics_rs_orgunitstructure ous on vrs.organisationunitid=ous.organisationunitid \ + inner join analytics_rs_categorystructure acs on vrs.attributeoptioncomboid=acs.categoryoptioncomboid \ + where vrs.created < '${startTime}' \ + and vrs.created is not null ${partitionClause} \ + and (ougs.startdate is null or ps.monthstartdate=ougs.startdate)""", Map.of( "peStartDateMonth", sqlBuilder.dateTrunc("month", "ps.startdate"), "startTime", toLongDate(params.getStartTime()), @@ -215,10 +215,10 @@ private List getDataYears(AnalyticsTableUpdateParams params) { String sql = replaceQualify( """ - select distinct(extract(year from ps.startdate)) - from ${validationresult} vrs - inner join analytics_rs_periodstructure ps on vrs.periodid=ps.periodid - where ps.startdate is not null + select distinct(extract(year from ps.startdate)) \ + from ${validationresult} vrs \ + inner join analytics_rs_periodstructure ps on vrs.periodid=ps.periodid \ + where ps.startdate is not null \ and vrs.created < '${startTime}' ${fromDateClause}""", Map.of( diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/init/AnalyticsDatabaseInit.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/init/AnalyticsDatabaseInit.java index 23c1485a8c8a..26dea065787c 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/init/AnalyticsDatabaseInit.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/init/AnalyticsDatabaseInit.java @@ -94,8 +94,8 @@ private void initDoris() { } /** - * Creates a JDBC catalog which is used to connect to and read from the PostgreSQL transaction - * database as an external data source. + * Creates a Doris JDBC catalog which is used to connect to and read from the PostgreSQL + * transaction database as an external data source. */ private void createDorisJdbcCatalog() { String connectionUrl = config.getProperty(ConfigurationKey.CONNECTION_URL);