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

refactor: Use util method for SQL generation [DHIS2-16705] #19441

Merged
merged 140 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
5fdf098
fix: Update code
larshelge Nov 25, 2024
12f1f27
fix: Update code
larshelge Nov 25, 2024
6647eac
fix: Update code
larshelge Nov 25, 2024
50825c4
fix: Update code
larshelge Nov 25, 2024
719655c
fix: Update code
larshelge Nov 25, 2024
c5863b1
fix: Update code
larshelge Nov 25, 2024
d2095b9
fix: Update code
larshelge Nov 25, 2024
18b9782
fix: Update code
larshelge Nov 25, 2024
d1520e3
fix: Update code
larshelge Nov 25, 2024
6c0b5a6
fix: Update code
larshelge Nov 25, 2024
7d42bb0
fix: Update code
larshelge Nov 25, 2024
1ebed16
Merge branch 'master' into DHIS2-18417
larshelge Nov 25, 2024
cb3d523
fix: Update code
larshelge Nov 26, 2024
9f369e4
fix: Update code
larshelge Nov 26, 2024
acccd5d
fix: Update code
larshelge Nov 26, 2024
97b6697
fix: Update code
larshelge Nov 26, 2024
7c725c7
fix: Update code
larshelge Nov 26, 2024
e58f104
Merge branch 'master' into DHIS2-18417
larshelge Nov 26, 2024
e8e862a
Merge branch 'master' into DHIS2-18417
larshelge Nov 26, 2024
490ea09
fix: Update code
larshelge Nov 26, 2024
781d2e4
fix: Update code
larshelge Nov 26, 2024
c1b20d7
fix: Update code
larshelge Nov 26, 2024
c51fb14
fix: Update code
larshelge Nov 26, 2024
a84ff58
fix: Update code
larshelge Nov 26, 2024
e375211
fix: Update code
larshelge Nov 26, 2024
ccbc1e4
Merge branch 'master' into DHIS2-18417
larshelge Nov 26, 2024
43ff102
fix: Update code
larshelge Nov 26, 2024
2cab8fc
fix: Update code
larshelge Nov 26, 2024
adc1599
fix: Update code
larshelge Nov 26, 2024
d013060
Merge branch 'master' into DHIS2-18417
larshelge Nov 26, 2024
793b9fa
fix: Update code
larshelge Nov 26, 2024
105b514
fix: Update code
larshelge Nov 26, 2024
45d734e
fix: Update code
larshelge Nov 26, 2024
793a55b
fix: Update code
larshelge Nov 26, 2024
0640b81
fix: Update code
larshelge Nov 26, 2024
f33bd88
fix: Update code
larshelge Nov 26, 2024
3a6b574
fix: Update code
larshelge Nov 26, 2024
7ac31de
fix: Update code
larshelge Nov 26, 2024
cd9c2ed
fix: Update code
larshelge Nov 26, 2024
e4c070d
fix: Update code
larshelge Nov 26, 2024
9cf4321
fix: Update code
larshelge Nov 26, 2024
df69357
fix: Update code
larshelge Nov 26, 2024
007fabb
fix: Update code
larshelge Nov 29, 2024
8af5d48
Revert "fix: Update code"
larshelge Nov 29, 2024
62627f0
Merge branch 'master' into DHIS2-18417
larshelge Nov 29, 2024
b3b0391
Merge branch 'master' into DHIS2-18417
larshelge Nov 29, 2024
77f814b
Merge branch 'master' into DHIS2-18417
larshelge Nov 30, 2024
4038b0d
fix: Update code
larshelge Nov 30, 2024
b48b83c
fix: Update code
larshelge Dec 1, 2024
f9ed2a3
fix: Update code
larshelge Dec 1, 2024
9a3afb8
fix: Update code
larshelge Dec 1, 2024
92be248
fix: Update code
larshelge Dec 1, 2024
8186edc
fix: Update code
larshelge Dec 1, 2024
31524ca
fix: Update code
larshelge Dec 1, 2024
04965f3
Merge branch 'master' into DHIS2-18417
larshelge Dec 2, 2024
4742e3b
fix: Update code
larshelge Dec 2, 2024
4259834
fix: Update code
larshelge Dec 2, 2024
25f4feb
fix: Update code
larshelge Dec 2, 2024
df215ec
fix: Update code
larshelge Dec 2, 2024
83b4758
fix: Update code
larshelge Dec 2, 2024
7a481d6
fix: Update code
larshelge Dec 2, 2024
bca8df5
fix: Update code
larshelge Dec 2, 2024
fdc5578
fix: Update code
larshelge Dec 2, 2024
13fbc75
fix: Update code
larshelge Dec 3, 2024
50da70c
Merge branch 'master' into DHIS2-18417
larshelge Dec 3, 2024
6633861
Revert "feat: skipAnalytics and ConfidentialFlag only for QUERY Analy…
larshelge Dec 4, 2024
693ac89
fix: Update code
larshelge Dec 4, 2024
b1e7bb3
Merge branch 'master' into DHIS2-18417
larshelge Dec 4, 2024
7b310eb
fix: Update code
larshelge Dec 4, 2024
be271e6
fix: Update code
larshelge Dec 4, 2024
e178384
fix: Update code
larshelge Dec 4, 2024
d3c1957
fix: Update code
larshelge Dec 4, 2024
55d8a84
fix: Update code
larshelge Dec 4, 2024
86ef201
fix: Update code
larshelge Dec 4, 2024
f4e7684
fix: Update code
larshelge Dec 4, 2024
a032072
fix: Update code
larshelge Dec 4, 2024
87a0fd3
fix: Update code
larshelge Dec 4, 2024
c93f4ff
fix: Update code
larshelge Dec 4, 2024
8d9b40f
fix: Update code
larshelge Dec 4, 2024
00536ff
fix: Update code
larshelge Dec 4, 2024
15cb92a
fix: Update code
larshelge Dec 4, 2024
85c2c92
fix: Update code
larshelge Dec 4, 2024
cd2cb15
Merge branch 'master' into DHIS2-18417
larshelge Dec 4, 2024
bec3c7e
fix: Update code
larshelge Dec 4, 2024
f66b2be
fix: Update code
larshelge Dec 4, 2024
7b92571
fix: Update code
larshelge Dec 4, 2024
b400d6b
fix: Update code
larshelge Dec 4, 2024
f55b900
fix: Update code
larshelge Dec 4, 2024
fb8c59f
fix: Update code
larshelge Dec 4, 2024
b4f34ba
fix: Update code
larshelge Dec 4, 2024
50d99c6
Merge branch 'master' into DHIS2-18417
larshelge Dec 4, 2024
ddb1161
fix: Update code
larshelge Dec 4, 2024
251e246
fix: Update code
larshelge Dec 4, 2024
d6c9f0e
fix: Update code
larshelge Dec 4, 2024
4bd41ca
fix: Update code
larshelge Dec 4, 2024
427ffbb
fix: Update code
larshelge Dec 4, 2024
b0f0751
fix: Update code
larshelge Dec 4, 2024
cce6d85
fix: Update code
larshelge Dec 4, 2024
63484bd
fix: Update code
larshelge Dec 4, 2024
c083771
Merge branch 'master' into DHIS2-18417
larshelge Dec 4, 2024
1064844
fix: Update code
larshelge Dec 4, 2024
67ef7db
fix: Update code
larshelge Dec 4, 2024
a4084c5
fix: Update code
larshelge Dec 4, 2024
1ed29a4
fix: Update code
larshelge Dec 4, 2024
ee94d65
fix: Update code
larshelge Dec 4, 2024
7918f3f
fix: Update code
larshelge Dec 4, 2024
000cc5d
fix: Update code
larshelge Dec 4, 2024
8caf620
fix: Update code
larshelge Dec 4, 2024
aeca0bd
fix: Update code
larshelge Dec 4, 2024
e0f0b7e
Merge branch 'master' into DHIS2-18417
larshelge Dec 5, 2024
75f1e63
fix: Update code
larshelge Dec 5, 2024
c3597a6
fix: Update strings
larshelge Dec 6, 2024
bec56ad
fix: Update code
larshelge Dec 10, 2024
c4b6775
fix: Update code
larshelge Dec 10, 2024
92aaf49
Merge branch 'master' into DHIS2-18417
larshelge Dec 10, 2024
4be3059
Merge branch 'master' into DHIS2-18417
larshelge Dec 10, 2024
2bec9de
fix: Update code
larshelge Dec 10, 2024
b76b930
fix: Update code
larshelge Dec 10, 2024
70fbb1f
fix: Update code
larshelge Dec 10, 2024
9c4143c
fix: Update code
larshelge Dec 10, 2024
8747d39
fix: Update code
larshelge Dec 10, 2024
311bb4f
fix: Update code
larshelge Dec 10, 2024
62eb664
fix: Update code
larshelge Dec 10, 2024
6a4c3b1
fix: Update code
larshelge Dec 10, 2024
f51f4c3
fix: Update code
larshelge Dec 10, 2024
7f9e59d
fix: Update code
larshelge Dec 10, 2024
fd72ecc
fix: Update code
larshelge Dec 10, 2024
c92d33f
Merge branch 'master' into DHIS2-18417
larshelge Dec 10, 2024
a0257a3
fix: Update code
larshelge Dec 11, 2024
5ef9f34
fix: Update code
larshelge Dec 11, 2024
536a950
fix: Update code
larshelge Dec 11, 2024
dcc9206
fix: Update code
larshelge Dec 11, 2024
9f61495
Merge branch 'master' into DHIS2-18417
larshelge Dec 11, 2024
394f2ba
fix: Update code
larshelge Dec 11, 2024
324f8e9
fix: Update code
larshelge Dec 11, 2024
c9ca1f2
fix: Update code
larshelge Dec 11, 2024
9ee1cb6
fix: Update code
larshelge Dec 11, 2024
39c08cf
fix: Update code
larshelge Dec 11, 2024
318e862
fix: Update code
larshelge Dec 11, 2024
0cfacb1
fix: Update code
larshelge Dec 11, 2024
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 @@ -340,38 +340,33 @@ private void populateTable(
StringBuilder sql =
new StringBuilder(replace("insert into ${tableName} (", Map.of("tableName", tableName)));

List<AnalyticsTableColumn> dimensions = partition.getMasterTable().getDimensionColumns();
List<AnalyticsTableColumn> columns = partition.getMasterTable().getAnalyticsTableColumns();
List<AnalyticsTableColumn> dimensions = partition.getMasterTable().getDimensionColumns();

for (AnalyticsTableColumn col : columns) {
sql.append(quote(col.getName()) + ",");
}

sql = TextUtils.removeLastComma(sql).append(") select ");

for (AnalyticsTableColumn col : dimensions) {
sql.append(col.getSelectExpression() + ",");
}
sql.append(toCommaSeparated(columns, col -> quote(col.getName())));
sql.append(") select ");
sql.append(toCommaSeparated(dimensions, AnalyticsTableColumn::getSelectExpression));
sql.append(",");

sql.append(
replaceQualify(
"""
${approvalSelectExpression} \
as approvallevel, \
${valueExpression} * ps.daysno as daysxvalue, \
ps.daysno as daysno, \
${valueExpression} as value, \
${textValueExpression} as textvalue \
from ${datavalue} dv \
inner join analytics_rs_periodstructure ps on dv.periodid=ps.periodid \
inner join analytics_rs_dataelementstructure des on dv.dataelementid=des.dataelementid \
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 \
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 \
inner join analytics_rs_categoryoptioncomboname con on dv.categoryoptioncomboid=con.categoryoptioncomboid\s""",
${approvalSelectExpression} \
as approvallevel, \
${valueExpression} * ps.daysno as daysxvalue, \
ps.daysno as daysno, \
${valueExpression} as value, \
${textValueExpression} as textvalue \
from ${datavalue} dv \
inner join analytics_rs_periodstructure ps on dv.periodid=ps.periodid \
inner join analytics_rs_dataelementstructure des on dv.dataelementid=des.dataelementid \
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 \
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 \
inner join analytics_rs_categoryoptioncomboname con on dv.categoryoptioncomboid=con.categoryoptioncomboid\s""",
Map.of(
"approvalSelectExpression", approvalSelectExpression,
"valueExpression", valueExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.hisp.dhis.analytics.table.setting.AnalyticsTableSettings;
import org.hisp.dhis.category.CategoryService;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.db.sql.SqlBuilder;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
Expand Down Expand Up @@ -151,11 +150,11 @@ public boolean hasUpdatedLatestData(Date startDate, Date endDate) {
String sql =
replaceQualify(
"""
select cdr.datasetid \
from ${completedatasetregistration} cdr \
where cdr.lastupdated >= '${startDate}' \
and cdr.lastupdated < '${endDate}' \
limit 1;""",
select cdr.datasetid \
from ${completedatasetregistration} cdr \
where cdr.lastupdated >= '${startDate}' \
and cdr.lastupdated < '${endDate}' \
limit 1;""",
Map.of("startDate", toLongDate(startDate), "endDate", toLongDate(endDate)));

return !jdbcTemplate.queryForList(sql).isEmpty();
Expand Down Expand Up @@ -196,24 +195,14 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti
String tableName = partition.getName();
String partitionClause = getPartitionClause(partition);

String sql = "insert into " + tableName + " (";

List<AnalyticsTableColumn> columns = partition.getMasterTable().getAnalyticsTableColumns();

for (AnalyticsTableColumn col : columns) {
sql += quote(col.getName()) + ",";
}

sql = TextUtils.removeLastComma(sql) + ") select ";

for (AnalyticsTableColumn col : columns) {
sql += col.getSelectExpression() + ",";
}

sql = TextUtils.removeLastComma(sql) + " ";

String sql = "insert into " + tableName + " (";
sql += toCommaSeparated(columns, col -> quote(col.getName()));
sql += ") select ";
sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression);
sql += " ";
// Database legacy fix

sql = sql.replace("organisationunitid", "sourceid");

sql +=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.hisp.dhis.analytics.table.setting.AnalyticsTableSettings;
import org.hisp.dhis.category.CategoryService;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.db.model.Logged;
import org.hisp.dhis.db.sql.SqlBuilder;
Expand Down Expand Up @@ -159,21 +158,13 @@ protected List<String> getPartitionChecks(Integer year, Date endDate) {
public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTablePartition partition) {
String tableName = partition.getName();

String sql = "insert into " + tableName + " (";

List<AnalyticsTableColumn> columns = partition.getMasterTable().getAnalyticsTableColumns();

for (AnalyticsTableColumn col : columns) {
sql += quote(col.getName()) + ",";
}

sql = TextUtils.removeLastComma(sql) + ") select ";

for (AnalyticsTableColumn col : columns) {
sql += col.getSelectExpression() + ",";
}

sql = TextUtils.removeLastComma(sql) + " ";
String sql = "insert into " + tableName + " (";
sql += toCommaSeparated(columns, col -> quote(col.getName()));
sql += ") select ";
sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression);
sql += " ";

sql +=
qualifyVariables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.hisp.dhis.analytics.table.setting.AnalyticsTableSettings;
import org.hisp.dhis.category.CategoryService;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.db.model.Logged;
import org.hisp.dhis.db.sql.SqlBuilder;
Expand Down Expand Up @@ -134,21 +133,13 @@ protected List<String> getPartitionChecks(Integer year, Date endDate) {
public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTablePartition partition) {
String tableName = partition.getName();

String sql = replace("insert into ${tableName} (", Map.of("tableName", quote(tableName)));

List<AnalyticsTableColumn> columns = partition.getMasterTable().getAnalyticsTableColumns();

for (AnalyticsTableColumn col : columns) {
sql += quote(col.getName()) + ",";
}

sql = TextUtils.removeLastComma(sql) + ") select ";

for (AnalyticsTableColumn col : columns) {
sql += col.getSelectExpression() + ",";
}

sql = TextUtils.removeLastComma(sql) + " ";
String sql = replace("insert into ${tableName} (", Map.of("tableName", quote(tableName)));
sql += toCommaSeparated(columns, col -> quote(col.getName()));
sql += ") select ";
sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression);
sql += " ";

sql +=
qualifyVariables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,12 @@ private void populateOwnershipTableInternal(AnalyticsTablePartition partition, S
* @return a SQL select query.
*/
private String getInputSql(Program program) {
StringBuilder sb = new StringBuilder("select ");
List<AnalyticsTableColumn> columns = getColumns();

for (AnalyticsTableColumn col : getColumns()) {
sb.append(col.getSelectExpression()).append(",");
}

sb.deleteCharAt(sb.length() - 1); // Remove the final ','.
StringBuilder sql = new StringBuilder("select ");
sql.append(toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression));

sb.append(
sql.append(
replaceQualify(
"""
\sfrom (\
Expand All @@ -272,7 +269,7 @@ and exists (\
"historyTableId", HISTORY_TABLE_ID,
"trackedEntityOwnTableId", TRACKED_ENTITY_OWN_TABLE_ID,
"programId", String.valueOf(program.getId()))));
return sb.toString();
return sql.toString();
}

private Map<String, Object> getRowMap(List<String> columnNames, ResultSet resultSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import static org.hisp.dhis.analytics.table.JdbcEventAnalyticsTableManager.EXPORTABLE_EVENT_STATUSES;
import static org.hisp.dhis.analytics.util.AnalyticsUtils.getColumnType;
import static org.hisp.dhis.analytics.util.DisplayNameUtils.getDisplayName;
import static org.hisp.dhis.commons.util.TextUtils.removeLastComma;
import static org.hisp.dhis.db.model.DataType.BOOLEAN;
import static org.hisp.dhis.db.model.DataType.CHARACTER_11;
import static org.hisp.dhis.db.model.DataType.DOUBLE;
Expand Down Expand Up @@ -295,27 +294,19 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti
List<AnalyticsTableColumn> columns = partition.getMasterTable().getAnalyticsTableColumns();

StringBuilder sql = new StringBuilder("insert into " + tableName + " (");

for (AnalyticsTableColumn col : columns) {
sql.append(quote(col.getName()) + ",");
}

removeLastComma(sql).append(") select ");

for (AnalyticsTableColumn col : columns) {
sql.append(col.getSelectExpression() + ",");
}
sql.append(toCommaSeparated(columns, col -> quote(col.getName())));
sql.append(") select ");
sql.append(toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression));

TrackedEntityType trackedEntityType = partition.getMasterTable().getTrackedEntityType();

removeLastComma(sql)
.append(
replaceQualify(
"""
\sfrom ${trackedentity} te \
left join analytics_rs_orgunitstructure ous on te.organisationunitid=ous.organisationunitid \
left join analytics_rs_organisationunitgroupsetstructure ougs on te.organisationunitid=ougs.organisationunitid""",
Map.of()));
sql.append(
replaceQualify(
"""
\sfrom ${trackedentity} te \
left join analytics_rs_orgunitstructure ous on te.organisationunitid=ous.organisationunitid \
left join analytics_rs_organisationunitgroupsetstructure ougs on te.organisationunitid=ougs.organisationunitid""",
Map.of()));

((List<TrackedEntityAttribute>)
params.getExtraParam(trackedEntityType.getUid(), ALL_NON_CONFIDENTIAL_TET_ATTRIBUTES))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static java.lang.String.valueOf;
import static org.hisp.dhis.analytics.AnalyticsTableType.TRACKED_ENTITY_INSTANCE_ENROLLMENTS;
import static org.hisp.dhis.analytics.table.JdbcEventAnalyticsTableManager.EXPORTABLE_EVENT_STATUSES;
import static org.hisp.dhis.commons.util.TextUtils.removeLastComma;
import static org.hisp.dhis.db.model.DataType.CHARACTER_11;
import static org.hisp.dhis.db.model.DataType.DOUBLE;
import static org.hisp.dhis.db.model.DataType.GEOMETRY;
Expand Down Expand Up @@ -222,41 +221,33 @@ protected List<String> getPartitionChecks(Integer year, Date endDate) {
@Override
public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTablePartition partition) {
String tableName = partition.getName();
long tetId = partition.getMasterTable().getTrackedEntityType().getId();

List<AnalyticsTableColumn> columns = partition.getMasterTable().getAnalyticsTableColumns();

StringBuilder sql = new StringBuilder("insert into " + tableName + " (");
sql.append(toCommaSeparated(columns, col -> quote(col.getName())));
sql.append(") select ");
sql.append(toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression));

for (AnalyticsTableColumn col : columns) {
sql.append(quote(col.getName()) + ",");
}

removeLastComma(sql).append(") select ");

for (AnalyticsTableColumn col : columns) {
sql.append(col.getSelectExpression() + ",");
}

removeLastComma(sql)
.append(
replaceQualify(
"""
\sfrom ${enrollment} en \
inner join ${trackedentity} te on en.trackedentityid=te.trackedentityid \
and te.deleted = false and te.trackedentitytypeid = ${trackedEntityTypeId} \
and te.lastupdated < '${startTime}' \
left join ${program} p on en.programid=p.programid \
left join analytics_rs_orgunitstructure ous on en.organisationunitid=ous.organisationunitid \
where exists (select 1 from ${event} ev where ev.deleted = false \
and ev.enrollmentid = en.enrollmentid \
and ev.status in (${statuses})) \
and en.occurreddate is not null \
and en.deleted = false\s""",
Map.of(
"trackedEntityTypeId",
valueOf(partition.getMasterTable().getTrackedEntityType().getId()),
"startTime", toLongDate(params.getStartTime()),
"statuses", join(",", EXPORTABLE_EVENT_STATUSES))));
sql.append(
replaceQualify(
"""
\sfrom ${enrollment} en \
inner join ${trackedentity} te on en.trackedentityid=te.trackedentityid \
and te.deleted = false and te.trackedentitytypeid = ${trackedEntityTypeId} \
and te.lastupdated < '${startTime}' \
left join ${program} p on en.programid=p.programid \
left join analytics_rs_orgunitstructure ous on en.organisationunitid=ous.organisationunitid \
where exists (select 1 from ${event} ev where ev.deleted = false \
and ev.enrollmentid = en.enrollmentid \
and ev.status in (${statuses})) \
and en.occurreddate is not null \
and en.deleted = false\s""",
Map.of(
"trackedEntityTypeId", valueOf(tetId),
"startTime", toLongDate(params.getStartTime()),
"statuses", join(",", EXPORTABLE_EVENT_STATUSES))));

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