From 3aa36a540aa05f032bd5b2728bc0777634de2eee Mon Sep 17 00:00:00 2001 From: Greg Dean Date: Tue, 30 Apr 2024 14:53:07 -0400 Subject: [PATCH 1/2] change aggregation to better account for resource allocated changes --- .../resource_specifications/resource_specs_aggregation.json | 2 +- .../resource_specs_aggregation_by_day.json | 2 +- configuration/etl/etl_macros.d/resource_specs_time_diff.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation.json b/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation.json index 7034a1d327..9a5068a782 100644 --- a/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation.json +++ b/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation.json @@ -67,7 +67,7 @@ "name": "resource_allocated", "alias": "ra", "schema": "${SOURCE_SCHEMA}", - "on": "r.resource_id = ra.resource_id AND r.start_day_id = ra.start_day_id AND r.end_day_id = ra.end_day_id" + "on": "r.resource_id = ra.resource_id AND ra.start_day_id <= ${:PERIOD_END_DAY_ID} AND ra.end_day_id >= ${:PERIOD_START_DAY_ID}" }, { "name": "resourcefact", diff --git a/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation_by_day.json b/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation_by_day.json index d7409e2425..4fa28e13e9 100644 --- a/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation_by_day.json +++ b/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation_by_day.json @@ -68,7 +68,7 @@ "name": "resource_allocated", "alias": "ra", "schema": "${SOURCE_SCHEMA}", - "on": "r.resource_id = ra.resource_id AND r.start_day_id = ra.start_day_id AND r.end_day_id = ra.end_day_id" + "on": "r.resource_id = ra.resource_id AND ra.start_day_id <= ${:PERIOD_END_DAY_ID} AND ra.end_day_id >= ${:PERIOD_START_DAY_ID}" }, { "name": "resourcefact", diff --git a/configuration/etl/etl_macros.d/resource_specs_time_diff.sql b/configuration/etl/etl_macros.d/resource_specs_time_diff.sql index ce0198cc3a..b391629bbc 100644 --- a/configuration/etl/etl_macros.d/resource_specs_time_diff.sql +++ b/configuration/etl/etl_macros.d/resource_specs_time_diff.sql @@ -1 +1 @@ -GREATEST(0, 1 + COALESCE(LEAST(r.end_date_ts, ${:PERIOD_END_TS}), ${:PERIOD_END_TS}) - GREATEST(r.start_date_ts, ${:PERIOD_START_TS})) +GREATEST(0, 1 + COALESCE(LEAST(ra.end_date_ts, r.end_date_ts, ${:PERIOD_END_TS}), ${:PERIOD_END_TS}) - GREATEST(ra.start_date_ts, r.start_date_ts, ${:PERIOD_START_TS})) From 0b3eb545915f176fbb19ff5cd7d083747e02a258 Mon Sep 17 00:00:00 2001 From: Greg Dean Date: Thu, 2 May 2024 08:00:40 -0400 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Aaron Weeden <31246768+aaronweeden@users.noreply.github.com> --- .../resource_specs_aggregation.json | 2 +- .../resource_specs_aggregation_by_day.json | 2 +- .../etl_macros.d/resource_specs_time_diff.sql | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation.json b/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation.json index 9a5068a782..4085bf1c7b 100644 --- a/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation.json +++ b/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation.json @@ -67,7 +67,7 @@ "name": "resource_allocated", "alias": "ra", "schema": "${SOURCE_SCHEMA}", - "on": "r.resource_id = ra.resource_id AND ra.start_day_id <= ${:PERIOD_END_DAY_ID} AND ra.end_day_id >= ${:PERIOD_START_DAY_ID}" + "on": "r.resource_id = ra.resource_id AND ra.start_day_id <= ${:PERIOD_END_DAY_ID} AND ra.end_day_id >= ${:PERIOD_START_DAY_ID} AND ra.start_day_id <= r.end_day_id AND ra.end_day_id >= r.start_day_id" }, { "name": "resourcefact", diff --git a/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation_by_day.json b/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation_by_day.json index 4fa28e13e9..009ab3b062 100644 --- a/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation_by_day.json +++ b/configuration/etl/etl_action_defs.d/resource_specifications/resource_specs_aggregation_by_day.json @@ -68,7 +68,7 @@ "name": "resource_allocated", "alias": "ra", "schema": "${SOURCE_SCHEMA}", - "on": "r.resource_id = ra.resource_id AND ra.start_day_id <= ${:PERIOD_END_DAY_ID} AND ra.end_day_id >= ${:PERIOD_START_DAY_ID}" + "on": "r.resource_id = ra.resource_id AND ra.start_day_id <= ${:PERIOD_END_DAY_ID} AND ra.end_day_id >= ${:PERIOD_START_DAY_ID} AND ra.start_day_id <= r.end_day_id AND ra.end_day_id >= r.start_day_id" }, { "name": "resourcefact", diff --git a/configuration/etl/etl_macros.d/resource_specs_time_diff.sql b/configuration/etl/etl_macros.d/resource_specs_time_diff.sql index b391629bbc..d27786eef6 100644 --- a/configuration/etl/etl_macros.d/resource_specs_time_diff.sql +++ b/configuration/etl/etl_macros.d/resource_specs_time_diff.sql @@ -1 +1,15 @@ -GREATEST(0, 1 + COALESCE(LEAST(ra.end_date_ts, r.end_date_ts, ${:PERIOD_END_TS}), ${:PERIOD_END_TS}) - GREATEST(ra.start_date_ts, r.start_date_ts, ${:PERIOD_START_TS})) +GREATEST( + 0, + 1 + COALESCE( + LEAST( + ra.end_date_ts, + r.end_date_ts, + ${:PERIOD_END_TS} + ), + ${:PERIOD_END_TS} + ) - GREATEST( + ra.start_date_ts, + r.start_date_ts, + ${:PERIOD_START_TS} + ) +)