Skip to content

Commit 5d51dab

Browse files
[COST-5148] EC2 insert sql - set SavingsPlanCoveredUsage unblended_cost to zero (#5247)
* [COST-5148] EC2 insert sql - set SavingsPlanCoveredUsage unblended_cost to /bin/zsh * use case-insensitive check for instance name * sql close case statement --------- Co-authored-by: Luke Couzens <[email protected]>
1 parent 0933e6f commit 5d51dab

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

koku/masu/database/trino_sql/reporting_awscostentrylineitem_summary_by_ec2_compute.sql

+12-7
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ FROM (
8282
max(date(lineitem_usagestartdate)) as usage_end,
8383
lineitem_usageaccountid as usage_account_id,
8484
lineitem_resourceid as resource_id,
85-
json_extract_scalar(json_parse(resourcetags), '$.Name') AS instance_name,
85+
json_extract_scalar(json_parse(lower(resourcetags)), '$.name') AS instance_name,
8686
nullif(product_instancetype, '') as instance_type,
8787
nullif(product_operatingsystem, '') as operating_system,
8888
nullif(product_region, '') as region,
@@ -96,7 +96,17 @@ FROM (
9696
sum(lineitem_normalizedusageamount) as normalized_usage_amount,
9797
max(lineitem_currencycode) as currency_code,
9898
max(lineitem_unblendedrate) as unblended_rate,
99-
sum(lineitem_unblendedcost) as unblended_cost,
99+
/* SavingsPlanCoveredUsage entries have corresponding SavingsPlanNegation line items
100+
that offset that cost.
101+
https://docs.aws.amazon.com/cur/latest/userguide/cur-sp.html
102+
*/
103+
sum(
104+
CASE
105+
WHEN lineitem_lineitemtype='SavingsPlanCoveredUsage'
106+
THEN 0.0
107+
ELSE lineitem_unblendedcost
108+
END
109+
) as unblended_cost,
100110
max(lineitem_blendedrate) as blended_rate,
101111
sum(lineitem_blendedcost) as blended_cost,
102112
sum(savingsplan_savingsplaneffectivecost) as savingsplan_effective_cost,
@@ -118,11 +128,6 @@ FROM (
118128
AND lineitem_productcode = 'AmazonEC2'
119129
AND product_productfamily LIKE '%Compute Instance%'
120130
AND lineitem_resourceid != ''
121-
/* SavingsPlanCoveredUsage entries have corresponding SavingsPlanNegation line items
122-
that offset that cost and usage.
123-
https://docs.aws.amazon.com/cur/latest/userguide/cur-sp.html
124-
*/
125-
AND lineitem_lineitemtype != 'SavingsPlanCoveredUsage'
126131
GROUP BY lineitem_resourceid,
127132
lineitem_usageaccountid,
128133
product_instancetype,

0 commit comments

Comments
 (0)