Skip to content

Commit

Permalink
feat: add year column to allow Doris partitioning [DHIS2-16705] (#19158)
Browse files Browse the repository at this point in the history
  • Loading branch information
luciano-fiandesio authored Nov 14, 2024
1 parent a520d26 commit 529d41c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import static org.hisp.dhis.analytics.table.util.PartitionUtils.getStartDate;
import static org.hisp.dhis.commons.util.TextUtils.format;
import static org.hisp.dhis.db.model.DataType.CHARACTER_11;
import static org.hisp.dhis.db.model.DataType.INTEGER;
import static org.hisp.dhis.db.model.DataType.TEXT;
import static org.hisp.dhis.db.model.constraint.Nullable.NOT_NULL;
import static org.hisp.dhis.util.DateUtils.toLongDate;

import java.util.Collection;
Expand Down Expand Up @@ -732,6 +734,24 @@ protected String replaceQualify(String template, Map<String, String> variables)
return TextUtils.replace(template, map);
}

protected AnalyticsTableColumn getPartitionColumn() {
return AnalyticsTableColumn.builder()
.name("year")
.dataType(INTEGER)
.nullable(NOT_NULL)
// The expression should use sqlBuilder, but the concept of functions (like YEAR)
// is part of the previous PR (https://github.com/dhis2/dhis2-core/pull/19131/files)
.selectExpression(
"""
CASE
WHEN ev.status = 'SCHEDULE' THEN YEAR(ev.scheduleddate)
ELSE YEAR(ev.occurreddate)
END
""")
.skipIndex(Skip.SKIP)
.build();
}

// -------------------------------------------------------------------------
// Private supportive methods
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ private List<AnalyticsTableColumn> getColumns(
.toList());

columns.addAll(getOrganisationUnitGroupSetColumns());
if (sqlBuilder.supportsDeclarativePartitioning()) {
columns.add(getPartitionColumn());
}

return columns;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ private List<AnalyticsTableColumn> getColumns() {
List<AnalyticsTableColumn> columns = new ArrayList<>();
columns.addAll(FIXED_COLS);
columns.add(getOrganisationUnitNameHierarchyColumn());

if (sqlBuilder.supportsDeclarativePartitioning()) {
columns.add(getPartitionColumn());
}
return columns;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ private List<Integer> getDataYears(AnalyticsTableUpdateParams params, TrackedEnt
private List<AnalyticsTableColumn> getColumns() {
List<AnalyticsTableColumn> columns = new ArrayList<>();
columns.addAll(FIXED_COLS);

if (sqlBuilder.supportsDeclarativePartitioning()) {
columns.add(getPartitionColumn());
}

columns.add(getOrganisationUnitNameHierarchyColumn());

return columns;
Expand Down

0 comments on commit 529d41c

Please sign in to comment.