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: Rename PostgresAnalyticsSqlBuilder [DHIS2-16705] #19469

Merged
merged 169 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 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
3d02bc6
Merge branch 'master' into DHIS2-18417
larshelge Dec 11, 2024
718d1be
fix: Update code
larshelge Dec 11, 2024
c679653
fix: Update code
larshelge Dec 11, 2024
e0aa6fb
Merge branch 'master' into DHIS2-18417
larshelge Dec 11, 2024
221a551
fix: Update code
larshelge Dec 11, 2024
7b0af20
fix: Update code
larshelge Dec 11, 2024
51462ef
fix: Update code
larshelge Dec 11, 2024
31ca1c6
Merge branch 'master' into DHIS2-18417
larshelge Dec 11, 2024
d9a17a3
Merge branch 'master' into DHIS2-18417
larshelge Dec 11, 2024
0b838bf
fix: Update code
larshelge Dec 11, 2024
7074bfd
Merge branch 'master' into DHIS2-18417
larshelge Dec 11, 2024
96afbba
fix: Update code
larshelge Dec 11, 2024
41bf58e
fix: Update code
larshelge Dec 11, 2024
be3a56b
Merge branch 'master' into DHIS2-18417
larshelge Dec 11, 2024
a53b45f
Merge branch 'master' into DHIS2-18417
larshelge Dec 14, 2024
0eeac01
fix: Update code
larshelge Dec 14, 2024
a8b798e
fix: Update code
larshelge Dec 14, 2024
bc07542
fix: Update code
larshelge Dec 14, 2024
693bb22
fix: Update code
larshelge Dec 14, 2024
3f30eb9
fix: Update code
larshelge Dec 14, 2024
c193d20
fix: Update code
larshelge Dec 14, 2024
e3ea08e
fix: Update code
larshelge Dec 14, 2024
4bf8a0a
fix: Update code
larshelge Dec 14, 2024
6ffe5d6
fix: Update code
larshelge Dec 14, 2024
a6c1c18
fix: Update code
larshelge Dec 15, 2024
891349f
Merge branch 'master' into DHIS2-18417
larshelge Dec 15, 2024
d5a753d
fix: Update code
larshelge Dec 15, 2024
1687966
fix: Update code
larshelge Dec 15, 2024
744704f
fix: Update code
larshelge Dec 15, 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 @@ -49,8 +49,8 @@
import static org.hisp.dhis.analytics.event.data.EnrollmentQueryHelper.getHeaderColumns;
import static org.hisp.dhis.analytics.event.data.EnrollmentQueryHelper.getOrgUnitLevelColumns;
import static org.hisp.dhis.analytics.event.data.EnrollmentQueryHelper.getPeriodColumns;
import static org.hisp.dhis.analytics.table.JdbcEventAnalyticsTableManager.OU_GEOMETRY_COL_SUFFIX;
import static org.hisp.dhis.analytics.table.JdbcEventAnalyticsTableManager.OU_NAME_COL_SUFFIX;
import static org.hisp.dhis.analytics.table.AbstractEventJdbcTableManager.OU_GEOMETRY_COL_SUFFIX;
import static org.hisp.dhis.analytics.table.AbstractEventJdbcTableManager.OU_NAME_COL_SUFFIX;
import static org.hisp.dhis.analytics.util.AnalyticsUtils.replaceStringBetween;
import static org.hisp.dhis.analytics.util.AnalyticsUtils.throwIllegalQueryEx;
import static org.hisp.dhis.analytics.util.AnalyticsUtils.withExceptionHandling;
Expand Down Expand Up @@ -375,8 +375,9 @@ private void addDimensionSelectColumns(
singleQuote(period.getIsoDate()) + " as " + period.getPeriodType().getName());
} else {
throw new IllegalStateException(
"Program indicator non-default boundary query must have "
+ "exactly one period, or no periods and a period filter");
"""
Program indicator non-default boundary query must have \"
exactly one period, or no periods and a period filter""");
}
});
}
Expand Down Expand Up @@ -455,7 +456,6 @@ private ColumnAndAlias getColumnAndAlias(
} else if (queryItem.getValueType() == ValueType.NUMBER && !isGroupByClause) {
ColumnAndAlias columnAndAlias =
getColumnAndAlias(queryItem, isAggregated, queryItem.getItemName());

return ColumnAndAlias.ofColumnAndAlias(
columnAndAlias.getColumn(),
defaultIfNull(columnAndAlias.getAlias(), queryItem.getItemName()));
Expand Down Expand Up @@ -532,14 +532,10 @@ protected Optional<String> getAlias(QueryItem queryItem) {
@Transactional(readOnly = true, propagation = REQUIRES_NEW)
public Grid getAggregatedEventData(EventQueryParams params, Grid grid, int maxLimit) {
String aggregateClause = getAggregateClause(params);
String columns = StringUtils.join(getSelectColumns(params, true), ",");

String sql =
TextUtils.removeLastComma(
"select "
+ aggregateClause
+ " as value,"
+ StringUtils.join(getSelectColumns(params, true), ",")
+ " ");
TextUtils.removeLastComma("select " + aggregateClause + " as value," + columns + " ");

// ---------------------------------------------------------------------
// Criteria
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ public class AnalyticsTableColumn {
/** Date of creation of the underlying data dimension. */
private final Date created;

// // -------------------------------------------------------------------------
// // Logic
// // -------------------------------------------------------------------------

/** Indicates whether this column is not null. */
public boolean isNotNull() {
return Nullable.NOT_NULL == nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ select json_agg(json_build_object(
// incidentDate is kept to support a deprecated field, will be removed when FE will only
// use occurreddate
"""
select json_agg(
json_build_object(
'programUid', en.program,
'enrollmentUid', en.enrollment,
'enrollmentDate', en.enrollmentdate,
'incidentDate', en.occurreddate,
'occurredDate', en.occurreddate,
'completedDate', en.completeddate,
'orgUnitUid', en.ou,
'orgUnitName', en.ouname,
'orgUnitCode', en.oucode,
'orgUnitNameHierarchy', en.ounamehierarchy,
'enrollmentStatus', en.enrollmentstatus,
'events', ${eventQuery}))
from analytics_te_enrollment_${trackedEntityType} en
where en.trackedentity = t_1.trackedentity""",
select json_agg(
json_build_object(
'programUid', en.program,
'enrollmentUid', en.enrollment,
'enrollmentDate', en.enrollmentdate,
'incidentDate', en.occurreddate,
'occurredDate', en.occurreddate,
'completedDate', en.completeddate,
'orgUnitUid', en.ou,
'orgUnitName', en.ouname,
'orgUnitCode', en.oucode,
'orgUnitNameHierarchy', en.ounamehierarchy,
'enrollmentStatus', en.enrollmentstatus,
'events', ${eventQuery}))
from analytics_te_enrollment_${trackedEntityType} en
where en.trackedentity = t_1.trackedentity""",
Map.of("eventQuery", coalesceToEmptyArray(EVENT_QUERY)));

private static final String JSON_AGGREGATION_QUERY = coalesceToEmptyArray(ENROLLMENT_QUERY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,22 @@ public static String getDisplayName(
isNotEmpty.apply(surname),
isNotEmpty.apply(firstName),
isEmpty.apply(username),
formatNames(sqlBuilder, surname, "', '", firstName),
sqlBuilder.concat(surname, "', '", firstName),

// FirstName and Username
isEmpty.apply(surname),
isNotEmpty.apply(firstName),
isNotEmpty.apply(username),
formatNames(sqlBuilder, firstName, "' ('", username, "')'"),
sqlBuilder.concat(firstName, "' ('", username, "')'"),

// Surname and Username
isNotEmpty.apply(surname),
isEmpty.apply(firstName),
isNotEmpty.apply(username),
formatNames(sqlBuilder, surname, "' ('", username, "')'"),
sqlBuilder.concat(surname, "' ('", username, "')'"),

// All fields
formatNames(sqlBuilder, surname, "', '", firstName, "' ('", username, "')'"),
sqlBuilder.concat(surname, "', '", firstName, "' ('", username, "')'"),
columnAlias);
}

Expand All @@ -149,8 +149,4 @@ private static String extractJsonValue(
String jsonExtracted = sqlBuilder.jsonExtract(json, path);
return sqlBuilder.trim(jsonExtracted);
}

private static String formatNames(SqlBuilder sqlBuilder, String... elements) {
return sqlBuilder.concat(elements);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
import org.hisp.dhis.category.CategoryService;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.db.sql.PostgreSqlAnalyticsSqlBuilder;
import org.hisp.dhis.db.sql.PostgreSqlBuilder;
import org.hisp.dhis.db.sql.PostgresAnalyticsSqlBuilder;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.PeriodDataProvider;
import org.hisp.dhis.resourcetable.ResourceTableService;
Expand Down Expand Up @@ -82,7 +82,7 @@ class JdbcTrackedEntityEventsAnalyticsTableManagerTest {

@Spy private PostgreSqlBuilder sqlBuilder;

@Spy private PostgresAnalyticsSqlBuilder analyticsSqlBuilder;
@Spy private PostgreSqlAnalyticsSqlBuilder analyticsSqlBuilder;

@Mock private PartitionManager partitionManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.hisp.dhis.db.sql.AnalyticsSqlBuilder;
import org.hisp.dhis.db.sql.ClickhouseAnalyticsSqlBuilder;
import org.hisp.dhis.db.sql.DorisAnalyticsSqlBuilder;
import org.hisp.dhis.db.sql.PostgresAnalyticsSqlBuilder;
import org.hisp.dhis.db.sql.PostgreSqlAnalyticsSqlBuilder;
import org.hisp.dhis.external.conf.DhisConfigurationProvider;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -70,7 +70,7 @@ private AnalyticsSqlBuilder getSqlBuilder(SqlBuilderSettings config) {
return switch (database) {
case DORIS -> new DorisAnalyticsSqlBuilder();
case CLICKHOUSE -> new ClickhouseAnalyticsSqlBuilder();
default -> new PostgresAnalyticsSqlBuilder();
default -> new PostgreSqlAnalyticsSqlBuilder();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
package org.hisp.dhis.db.sql;

public class PostgresAnalyticsSqlBuilder implements AnalyticsSqlBuilder {
public class PostgreSqlAnalyticsSqlBuilder implements AnalyticsSqlBuilder {

/**
* Returns a subquery that expand the event datavalue jsonb with two additional fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ public String dateDifference(String startDate, String endDate, DateUnit dateUnit
String.format(
"(extract(epoch from (cast(%s as timestamp) - cast(%s as timestamp))) / 60)",
endDate, startDate);
case WEEKS ->
String.format("((cast(%s as date) - cast(%s as date)) / 7)", endDate, startDate);
case MONTHS ->
String.format(
"((date_part('year',age(cast(%s as date), cast(%s as date)))) * 12 + "
Expand All @@ -286,8 +288,6 @@ public String dateDifference(String startDate, String endDate, DateUnit dateUnit
case YEARS ->
String.format(
"(date_part('year',age(cast(%s as date), cast(%s as date))))", endDate, startDate);
case WEEKS ->
String.format("((cast(%s as date) - cast(%s as date)) / 7)", endDate, startDate);
};
}

Expand Down
Loading