Skip to content

Commit

Permalink
[COST-4367] Update HCS AWS SQL (#4812)
Browse files Browse the repository at this point in the history
* update HCS AWS SQL and add records to yaml

* consolidate to one statement without the UNION to avoid any duplicate risk
  • Loading branch information
cgoodfred committed Dec 14, 2023
1 parent a7902d3 commit bdd582d
Showing 1 changed file with 74 additions and 21 deletions.
95 changes: 74 additions & 21 deletions koku/hcs/database/sql/reporting_aws_hcs_daily_summary.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
SELECT
*,
lineitem_resourceid,
lineitem_usagestartdate,
bill_payeraccountid,
lineitem_usageaccountid,
lineitem_legalentity,
lineitem_lineitemdescription,
bill_billingentity,
lineitem_productcode,
lineitem_availabilityzone,
lineitem_lineitemtype,
product_productfamily,
product_instancetype,
product_region,
pricing_unit,
resourcetags,
costcategory,
lineitem_usageamount,
lineitem_normalizationfactor,
lineitem_normalizedusageamount,
lineitem_currencycode,
lineitem_unblendedrate,
CASE
WHEN
(
try_cast(product_vcpu AS INT) <= 4
AND (lineitem_lineitemdescription LIKE '%Red Hat%' OR lineitem_lineitemdescription LIKE '%RHEL%')
) THEN 0.06 * lineitem_usageamount
WHEN
(
try_cast(product_vcpu AS INT) > 4
AND (lineitem_lineitemdescription LIKE '%Red Hat%' OR lineitem_lineitemdescription LIKE '%RHEL%')
) THEN 0.13 * lineitem_usageamount
ELSE lineitem_unblendedcost
END AS lineitem_unblendedcost,
lineitem_blendedrate,
lineitem_blendedcost,
pricing_publicondemandcost,
pricing_publicondemandrate,
savingsplan_savingsplaneffectivecost,
product_productname,
bill_invoiceid,
product_vcpu,
source,
year,
month,
{{ebs_acct_num}} as ebs_account_id,
{{org_id}} as org_id
FROM
Expand All @@ -9,28 +53,37 @@ WHERE
AND year = {{year}}
AND month = {{month}}
AND (
-- private offer
(
bill_billingentity = 'AWS Marketplace'
AND lineitem_legalentity like '%Red Hat%'
AND lineitem_legalentity LIKE '%Red Hat%'
)
-- alternative CCSP
OR (
lineitem_legalentity LIKE '%Amazon Web Services%'
AND product_productname LIKE '%Red Hat%'
)
OR (
lineitem_legalentity LIKE '%AWS%'
AND product_productname LIKE '%Red Hat%'
)
-- CCSP with estimated costs
OR (
lineitem_legalentity LIKE '%Amazon Web Services%'
AND lineitem_lineitemdescription LIKE '%Red Hat%'
)
OR (
lineitem_legalentity LIKE '%Amazon Web Services%'
AND lineitem_lineitemdescription LIKE '%RHEL%'
)
OR (
lineitem_legalentity LIKE '%AWS%'
AND lineitem_lineitemdescription LIKE '%Red Hat%'
)
OR (
lineitem_legalentity LIKE '%AWS%'
AND lineitem_lineitemdescription LIKE '%RHEL%'
)
-- OR (
-- lineitem_legalentity like '%Amazon Web Services%'
-- AND lineitem_lineitemdescription like '%Red Hat%'
-- )
-- OR (
-- lineitem_legalentity like '%Amazon Web Services%'
-- AND lineitem_lineitemdescription like '%RHEL%'
-- )
-- OR (
-- lineitem_legalentity like '%AWS%'
-- AND lineitem_lineitemdescription like '%Red Hat%'
-- )
-- OR (
-- lineitem_legalentity like '%AWS%'
-- AND lineitem_lineitemdescription like '%RHEL%'
-- )
)
AND lineitem_usagestartdate >= {{date}}
AND lineitem_usagestartdate < date_add(
'day', 1, {{date}}
)
AND lineitem_usagestartdate < date_add('day', 1, {{date}})

0 comments on commit bdd582d

Please sign in to comment.