Athena Query Updates

In version 26.4.0, the Athena query layer received a major overhaul. The shared cost allocation views were rewritten to fix a duplication issue where shared costs were being multiplied across element4_id values in cartesian product joins. Both the claimed and shared resource base views were rebuilt with new columns including account_name (joined from account_mapping), aws_product, five discount columns (distributor_discount, private_rate_discount, bundled_discount, edp_discount, spp_discount), net_cost, and interval_start/interval_end date fields. AI-specific columns were added for Bedrock cost tracking: ai_provider, is_ai_usage, ai_operation_type, and token usage fields. All views now support cross-year data spanning 2024, 2025, and 2026.

There are some conditions that cause cartesian product effect in your joins. Those conditions are when multiple product users are mapped to the same product or element 4.

In Athena, run an Update to the Claimed and Shared Resource Query.

Claimed Resource Query

CREATE OR REPLACE VIEW "finopscenter_claimed_resource_base_view" AS 
SELECT
  crtbl."accountid"
, rescur."line_item_usage_account_name" "account_name"
, crtbl."resourceid" "resourceid"
, crtbl."claimedby"
, crtbl."element1" "element1_id"
, crtbl."element2map"
, crtbl."element3map"
, crtbl."element4map"
, crtbl."elementmap_element2id" "element2_id"
, crtbl."elementmap_element3id" "element3_id"
, crtbl."elementmap_element4id" "element4_id"
, crtbl."reference" "workload"
, crtbl."isactive"
, crtbl."year"
, crtbl."releasedby"
, CAST(from_iso8601_timestamp(crtbl."startdate") AS timestamp) "cr_start_date"
, CAST(from_iso8601_timestamp(crtbl."enddate") AS timestamp) "cr_end_date"
, date_trunc('day', rescur."line_item_usage_start_date") "usage_date"
, rescur."bill_payer_account_id" "payer_account_id"
, rescur."bill_billing_entity" "billing_entity"
, rescur."line_item_product_code" "product_code"
, rescur."line_item_operation" "operation"
, rescur."line_item_line_item_type" "charge_type"
, rescur."line_item_usage_type" "usage_type"
, rescur."pricing_unit" "pricing_unit"
, rescur."product_region_code" "region"
, rescur."line_item_line_item_description" "item_description"
, rescur."line_item_legal_entity" "legal_entity"
, rescur."pricing_term" "pricing_term"
, rescur."product_from_location" "product_from_location"
, rescur."product_instance_type" "instance_type"
, rescur."product_product_family" "product_family"
, rescur."product_servicecode" "service"
, rescur."product_to_location" "product_to_location"
, rescur."reservation_reservation_a_r_n" "reservation_a_r_n"
, rescur."savings_plan_savings_plan_a_r_n" "savings_plan_a_r_n"
, element_at(rescur.product, 'product_name') "aws_product"
, am."percentage" "percentage"
, date_parse(am."startdate", '%m-%d-%Y') "am_start_date"
, date_parse(am."enddate", '%m-%d-%Y') "am_end_date"
, am.accounttype "account_type"
, 'Claimed' spending_type
, rescur."savings_plan_savings_plan_effective_cost" savings_plan_effective_cost
, rescur."reservation_effective_cost" reservation_effective_cost
, rescur."line_item_usage_amount" "usage_quantity"
, rescur."line_item_unblended_cost" unblended_cost
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'Usage') THEN rescur.line_item_unblended_cost ELSE 0 END)) claimed_cost
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'Credit') THEN rescur.line_item_unblended_cost ELSE 0 END)) credit
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'Fee') THEN rescur.line_item_unblended_cost ELSE 0 END)) fee
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN rescur.line_item_unblended_cost ELSE 0 END)) savings_plan_coverage
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'Tax') THEN rescur.line_item_unblended_cost ELSE 0 END)) tax
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'RIFee') THEN rescur.line_item_unblended_cost ELSE 0 END)) ri_fee
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'DiscountedUsage') THEN rescur.line_item_unblended_cost ELSE 0 END)) discounted_usage
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'SavingsPlanNegation') THEN rescur.line_item_unblended_cost ELSE 0 END)) savings_plan_negation
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'SavingsPlanRecurringFee') THEN rescur.line_item_unblended_cost ELSE 0 END)) saving_plan_recurring_fee
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'Refund') THEN rescur.line_item_unblended_cost ELSE 0 END)) refund
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN rescur.line_item_unblended_cost ELSE 0 END)) saving_plan_upfront_fee
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'DistributorDiscount') THEN rescur.line_item_unblended_cost ELSE 0 END)) distributor_discount
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'BundledDiscount') THEN rescur.line_item_unblended_cost ELSE 0 END)) bundled_discount
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'PrivateRateDiscount') THEN rescur.line_item_unblended_cost ELSE 0 END)) private_rate_discount
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'EdpDiscount') THEN rescur.line_item_unblended_cost ELSE 0 END)) edp_discount
, SUM((CASE WHEN (rescur.line_item_line_item_type = 'SppDiscount') THEN rescur.line_item_unblended_cost ELSE 0 END)) spp_discount
FROM
  (("cid_data_export"."cur2" rescur
INNER JOIN "finopscenterq_db"."claimed_resource_table" crtbl ON (rescur."line_item_resource_id" = crtbl."resourceid"))
INNER JOIN "finopscenterq_db"."account_mapping" am ON (
    crtbl.accountid = am.accountid 
    AND crtbl.elementmap_element4id = am.element4id
    AND date_trunc('day', rescur."line_item_usage_start_date") >= date_trunc('day', date_parse(am."startdate", '%m-%d-%Y'))
    AND date_trunc('day', rescur."line_item_usage_start_date") <= date_trunc('day', date_parse(am."enddate", '%m-%d-%Y'))
))
WHERE ((line_item_resource_id <> '') AND (date_trunc('day', from_iso8601_timestamp(crtbl."startdate")) <= date_trunc('day', rescur."line_item_usage_start_date")) AND ((crtbl."enddate" IS NULL) OR (date_trunc('day', from_iso8601_timestamp(crtbl."enddate")) >= date_trunc('day', rescur."line_item_usage_start_date"))))
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46

Resource View

Updated Views Summary

The following 14 views were created or updated in 26.4.0. Base views: finopscenter_claimed_resource_base_view and finopscenter_shared_resource_base_view. Claimed element views: finopscenter_claimed_resource_view_e1 through e4. Shared element views: finopscenter_shared_resource_view_e1 through e4. Resource views (UNION ALL of claimed + shared): finopscenter_resource_view_e1 through e4. The e4-level resource views include the five discount columns in both the claimed and shared SELECT statements.

Last updated