Skip to content

Commit

Permalink
Fix amortised cost calculations (#5446)
Browse files Browse the repository at this point in the history
* Fix amortised cost calculations missing additional cost types.
  • Loading branch information
lcouzens authored Jan 16, 2025
1 parent aabdbae commit 43f3859
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ FROM (
sum(savingsplan_savingsplaneffectivecost) as savingsplan_effective_cost,
sum(
CASE
WHEN lineitem_lineitemtype='Tax'
OR lineitem_lineitemtype='Usage'
THEN lineitem_unblendedcost
ELSE savingsplan_savingsplaneffectivecost
WHEN lineitem_lineitemtype='SavingsPlanCoveredUsage'
OR lineitem_lineitemtype='SavingsPlanNegation'
THEN savingsplan_savingsplaneffectivecost
ELSE lineitem_unblendedcost
END
) as calculated_amortized_cost,
sum(pricing_publicondemandcost) as public_on_demand_cost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,58 +112,58 @@ SELECT uuid() as uuid,
aa.id as account_alias_id
FROM (
SELECT min(date(lineitem_usagestartdate)) as usage_start,
max(date(lineitem_usagestartdate)) as usage_end,
max(lineitem_usageaccountid) as usage_account_id,
lineitem_resourceid as resource_id,
max(nullif(product_operatingsystem, '')) as operating_system,
max(nullif(product_region, '')) as region,
max(nullif(pricing_unit, '')) as unit,
-- SavingsPlanNegation needs to be negated to prevent duplicate usage COST-5369
sum(
CASE
WHEN lineitem_lineitemtype='SavingsPlanNegation'
THEN 0.0
ELSE lineitem_usageamount
END
) as usage_amount,
max(lineitem_normalizationfactor) as normalization_factor,
sum(lineitem_normalizedusageamount) as normalized_usage_amount,
max(lineitem_currencycode) as currency_code,
max(lineitem_unblendedrate) as unblended_rate,
/* SavingsPlanCoveredUsage entries have corresponding SavingsPlanNegation line items
that offset that cost.
https://docs.aws.amazon.com/cur/latest/userguide/cur-sp.html
*/
sum(
CASE
WHEN lineitem_lineitemtype='SavingsPlanCoveredUsage'
THEN 0.0
ELSE lineitem_unblendedcost
END
) as unblended_cost,
max(lineitem_blendedrate) as blended_rate,
max(date(lineitem_usagestartdate)) as usage_end,
max(lineitem_usageaccountid) as usage_account_id,
lineitem_resourceid as resource_id,
max(nullif(product_operatingsystem, '')) as operating_system,
max(nullif(product_region, '')) as region,
max(nullif(pricing_unit, '')) as unit,
-- SavingsPlanNegation needs to be negated to prevent duplicate usage COST-5369
sum(
CASE
WHEN lineitem_lineitemtype='SavingsPlanNegation'
THEN 0.0
ELSE lineitem_usageamount
END
) as usage_amount,
max(lineitem_normalizationfactor) as normalization_factor,
sum(lineitem_normalizedusageamount) as normalized_usage_amount,
max(lineitem_currencycode) as currency_code,
max(lineitem_unblendedrate) as unblended_rate,
/* SavingsPlanCoveredUsage entries have corresponding SavingsPlanNegation line items
that offset that cost.
https://docs.aws.amazon.com/cur/latest/userguide/cur-sp.html
*/
sum(
CASE
WHEN lineitem_lineitemtype='SavingsPlanCoveredUsage'
THEN 0.0
ELSE lineitem_unblendedcost
END
) as unblended_cost,
max(lineitem_blendedrate) as blended_rate,
/* SavingsPlanCoveredUsage entries have corresponding SavingsPlanNegation line items
that offset that cost.
https://docs.aws.amazon.com/cur/latest/userguide/cur-sp.html
that offset that cost.
https://docs.aws.amazon.com/cur/latest/userguide/cur-sp.html
*/
sum(
CASE
WHEN lineitem_lineitemtype='SavingsPlanCoveredUsage'
THEN 0.0
ELSE lineitem_blendedcost
END
) as blended_cost,
sum(savingsplan_savingsplaneffectivecost) as savingsplan_effective_cost,
sum(
CASE
WHEN lineitem_lineitemtype='Tax'
OR lineitem_lineitemtype='Usage'
THEN lineitem_unblendedcost
ELSE savingsplan_savingsplaneffectivecost
END
) as calculated_amortized_cost,
sum(pricing_publicondemandcost) as public_on_demand_cost,
max(pricing_publicondemandrate) as public_on_demand_rate
sum(
CASE
WHEN lineitem_lineitemtype='SavingsPlanCoveredUsage'
THEN 0.0
ELSE lineitem_blendedcost
END
) as blended_cost,
sum(savingsplan_savingsplaneffectivecost) as savingsplan_effective_cost,
sum(
CASE
WHEN lineitem_lineitemtype='SavingsPlanCoveredUsage'
OR lineitem_lineitemtype='SavingsPlanNegation'
THEN savingsplan_savingsplaneffectivecost
ELSE lineitem_unblendedcost
END
) as calculated_amortized_cost,
sum(pricing_publicondemandcost) as public_on_demand_cost,
max(pricing_publicondemandrate) as public_on_demand_rate
FROM hive.{{schema | sqlsafe}}.aws_line_items_daily as lid
WHERE source = '{{source_uuid | sqlsafe}}'
AND year = '{{year | sqlsafe}}'
Expand Down

0 comments on commit 43f3859

Please sign in to comment.