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

Fix amortised cost calculations #5446

Merged
merged 9 commits into from
Jan 16, 2025
Merged
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
Loading