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: Use dynamic org unit level analytics table columns [DHIS2-18417] #19439

Merged
merged 132 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 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
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 @@ -35,7 +35,6 @@
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.commons.util.TextUtils.replace;
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 @@ -65,7 +64,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.common.ValueType;
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.db.model.IndexType;
import org.hisp.dhis.db.model.Logged;
Expand All @@ -85,7 +83,7 @@
import org.springframework.transaction.annotation.Transactional;

@Component("org.hisp.dhis.analytics.TrackedEntityAnalyticsTableManager")
public class JdbcTrackedEntityAnalyticsTableManager extends AbstractJdbcTableManager {
public class JdbcTrackedEntityAnalyticsTableManager extends AbstractEventJdbcTableManager {
private static final String PROGRAMS_BY_TET_KEY = "programsByTetUid";

private static final String ALL_NON_CONFIDENTIAL_TET_ATTRIBUTES =
Expand Down Expand Up @@ -215,7 +213,7 @@ private List<AnalyticsTableColumn> getColumns(
.name(tea.getUid())
.dataType(getColumnType(tea.getValueType(), isSpatialSupport()))
.selectExpression(
castBasedOnType(tea.getValueType(), quote(tea.getUid()) + ".value"))
getColumnExpression(tea.getValueType(), quote(tea.getUid()) + ".value"))
.build())
.toList());

Expand All @@ -242,41 +240,6 @@ private Stream<TrackedEntityAttribute> getAllTrackedEntityAttributes(
return getAllTrackedEntityAttributesByEntityType(trackedEntityType);
}

/**
* Returns the select clause, potentially with a cast statement, based on the given value type.
*
* @param valueType the value type to represent as database column type.
*/
private String castBasedOnType(ValueType valueType, String columnName) {
if (valueType.isDecimal()) {

return replace(
" cast(${columnName} as ${type})",
Map.of("columnName", columnName, "type", sqlBuilder.dataTypeDouble()));
}
if (valueType.isInteger()) {
return replace(" cast(${columnName} as bigint)", Map.of("columnName", columnName));
}
if (valueType.isBoolean()) {
return replace(
" case when ${columnName} = 'true' then 1 when ${columnName} = 'false' then 0 end ",
Map.of("columnName", columnName));
}
if (valueType.isDate()) {
return replace(
" cast(${columnName} as ${type})",
Map.of("columnName", columnName, "type", sqlBuilder.dataTypeTimestamp()));
}
if (valueType.isGeo() && isSpatialSupport() && sqlBuilder.supportsGeospatialData()) {
return replace(
"""
\s ST_GeomFromGeoJSON('{"type":"Point", "coordinates":' || (${columnName}) || ',
"crs":{"type":"name", "properties":{"name":"EPSG:4326"}}}')""",
Map.of("columnName", columnName));
}
return columnName;
}

/**
* Returns all {@link TrackedEntityAttribute} for the given {@link TrackedEntityType} and
* programs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,6 @@ public class JdbcTrackedEntityEnrollmentsAnalyticsTableManager extends AbstractJ
.dataType(VARCHAR_50)
.selectExpression("en.status")
.build(),
AnalyticsTableColumn.builder()
.name("uidlevel1")
.dataType(CHARACTER_11)
.nullable(NULL)
.selectExpression("ous.uidlevel1")
.build(),
AnalyticsTableColumn.builder()
.name("uidlevel2")
.dataType(CHARACTER_11)
.nullable(NULL)
.selectExpression("ous.uidlevel2")
.build(),
AnalyticsTableColumn.builder()
.name("uidlevel3")
.dataType(CHARACTER_11)
.nullable(NULL)
.selectExpression("ous.uidlevel3")
.build(),
AnalyticsTableColumn.builder()
.name("uidlevel4")
.dataType(CHARACTER_11)
.nullable(NULL)
.selectExpression("ous.uidlevel4")
.build(),
AnalyticsTableColumn.builder()
.name("ou")
.dataType(CHARACTER_11)
Expand Down Expand Up @@ -225,6 +201,7 @@ private List<AnalyticsTableColumn> getColumns() {
List<AnalyticsTableColumn> columns = new ArrayList<>();
columns.addAll(getFixedCols());
columns.add(getOrganisationUnitNameHierarchyColumn());
columns.addAll(getOrganisationUnitLevelColumns());
if (sqlBuilder.supportsDeclarativePartitioning()) {
columns.add(getPartitionColumn());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,6 @@ public class JdbcTrackedEntityEventsAnalyticsTableManager extends AbstractJdbcTa
.dataType(VARCHAR_50)
.selectExpression("ev.status")
.build(),
AnalyticsTableColumn.builder()
.name("uidlevel1")
.dataType(CHARACTER_11)
.nullable(NULL)
.selectExpression("ous.uidlevel1")
.build(),
AnalyticsTableColumn.builder()
.name("uidlevel2")
.dataType(CHARACTER_11)
.nullable(NULL)
.selectExpression("ous.uidlevel2")
.build(),
AnalyticsTableColumn.builder()
.name("uidlevel3")
.dataType(CHARACTER_11)
.nullable(NULL)
.selectExpression("ous.uidlevel3")
.build(),
AnalyticsTableColumn.builder()
.name("uidlevel4")
.dataType(CHARACTER_11)
.nullable(NULL)
.selectExpression("ous.uidlevel4")
.build(),
AnalyticsTableColumn.builder()
.name("ou")
.dataType(CHARACTER_11)
Expand Down Expand Up @@ -367,6 +343,7 @@ private List<AnalyticsTableColumn> getColumns() {
}

columns.add(getOrganisationUnitNameHierarchyColumn());
columns.addAll(getOrganisationUnitLevelColumns());

return columns;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
package org.hisp.dhis.analytics.util;

import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.hisp.dhis.common.DataDimensionItem.DATA_DIM_TYPE_CLASS_MAP;
import static org.hisp.dhis.common.DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID;
Expand Down Expand Up @@ -1202,33 +1201,4 @@ public static String replaceStringBetween(
Matcher matcher = pattern.matcher(original);
return matcher.replaceAll(startToken + replacement + endToken);
}

/**
* Returns a string containing closing parenthesis. The number of parenthesis is based on the
* number of missing closing parenthesis in the argument string.
*
* <p>Example:
*
* <p>{@code} input: "((( ))" -> output: ")" {@code}
*
* @param str a string.
* @return a String containing 0 or more "closing" parenthesis
*/
public static String getClosingParentheses(String str) {
if (StringUtils.isEmpty(str)) {
return EMPTY;
}

int open = 0;

for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '(') {
open++;
} else if ((str.charAt(i) == ')') && open >= 1) {
open--;
}
}

