|
3 | 3 | "year" |
4 | 4 | , "month" |
5 | 5 | , "bill_billing_period_start_date" "billing_period" |
6 | | - , "date_trunc"('day', "line_item_usage_start_date") "usage_date" |
| 6 | + , CASE |
| 7 | + WHEN ("date_trunc"('month',"line_item_usage_start_date")) >= ("date_trunc"('month', current_timestamp) - INTERVAL '3' MONTH) THEN "date_trunc"('day', "line_item_usage_start_date") ELSE "date_trunc"('month', "line_item_usage_start_date") END "usage_date" |
7 | 8 | , "bill_payer_account_id" "payer_account_id" |
8 | 9 | , "line_item_usage_account_id" "linked_account_id" |
9 | 10 | , "bill_invoice_id" "invoice_id" |
10 | 11 | , "line_item_line_item_type" "charge_type" |
11 | | - , CASE |
12 | | - WHEN ("line_item_line_item_type" = 'DiscountedUsage') THEN 'Running_Usage' |
13 | | - -- WHEN ("line_item_line_item_type" = 'SavingsPlanCoveredUsage') THEN 'Running_Usage' |
| 12 | + , CASE |
| 13 | + WHEN ("line_item_line_item_type" = 'DiscountedUsage') THEN 'Running_Usage' |
| 14 | + -- WHEN ("line_item_line_item_type" = 'SavingsPlanCoveredUsage') THEN 'Running_Usage' |
14 | 15 | WHEN ("line_item_line_item_type" = 'Usage') THEN 'Running_Usage' ELSE 'non_usage' END "charge_category" |
15 | | - , CASE |
16 | | - -- WHEN ("savings_plan_savings_plan_a_r_n" <> '') THEN 'SavingsPlan' |
17 | | - WHEN ("reservation_reservation_a_r_n" <> '') THEN 'Reserved' |
18 | | - WHEN ("line_item_usage_type" LIKE '%Spot%') THEN 'Spot' |
| 16 | + , CASE |
| 17 | + -- WHEN ("savings_plan_savings_plan_a_r_n" <> '') THEN 'SavingsPlan' |
| 18 | + WHEN ("reservation_reservation_a_r_n" <> '') THEN 'Reserved' |
| 19 | + WHEN ("line_item_usage_type" LIKE '%Spot%') THEN 'Spot' |
19 | 20 | ELSE 'OnDemand' END "purchase_option" |
20 | | - , CASE |
21 | | - -- WHEN ("savings_plan_savings_plan_a_r_n" <> '') THEN "savings_plan_savings_plan_a_r_n" |
| 21 | + , CASE |
| 22 | + -- WHEN ("savings_plan_savings_plan_a_r_n" <> '') THEN "savings_plan_savings_plan_a_r_n" |
22 | 23 | WHEN ("reservation_reservation_a_r_n" <> '') THEN "reservation_reservation_a_r_n" ELSE '' END "ri_sp_arn" |
23 | 24 | , "line_item_product_code" "product_code" |
24 | 25 | , "product_product_name" "product_name" |
25 | | - , CASE |
26 | | - WHEN ("bill_billing_entity" = 'AWS Marketplace' AND "line_item_line_item_type" NOT LIKE '%Discount%') THEN "Product_Product_Name" |
| 26 | + , CASE |
| 27 | + WHEN ("bill_billing_entity" = 'AWS Marketplace' AND "line_item_line_item_type" NOT LIKE '%Discount%') THEN "Product_Product_Name" |
27 | 28 | WHEN ("product_servicecode" = '') THEN "line_item_product_code" ELSE "product_servicecode" END "service" |
28 | 29 | , "product_product_family" "product_family" |
29 | 30 | , "line_item_usage_type" "usage_type" |
30 | 31 | , "line_item_operation" "operation" |
31 | 32 | , "line_item_line_item_description" "item_description" |
32 | 33 | , "line_item_availability_zone" "availability_zone" |
33 | 34 | , "product_region" "region" |
34 | | - , CASE |
| 35 | + , CASE |
35 | 36 | WHEN (("line_item_usage_type" LIKE '%Spot%') AND ("line_item_product_code" = 'AmazonEC2') AND ("line_item_line_item_type" = 'Usage')) THEN "split_part"("line_item_line_item_description", '.', 1) ELSE "product_instance_type_family" END "instance_type_family" |
36 | | - , CASE |
| 37 | + , CASE |
37 | 38 | WHEN (("line_item_usage_type" LIKE '%Spot%') AND ("line_item_product_code" = 'AmazonEC2') AND ("line_item_line_item_type" = 'Usage')) THEN "split_part"("line_item_line_item_description", ' ', 1) ELSE "product_instance_type" END "instance_type" |
38 | | - , CASE |
39 | | - WHEN (("line_item_usage_type" LIKE '%Spot%') AND ("line_item_product_code" = 'AmazonEC2') AND ("line_item_line_item_type" = 'Usage')) THEN "split_part"("split_part"("line_item_line_item_description", ' ', 2), '/', 1) ELSE "product_operating_system" END "platform" |
| 39 | + , CASE |
| 40 | + WHEN (("line_item_usage_type" LIKE '%Spot%') AND ("line_item_product_code" = 'AmazonEC2') AND ("line_item_line_item_type" = 'Usage')) THEN "split_part"("split_part"("line_item_line_item_description", ' ', 2), '/', 1) ELSE "product_operating_system" END "platform" |
40 | 41 | , "product_tenancy" "tenancy" |
41 | 42 | , "product_physical_processor" "processor" |
42 | 43 | , "product_processor_features" "processor_features" |
|
49 | 50 | , "bill_billing_entity" "billing_entity" |
50 | 51 | , "pricing_unit" "pricing_unit" |
51 | 52 | , "count"(DISTINCT "Line_item_resource_id") "resource_id_count" |
52 | | - , sum(CASE |
53 | | - -- WHEN ("line_item_line_item_type" = 'SavingsPlanCoveredUsage') THEN "line_item_usage_amount" |
54 | | - WHEN ("line_item_line_item_type" = 'DiscountedUsage') THEN "line_item_usage_amount" |
| 53 | + , sum(CASE |
| 54 | + -- WHEN ("line_item_line_item_type" = 'SavingsPlanCoveredUsage') THEN "line_item_usage_amount" |
| 55 | + WHEN ("line_item_line_item_type" = 'DiscountedUsage') THEN "line_item_usage_amount" |
55 | 56 | WHEN ("line_item_line_item_type" = 'Usage') THEN "line_item_usage_amount" ELSE 0 END) "usage_quantity" |
56 | 57 | , sum ("line_item_unblended_cost") "unblended_cost" |
57 | 58 | , sum(CASE |
58 | | - -- WHEN ("line_item_line_item_type" = 'SavingsPlanCoveredUsage') THEN "savings_plan_savings_plan_effective_cost" |
59 | | - -- WHEN ("line_item_line_item_type" = 'SavingsPlanRecurringFee') THEN ("savings_plan_total_commitment_to_date" - "savings_plan_used_commitment") |
| 59 | + -- WHEN ("line_item_line_item_type" = 'SavingsPlanCoveredUsage') THEN "savings_plan_savings_plan_effective_cost" |
| 60 | + -- WHEN ("line_item_line_item_type" = 'SavingsPlanRecurringFee') THEN ("savings_plan_total_commitment_to_date" - "savings_plan_used_commitment") |
60 | 61 | -- WHEN ("line_item_line_item_type" = 'SavingsPlanNegation') THEN 0 |
61 | 62 | -- WHEN ("line_item_line_item_type" = 'SavingsPlanUpfrontFee') THEN 0 |
62 | | - WHEN ("line_item_line_item_type" = 'DiscountedUsage') THEN "reservation_effective_cost" |
| 63 | + WHEN ("line_item_line_item_type" = 'DiscountedUsage') THEN "reservation_effective_cost" |
63 | 64 | WHEN ("line_item_line_item_type" = 'RIFee') THEN ("reservation_unused_amortized_upfront_fee_for_billing_period" + "reservation_unused_recurring_fee") |
64 | 65 | WHEN (("line_item_line_item_type" = 'Fee') AND ("reservation_reservation_a_r_n" <> '')) THEN 0 ELSE "line_item_unblended_cost" END) "amortized_cost" |
65 | 66 | , sum(CASE |
66 | | - -- WHEN ("line_item_line_item_type" = 'SavingsPlanRecurringFee') THEN (-"savings_plan_amortized_upfront_commitment_for_billing_period") |
| 67 | + -- WHEN ("line_item_line_item_type" = 'SavingsPlanRecurringFee') THEN (-"savings_plan_amortized_upfront_commitment_for_billing_period") |
67 | 68 | WHEN ("line_item_line_item_type" = 'RIFee') THEN (-"reservation_amortized_upfront_fee_for_billing_period") ELSE 0 END) "ri_sp_trueup" |
68 | 69 | , sum(CASE |
69 | 70 | -- WHEN ("line_item_line_item_type" = 'SavingsPlanUpfrontFee') THEN "line_item_unblended_cost" |
70 | 71 | WHEN (("line_item_line_item_type" = 'Fee') AND ("reservation_reservation_a_r_n" <> '')) THEN "line_item_unblended_cost" ELSE 0 END) "ri_sp_upfront_fees" |
71 | 72 | , sum(CASE |
72 | | - WHEN ("line_item_line_item_type" <> 'SavingsPlanNegation') THEN "pricing_public_on_demand_cost" ELSE 0 END) "public_cost" |
| 73 | + WHEN ("line_item_line_item_type" <> 'SavingsPlanNegation') THEN "pricing_public_on_demand_cost" ELSE 0 END) "public_cost" |
73 | 74 | FROM |
74 | 75 | "${cur_table_name}" |
75 | 76 | WHERE (("bill_billing_period_start_date" >= ("date_trunc"('month', current_timestamp) - INTERVAL '7' MONTH)) AND (CAST("concat"("year", '-', "month", '-01') AS date) >= ("date_trunc"('month', current_date) - INTERVAL '7' MONTH))) |
76 | | - |
| 77 | + |
77 | 78 | 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 |
0 commit comments