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

chore: Rename executiondate to occurreddate in DB [TECH-1615] #15648

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -40,7 +40,7 @@

/** Enum that maps database column names to their respective "business" names. */
public enum TimeField {
EVENT_DATE("executiondate"),
EVENT_DATE("occurreddate"),
ENROLLMENT_DATE("enrollmentdate"),
INCIDENT_DATE("incidentdate"),
// Not a typo, different naming convention between FE and database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class AnalyticsPeriodBoundary extends BaseIdentifiableObject implements E
public static final Pattern COHORT_HAVING_ATTRIBUTE_PATTERN =
Pattern.compile(COHORT_HAVING_ATTRIBUTE_REGEX);

public static final String DB_EVENT_DATE = "executiondate";
public static final String DB_EVENT_DATE = "occurreddate";

public static final String DB_ENROLLMENT_DATE = "enrollmentdate";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* An example of a generated sub-query is:
*
* <pre>
* avg((date_part('year', age(cast(executiondate as date), cast("iESIqZ0R0R0" as date)))))
* avg((date_part('year', age(cast(occurreddate as date), cast("iESIqZ0R0R0" as date)))))
* FROM analytics_event_uy2gu8kt1jf as subax"
* </pre>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class DefaultEventDataQueryService implements EventDataQueryService {

private static final String COL_NAME_EVENT_STATUS = "psistatus";

private static final String COL_NAME_EVENTDATE = "executiondate";
private static final String COL_NAME_EVENTDATE = "occurreddate";

private static final String COL_NAME_ENROLLMENTDATE = "enrollmentdate";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ private String getProgramIndicatorEventInProgramStageSql(
+ eventTableName
+ ".pi = "
+ ANALYTICS_TBL_ALIAS
+ ".pi and executiondate is not null ";
+ ".pi and occurreddate is not null ";

for (AnalyticsPeriodBoundary boundary : boundaries) {
sql +=
" and executiondate "
" and occurreddate "
+ (boundary.getAnalyticsPeriodBoundaryType().isStartBoundary() ? ">=" : "<")
+ " cast( '"
+ format.format(boundary.getBoundaryDate(reportingStartDate, reportingEndDate))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class JdbcEnrollmentAnalyticsManager extends AbstractJdbcEventAnalyticsMa

private static final String ANALYTICS_EVENT = "analytics_event_";

private static final String ORDER_BY_EXECUTION_DATE = "order by executiondate ";
private static final String ORDER_BY_EXECUTION_DATE = "order by occurreddate ";

private static final String LIMIT_1 = "limit 1";

Expand Down Expand Up @@ -553,7 +553,7 @@ protected String getColumn(QueryItem item, String suffix) {
&& !item.getRepeatableStageParams().simpleStageValueExpected()) {
return "(select json_agg(t1) from (select "
+ colName
+ ", incidentdate, scheduleddate, executiondate "
+ ", incidentdate, scheduleddate, occurreddate "
+ " from "
+ eventTableName
+ " where "
Expand Down Expand Up @@ -640,14 +640,14 @@ private static String getExecutionDateFilter(Date startDate, Date endDate) {
StringBuilder sb = new StringBuilder();

if (startDate != null) {
sb.append(" and executiondate >= ");
sb.append(" and occurreddate >= ");

sb.append(
String.format("%s ", SqlUtils.singleQuote(DateUtils.getMediumDateString(startDate))));
}

if (endDate != null) {
sb.append(" and executiondate <= ");
sb.append(" and occurreddate <= ");

sb.append(String.format("%s ", SqlUtils.singleQuote(DateUtils.getMediumDateString(endDate))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ protected String getSelectClause(EventQueryParams params) {
.add(
"psi",
"ps",
"executiondate",
"occurreddate",
"storedby",
"createdbydisplayname",
"lastupdatedbydisplayname",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public JdbcEventAnalyticsTableManager(
new AnalyticsTableColumn(quote("ao"), CHARACTER_11, NOT_NULL, "ao.uid"),
new AnalyticsTableColumn(quote("enrollmentdate"), TIMESTAMP, "pi.enrollmentdate"),
new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.incidentdate"),
new AnalyticsTableColumn(quote("executiondate"), TIMESTAMP, "psi.executiondate"),
new AnalyticsTableColumn(quote("occurreddate"), TIMESTAMP, "psi.occurreddate"),
new AnalyticsTableColumn(quote("scheduleddate"), TIMESTAMP, "psi.scheduleddate"),
new AnalyticsTableColumn(quote("completeddate"), TIMESTAMP, "psi.completeddate"),

Expand Down Expand Up @@ -262,7 +262,7 @@ public List<AnalyticsTable> getAnalyticsTables(AnalyticsTableUpdateParams params
* status
*/
static String getDateLinkedToStatus() {
return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.scheduleddate ELSE psi.executiondate END";
return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.scheduleddate ELSE psi.occurreddate END";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public JdbcTeiEventsAnalyticsTableManager(
new AnalyticsTableColumn(quote("programinstanceuid"), CHARACTER_11, NULL, "pi.uid"),
new AnalyticsTableColumn(quote("programstageuid"), CHARACTER_11, NULL, "ps.uid"),
new AnalyticsTableColumn(quote("programstageinstanceuid"), CHARACTER_11, NULL, "psi.uid"),
new AnalyticsTableColumn(quote("executiondate"), TIMESTAMP, "psi.executiondate"),
new AnalyticsTableColumn(quote("occurreddate"), TIMESTAMP, "psi.occurreddate"),
new AnalyticsTableColumn(quote("lastupdated"), TIMESTAMP, "psi.lastupdated"),
new AnalyticsTableColumn(quote("created"), TIMESTAMP, "psi.created"),
new AnalyticsTableColumn(quote("scheduleddate"), TIMESTAMP, "psi.scheduleddate"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static String eventSelect(
SqlParameterManager sqlParameterManager) {
return "select innermost_evt.*"
+ " from (select *,"
+ " row_number() over (partition by programinstanceuid order by executiondate desc) as rn"
+ " row_number() over (partition by programinstanceuid order by occurreddate desc) as rn"
+ " from "
+ ANALYTICS_TEI_EVT
+ trackedEntityType.getUid().toLowerCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static String eventProgramIndicatorSelect(
+ ", "
+ expression
+ " as value, "
+ " row_number() over (partition by pi order by executiondate desc) as rn "
+ " row_number() over (partition by pi order by occurreddate desc) as rn "
+ " from analytics_event_"
+ program.getElement().getUid()
+ " as "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void verifyWithProgramStageAndDataElement(ValueType valueType) {
+ programA.getUid()
+ ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '"
+ programStage.getUid()
+ "' order by executiondate desc limit 1 )";
+ "' order by occurreddate desc limit 1 )";

if (valueType == ValueType.NUMBER) {
subSelect = subSelect + " as \"fWIAEtYVEGk\"";
Expand Down Expand Up @@ -257,7 +257,7 @@ private void verifyWithRepeatableProgramStageAndDataElement(ValueType valueType)
+ programUid
+ ".pi = ax.pi and ps = '"
+ repeatableProgramStage.getUid()
+ "' order by executiondate desc offset 1 limit 1 ) "
+ "' order by occurreddate desc offset 1 limit 1 ) "
+ "as \""
+ programStageUid
+ "[-1]."
Expand All @@ -272,7 +272,7 @@ private void verifyWithRepeatableProgramStageAndDataElement(ValueType valueType)
+ programUid
+ ".pi = ax.pi and ps = '"
+ programStageUid
+ "' order by executiondate desc offset 1 limit 1 )) "
+ "' order by occurreddate desc offset 1 limit 1 )) "
+ "as \""
+ programStageUid
+ "[-1]."
Expand Down Expand Up @@ -303,7 +303,7 @@ void verifyWithProgramStageAndTextualDataElementAndFilter() {
+ programA.getUid()
+ ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '"
+ programStage.getUid()
+ "' order by executiondate desc limit 1 )";
+ "' order by occurreddate desc limit 1 )";

String expected =
"ax.\"quarterly\",ax.\"ou\","
Expand Down Expand Up @@ -377,7 +377,7 @@ void verifyWithProgramStageAndNumericDataElementAndFilter2() {
+ programA.getUid()
+ ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '"
+ programStage.getUid()
+ "' order by executiondate desc limit 1 )";
+ "' order by occurreddate desc limit 1 )";

String expected =
"ax.\"quarterly\",ax.\"ou\","
Expand All @@ -404,7 +404,7 @@ void verifyGetEnrollmentsWithMissingValueEqFilter() {
+ programA.getUid()
+ ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '"
+ programStage.getUid()
+ "' order by executiondate desc limit 1 )";
+ "' order by occurreddate desc limit 1 )";

String expected = subSelect + " is null";

Expand All @@ -423,7 +423,7 @@ void verifyGetEnrollmentsWithMissingValueNeqFilter() {
+ programA.getUid()
+ ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '"
+ programStage.getUid()
+ "' order by executiondate desc limit 1 )";
+ "' order by occurreddate desc limit 1 )";

String expected = subSelect + " is not null";
testIt(
Expand All @@ -441,7 +441,7 @@ void verifyGetEnrollmentsWithMissingValueAndNumericValuesInFilter() {
+ programA.getUid()
+ ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '"
+ programStage.getUid()
+ "' order by executiondate desc limit 1 )";
+ "' order by occurreddate desc limit 1 )";

String numericValues = String.join(OPTION_SEP, "10", "11", "12");
String expected =
Expand All @@ -467,7 +467,7 @@ void verifyGetEnrollmentsWithoutMissingValueAndNumericValuesInFilter() {
+ programA.getUid()
+ ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '"
+ programStage.getUid()
+ "' order by executiondate desc limit 1 )";
+ "' order by occurreddate desc limit 1 )";

String numericValues = String.join(OPTION_SEP, "10", "11", "12");
String expected = subSelect + " in (" + String.join(",", numericValues.split(OPTION_SEP)) + ")";
Expand All @@ -486,7 +486,7 @@ void verifyGetEnrollmentsWithOnlyMissingValueInFilter() {
+ programA.getUid()
+ ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '"
+ programStage.getUid()
+ "' order by executiondate desc limit 1 )";
+ "' order by occurreddate desc limit 1 )";

String expected = subSelect + " is null";
String unexpected = "(" + subSelect + " in (";
Expand Down Expand Up @@ -718,7 +718,7 @@ void verifyGetColumnOfTypeCoordinateAndWithProgramStages() {
+ dataElementA.getUid()
+ "\" is not null and ps = '"
+ programStage.getUid()
+ "' order by executiondate desc limit 1 )"));
+ "' order by occurreddate desc limit 1 )"));
}

@Test
Expand All @@ -744,13 +744,13 @@ void verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithReferenceTy
is(
"(select json_agg(t1) from (select \""
+ dataElementA.getUid()
+ "\", incidentdate, scheduleddate, executiondate from analytics_event_"
+ "\", incidentdate, scheduleddate, occurreddate from analytics_event_"
+ programB.getUid()
+ " where analytics_event_"
+ programB.getUid()
+ ".pi = ax.pi and ps = '"
+ repeatableProgramStage.getUid()
+ "' and executiondate >= '2022-01-01' and executiondate <= '2022-01-31' order by executiondate desc LIMIT 100 ) as t1)"));
+ "' and occurreddate >= '2022-01-01' and occurreddate <= '2022-01-31' order by occurreddate desc LIMIT 100 ) as t1)"));
}

@Test
Expand Down Expand Up @@ -780,7 +780,7 @@ void verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithNumberTypeV
+ programB.getUid()
+ ".pi = ax.pi and ps = '"
+ repeatableProgramStage.getUid()
+ "' order by executiondate desc limit 1 )"));
+ "' order by occurreddate desc limit 1 )"));
}

@Test
Expand Down Expand Up @@ -816,7 +816,7 @@ void verifyGetCoordinateColumnAndNoProgramStage() {
+ "and "
+ colName
+ " is not null "
+ "order by executiondate "
+ "order by occurreddate "
+ "desc limit 1 )"));
}

Expand Down Expand Up @@ -856,7 +856,7 @@ void verifyGetCoordinateColumnWithProgramStage() {
+ " is not null "
+ "and ps = '"
+ item.getProgramStage().getUid()
+ "' order by executiondate "
+ "' order by occurreddate "
+ "desc limit 1 )"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class EventAnalyticsManagerTest extends EventAnalyticsTest {
private static final String TABLE_NAME = "analytics_event";

private static final String DEFAULT_COLUMNS_WITH_REGISTRATION =
"psi,ps,executiondate,storedby,"
"psi,ps,occurreddate,storedby,"
+ "createdbydisplayname"
+ ","
+ "lastupdatedbydisplayname"
Expand Down Expand Up @@ -153,7 +153,7 @@ void verifyGetEventSqlWithProgramWithNoRegistration() {
verify(jdbcTemplate).queryForRowSet(sql.capture());

String expected =
"select psi,ps,executiondate,storedby,"
"select psi,ps,occurreddate,storedby,"
+ "createdbydisplayname"
+ ","
+ "lastupdatedbydisplayname"
Expand Down Expand Up @@ -214,7 +214,7 @@ void verifyGetEventSqlWithOrgUnitTypeDataElement() {
verify(jdbcTemplate).queryForRowSet(sql.capture());

String expected =
"select psi,ps,executiondate,storedby,"
"select psi,ps,occurreddate,storedby,"
+ "createdbydisplayname"
+ ","
+ "lastupdatedbydisplayname"
Expand Down Expand Up @@ -563,9 +563,9 @@ void verifyLastLastOrgUnitAggregationTypeSubquery() {
"from (select \"psi\",ax.\"deabcdefghX\",\"ou\","
+ "\"monthly\",\"jkYhtGth12t\","
+ "row_number() over (partition by ax.\"ou\",ax.\"jkYhtGth12t\" "
+ "order by ax.\"executiondate\" desc, ax.\"created\" desc) as pe_rank "
+ "order by ax.\"occurreddate\" desc, ax.\"created\" desc) as pe_rank "
+ "from analytics_event_prabcdefghA as ax "
+ "where ax.\"executiondate\" >= '2012-01-31' and ax.\"executiondate\" <= '2022-01-31' "
+ "where ax.\"occurreddate\" >= '2012-01-31' and ax.\"occurreddate\" <= '2022-01-31' "
+ "and ax.\"deabcdefghX\" is not null)";

assertThat(params.isAggregationType(AggregationType.LAST), is(true));
Expand Down Expand Up @@ -648,15 +648,15 @@ private void verifyFirstOrLastAggregationTypeSubquery(
"from (select \"psi\",ax.\""
+ deU.getUid()
+ "\",\"quarterly\",\"ou\","
+ "row_number() over (partition by ax.\"ou\",ax.\"ao\" order by ax.\"executiondate\" "
+ "row_number() over (partition by ax.\"ou\",ax.\"ao\" order by ax.\"occurreddate\" "
+ order
+ ", ax.\"created\" "
+ order
+ ") as pe_rank "
+ "from "
+ getTable(programA.getUid())
+ " as ax where ax.\"executiondate\" >= '1990-03-31' "
+ "and ax.\"executiondate\" <= '2000-03-31' and ax.\""
+ " as ax where ax.\"occurreddate\" >= '1990-03-31' "
+ "and ax.\"occurreddate\" <= '2000-03-31' and ax.\""
+ deU.getUid()
+ "\" is not null)";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void testRenderEventTimeFieldSqlWhenNonContinuousDateRange() {
params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();

assertEquals(
"((ax.\"executiondate\" >= '2022-04-01' and ax.\"executiondate\" < '2022-07-01')) ",
"((ax.\"occurreddate\" >= '2022-04-01' and ax.\"occurreddate\" < '2022-07-01')) ",
timeFieldSqlRenderer.renderPeriodTimeFieldSql(params));
}

Expand All @@ -103,7 +103,7 @@ void testRenderEventTimeFieldSqlWhenContinuousDateRange() {
params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();

assertEquals(
"((ax.\"executiondate\" >= '2022-04-01' and ax.\"executiondate\" < '2022-07-01')) ",
"((ax.\"occurreddate\" >= '2022-04-01' and ax.\"occurreddate\" < '2022-07-01')) ",
timeFieldSqlRenderer.renderPeriodTimeFieldSql(params));
}

Expand Down Expand Up @@ -172,7 +172,7 @@ void testRenderEnrollmentTimeFieldSqlWhenContinuousDateRangeWithTimeFieldNotAllo
params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();

assertEquals(
"((ax.\"executiondate\" >= '2022-04-01' and ax.\"executiondate\" < '2022-07-01')) ",
"((ax.\"occurreddate\" >= '2022-04-01' and ax.\"occurreddate\" < '2022-07-01')) ",
timeFieldSqlRenderer.renderPeriodTimeFieldSql(params));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,6 @@ private String getYearQueryForCurrentYear(
}

private String getDateLinkedToStatus() {
return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.scheduleddate ELSE psi.executiondate END";
return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.scheduleddate ELSE psi.occurreddate END";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void addSafetyBuffer(List<Integer> years, int buffer) {
*/
private List<Integer> fetchAvailableYears() {
String dueDateOrExecutionDate =
"(case when 'SCHEDULE' = ev.status then ev.scheduleddate else ev.executiondate end)";
"(case when 'SCHEDULE' = ev.status then ev.scheduleddate else ev.occurreddate end)";

String sql =
"( select distinct (extract(year from pe.startdate)) as datayear from period pe )"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public final Object getSql(ExpressionParser.ExprContext ctx, CommonExpressionVis
.getStatementBuilder()
.getProgramIndicatorEventColumnSql(
ctx.uid0.getText(),
"executiondate",
"occurreddate",
params.getReportingStartDate(),
params.getReportingEndDate(),
params.getProgramIndicator());
Expand Down
Loading
Loading