return StringUtils.repeat(")", open);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ void testPopulateTable() {
String expectedSql =
"""
insert into analytics_te_event_tetuid_temp ("trackedentity","program","enrollment","programstage","event","occurreddate","lastupdated","created",
"scheduleddate","status","uidlevel1","uidlevel2","uidlevel3","uidlevel4","ou","ouname","oucode","oulevel","eventdatavalues","eventgeometry",
"scheduleddate","status","ou","ouname","oucode","oulevel","eventdatavalues","eventgeometry",
"evlongitude","evlatitude","ounamehierarchy") select distinct te.uid,p.uid,en.uid,ps.uid,ev.uid,ev.occurreddate,ev.lastupdated,
ev.created,ev.scheduleddate,ev.status,ous.uidlevel1,ous.uidlevel2,ous.uidlevel3,ous.uidlevel4,ous.organisationunituid,ous.name,ous.code,ous.level,
ev.created,ev.scheduleddate,ev.status,ous.organisationunituid,ous.name,ous.code,ous.level,
%s,
ev.geometry,case when 'POINT' = GeometryType(ev.geometry) then ST_X(ev.geometry) end,case when 'POINT' = GeometryType(ev.geometry) then ST_Y(ev.geometry) end,concat_ws(' / ',) as ounamehierarchy
from "event" ev inner join "enrollment" en on en.enrollmentid=ev.enrollmentid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,14 +739,6 @@ void testGetEnumCaseSensitivity() {
assertNull(EnumUtils.getEnum(Database.class, "postgresql"));
}

@Test
void testGetClosingParentheses() {
assertEquals("", AnalyticsUtils.getClosingParentheses(null));
assertEquals("", AnalyticsUtils.getClosingParentheses(""));
assertEquals(")", AnalyticsUtils.getClosingParentheses("from(select(select (*))"));
assertEquals("))", AnalyticsUtils.getClosingParentheses("(("));
}

@Test
void whenUncategorizedSQLException_withTableNotExisting_thenThrowException() {
SQLException sqlException = new SQLException("relation does not exist", "42P01");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ public boolean supportsVacuum() {
return false;
}

@Override
public boolean supportsCorrelatedSubquery() {
return false;
}

@Override
public boolean requiresIndexesForAnalytics() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public boolean supportsVacuum() {
return false;
}

@Override
public boolean supportsCorrelatedSubquery() {
return true;
}

@Override
public boolean requiresIndexesForAnalytics() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public boolean supportsVacuum() {
return true;
}

@Override
public boolean supportsCorrelatedSubquery() {
return true;
}

@Override
public boolean requiresIndexesForAnalytics() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ public interface SqlBuilder {
*/
boolean supportsVacuum();

/**
* @return true if the DBMS supports corrected subqueries.
*/
boolean supportsCorrelatedSubquery();

/**
* @return true if the DBMS requires indexes for analytics tables for performance.
*/
Expand Down
Loading