From 32977201a89e4f16b3b631b653af7b32e15d7d80 Mon Sep 17 00:00:00 2001 From: Cody Myers Date: Fri, 25 Oct 2024 18:44:56 -0400 Subject: [PATCH] [COST-5603] Prevent zero for AWS disk capacity (#5346) --- ...rting_ocpawscostlineitem_daily_summary.sql | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql b/koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql index d147a8cb7d..5146f4fda6 100644 --- a/koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql +++ b/koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql @@ -418,23 +418,28 @@ cte_ocp_filtered_resources as ( AND aws.ocp_source = {{ocp_source_uuid}} AND aws.year = {{year}} AND aws.month = {{month}} +), +calculated_capacity AS ( + SELECT + aws.lineitem_resourceid as resource_id, + ROUND(MAX(aws.lineitem_unblendedcost) / (MAX(aws.lineitem_unblendedrate) / MAX(hours.in_month))) AS capacity, + ocpaws.usage_start, + {{ocp_source_uuid}} as ocp_source, + {{year}} as year, + {{month}} as month + FROM hive.{{schema | sqlsafe}}.aws_line_items as aws + INNER JOIN cte_ocp_filtered_resources as ocpaws + ON aws.lineitem_resourceid = ocpaws.resource_id + AND DATE(aws.lineitem_usagestartdate) = ocpaws.usage_start + CROSS JOIN cte_hours as hours + WHERE aws.year = {{year}} + AND aws.month = {{month}} + AND aws.source = {{aws_source_uuid}} + GROUP BY aws.lineitem_resourceid, ocpaws.usage_start ) -SELECT - aws.lineitem_resourceid as resource_id, - ROUND(MAX(aws.lineitem_unblendedcost) / (MAX(aws.lineitem_unblendedrate) / MAX(hours.in_month))) AS capacity, - ocpaws.usage_start, - {{ocp_source_uuid}} as ocp_source, - {{year}} as year, - {{month}} as month -FROM hive.{{schema | sqlsafe}}.aws_line_items as aws -INNER JOIN cte_ocp_filtered_resources as ocpaws - ON aws.lineitem_resourceid = ocpaws.resource_id - AND DATE(aws.lineitem_usagestartdate) = ocpaws.usage_start -CROSS JOIN cte_hours as hours -WHERE aws.year = {{year}} -AND aws.month = {{month}} -AND aws.source = {{aws_source_uuid}} -group by aws.lineitem_resourceid, ocpaws.usage_start +SELECT * +FROM calculated_capacity +WHERE capacity > 0 {% endif %} ;