Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ SELECT
, "round"("sum"("line_item_usage_amount"), 2) "line_item_usage_amount"
FROM
("${cur2_database}"."${cur2_table_name}"
LEFT JOIN aws_accounts ON ("line_item_usage_account_id" = "account_id"))
LEFT JOIN account_map ON ("line_item_usage_account_id" = "account_id"))
WHERE ("date_diff"('day', "date"("line_item_usage_start_date"), "date"("now"())) <= 110)
GROUP BY "line_item_usage_start_date", "line_item_usage_account_id", "account_name", 4
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ SELECT
, "round"("sum"("line_item_usage_amount"), 2) "line_item_usage_amount"
FROM
("${cur2_database}"."${cur2_table_name}"
LEFT JOIN aws_accounts ON ("line_item_usage_account_id" = "account_id"))
LEFT JOIN account_map ON ("line_item_usage_account_id" = "account_id"))
WHERE ("date_diff"('month', "date"("bill_billing_period_start_date"), "date"("now"())) <= 20)
GROUP BY "bill_billing_period_start_date", "line_item_usage_account_id", "account_name", 4
GROUP BY "bill_billing_period_start_date", "line_item_usage_account_id", "account_name", 4
28 changes: 11 additions & 17 deletions cid/builtin/core/data/queries/trends/monthly_bill_by_account.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ WITH
SELECT
"account_name"
, "account_id"
, "parent_account_name" "payer_account_name"
, "parent_account_id"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

account_map does not have to contain parent_account_id or parent_account_name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this query will break in this case

FROM
aws_accounts
)
, t3 AS (
SELECT
"payer_account_name"
, "account_id"
FROM
payer_account_name_map
account_map
)
, t4 AS (
SELECT
Expand All @@ -47,13 +42,12 @@ WITH
SELECT
t1.*
, "t2"."account_name"
, "t3"."payer_account_name"
, TRY_CAST("t4"."region_latitude" AS decimal) "region_latitude"
, TRY_CAST("t4"."region_longitude" AS decimal) "region_longitude"
, (CASE WHEN (("t5"."aws_service_category" IS NULL) AND ("t1"."product_product_name" IS NOT NULL)) THEN "t1"."product_product_name" WHEN (("aws_service_category" IS NULL) AND ("t1"."product_product_name" IS NULL)) THEN 'Other' ELSE "t5"."aws_service_category" END) "aws_service_category"
, "t2"."payer_account_name"
, TRY_CAST("t3"."region_latitude" AS decimal) "region_latitude"
, TRY_CAST("t3"."region_longitude" AS decimal) "region_longitude"
, (CASE WHEN (("t4"."aws_service_category" IS NULL) AND ("t1"."product_product_name" IS NOT NULL)) THEN "t1"."product_product_name" WHEN (("aws_service_category" IS NULL) AND ("t1"."product_product_name" IS NULL)) THEN 'Other' ELSE "t4"."aws_service_category" END) "aws_service_category"
FROM
((((t1
LEFT JOIN t2 ON ("t1"."line_item_usage_account_id" = "t2"."account_id"))
LEFT JOIN t3 ON ("t1"."bill_payer_account_id" = "t3"."account_id"))
LEFT JOIN t4 ON ("t1"."product_region" = "t4"."region_name"))
LEFT JOIN t5 ON ("t1"."line_item_product_code" = "t5"."line_item_product_code"))
(((t1
LEFT JOIN t2 ON ("t1"."line_item_usage_account_id" = "t2"."account_id" AND "t1"."bill_payer_account_id" = "t2"."parent_account_id"))
LEFT JOIN t3 ON ("t1"."product_region" = "t3"."region_name"))
LEFT JOIN t4 ON ("t1"."line_item_product_code" = "t4"."line_item_product_code"))