Skip to content

Commit

Permalink
refactor: Move table join condition to where clause [DHIS2-16705] (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge authored Nov 18, 2024
1 parent 3f41841 commit 2d25cab
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -215,10 +215,10 @@ private List<Integer> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2d25cab

Please sign in to comment.