Skip to content

Commit

Permalink
wrapped the table name with adapter.quote which ensures tables are wr…
Browse files Browse the repository at this point in the history
…apped by db correct qoutes
  • Loading branch information
john-s58 committed Dec 31, 2024
1 parent c638d05 commit fc5d4b3
Show file tree
Hide file tree
Showing 46 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ select
'arn:aws:ec2:' || product_region_code::text || ':' || line_item_usage_account_id::text || ':instance/' || line_item_resource_id::text AS arn,
product_region_code as region,
SUM(line_item_unblended_cost) AS cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
where line_item_product_code = 'AmazonEC2'
and line_item_resource_id like 'i-%'
group by arn, region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SELECT
ec2.instance_type,
SUM(cu.line_item_unblended_cost) AS cost
FROM
{{ var('cost_usage_table') }} AS cu
{{ adapter.quote(var('cost_usage_table')) }} AS cu
JOIN
aws_ec2_instances AS ec2
ON
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT product_region_code, SUM(line_item_unblended_cost) as cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
where line_item_line_item_type = 'Usage'
AND line_item_product_code = 'AmazonEC2'
AND line_item_resource_id like 'i-%'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT
DATE(line_item_usage_end_date) AS usage_date,
SUM(line_item_unblended_cost) AS total_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE
line_item_product_code = 'AmazonEC2'
AND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cost_by_region_resource AS (
line_item_resource_id,
SUM(line_item_unblended_cost) AS cost
FROM
{{ var('cost_usage_table') }}
{{ adapter.quote(var('cost_usage_table')) }}
WHERE
line_item_resource_id != ''
AND line_item_product_code = 'AmazonEC2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SELECT
SUM(line_item_unblended_cost) AS total_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE
line_item_product_code = 'AmazonEC2'
AND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ with all_costs as (
select resource_tags_aws_elasticbeanstalk_environment_id as elasticbeanstalk_environment_id,
extract(month from bill_billing_period_start_date) as month,
sum(line_item_unblended_cost) as sum_line_item_unblended_cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
group by resource_tags_aws_elasticbeanstalk_environment_id, month
),
cost_calcs as (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
select
bill_payer_account_id as account_id,
sum(line_item_unblended_cost) as cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
where line_item_line_item_type = 'Usage'
group by bill_payer_account_id
having sum(line_item_unblended_cost) > 0

-- SELECT line_item_usage_account_id, SUM(line_item_unblended_cost) as cost
-- FROM {{ var('cost_usage_table') }}
-- FROM {{ adapter.quote(var('cost_usage_table')) }}
-- GROUP BY line_item_usage_account_id
-- HAVING SUM(line_item_unblended_cost) > 0
-- ORDER BY SUM(line_item_unblended_cost) DESC
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
select resource_tags_aws_elasticbeanstalk_environment_id as elasticbeanstalk_environment_id,
extract(month from bill_billing_period_start_date) as month,
sum(line_item_unblended_cost) as sum_line_item_unblended_cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
group by resource_tags_aws_elasticbeanstalk_environment_id, month
having sum(line_item_unblended_cost) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ select resource_tags_aws_cloudformation_logical_id as cloudformation_logical_id,
resource_tags_aws_cloudformation_stack_name as cloudformation_stack_name,
extract(month from bill_billing_period_start_date) as month,
sum(line_item_unblended_cost) as sum_line_item_unblended_cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
group by resource_tags_aws_cloudformation_logical_id, resource_tags_aws_cloudformation_stack_name, month
having sum(line_item_unblended_cost) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SELECT
SUM(CAST(line_item_usage_amount AS DOUBLE PRECISION)) AS sum_line_item_usage_amount,
SUM(line_item_unblended_cost) sum_line_item_unblended_cost
FROM
{{ var('cost_usage_table') }}
{{ adapter.quote(var('cost_usage_table')) }}
WHERE
line_item_product_code IN ('AmazonECS','AmazonEKS')
AND line_item_line_item_type IN ('DiscountedUsage', 'Usage')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
select resource_tags_aws_ecs_cluster as ecs_cluster,
extract(month from bill_billing_period_start_date) as month,
sum(line_item_unblended_cost) as sum_line_item_unblended_cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
group by resource_tags_aws_ecs_cluster, month
having sum(line_item_unblended_cost) > 0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
select resource_tags_aws_lambda_function_name as lambda_function_name,
extract(month from bill_billing_period_start_date) as month,
sum(line_item_unblended_cost) as sum_line_item_unblended_cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
group by resource_tags_aws_lambda_function_name, month
having sum(line_item_unblended_cost) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SELECT
pricing_term,
SUM(CAST(line_item_usage_amount AS DOUBLE PRECISION)) AS sum_line_item_usage_amount,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE
line_item_product_code = 'AWS Lambda'
AND line_item_line_item_type LIKE '%Usage%'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT line_item_product_code, SUM(line_item_unblended_cost) as cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
where line_item_line_item_type = 'Usage'
GROUP BY line_item_product_code
HAVING SUM(line_item_unblended_cost) > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SELECT
END) AS sum_line_item_usage_amount,
SUM(line_item_unblended_cost) AS sum_line_item_unblended_cost
FROM
{{ var('cost_usage_table') }}
{{ adapter.quote(var('cost_usage_table')) }}
WHERE
line_item_product_code = 'Amazon Relational Database Service'
GROUP BY
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT
product_location,
SUM(line_item_unblended_cost) AS cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_resource_id !='' and product_location_type = 'AWS Region'
GROUP BY product_location
HAVING SUM(line_item_unblended_cost) > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SELECT
line_item_resource_id,
line_item_product_code,
SUM(line_item_unblended_cost) AS cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_resource_id !=''
GROUP BY line_item_resource_id, line_item_product_code
HAVING SUM(line_item_unblended_cost) > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ with raw_tags as
EXTRACT(month FROM bill_billing_period_start_date) AS month,
line_item_unblended_cost
FROM
{{ var('cost_usage_table') }}
{{ adapter.quote(var('cost_usage_table')) }}
LEFT JOIN LATERAL (
SELECT
jsonb_array_elements(resource_tags::jsonb) ->> 'key' AS aws_tag_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ product_servicecode as service,
extract(month from bill_billing_period_start_date) as month,
sum(line_item_unblended_cost) as sum_line_item_unblended_cost
from
{{ var('cost_usage_table') }}
{{ adapter.quote(var('cost_usage_table')) }}
where resource_tags = '[]' or resource_tags is null
group by account_id, resource_id, service, month
having sum(line_item_unblended_cost) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ with all_costs as (
resource_tags_aws_cloudformation_stack_name as cloudformation_stack_name,
extract(month from bill_billing_period_start_date) as month,
sum(line_item_unblended_cost) as sum_line_item_unblended_cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
group by resource_tags_aws_cloudformation_logical_id, resource_tags_aws_cloudformation_stack_name, month
),
cost_calcs as (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ with all_costs as (
select resource_tags_aws_ecs_cluster as ecs_cluster,
extract(month from bill_billing_period_start_date) as month,
sum(line_item_unblended_cost) as sum_line_item_unblended_cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
group by resource_tags_aws_ecs_cluster, month
),
cost_calcs as (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FROM (
SELECT
line_item_resource_id, line_item_product_code,
SUM(line_item_unblended_cost) AS cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE
line_item_resource_id LIKE 'vol-%'
GROUP BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ with all_costs as (
select resource_tags_aws_lambda_function_name as lambda_function_name,
extract(month from bill_billing_period_start_date) as month,
sum(line_item_unblended_cost) as sum_line_item_unblended_cost
from {{ var('cost_usage_table') }}
from {{ adapter.quote(var('cost_usage_table')) }}
group by resource_tags_aws_lambda_function_name, month
),
cost_calcs as (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SELECT
line_item_usage_start_date,
line_item_usage_end_date,
SUM(line_item_unblended_cost) AS cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_resource_id !='' and product_location_type = 'AWS Region'
GROUP BY line_item_usage_start_date, line_item_usage_end_date
HAVING SUM(line_item_unblended_cost) > 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT
DATE(line_item_usage_end_date) AS usage_date,
SUM(line_item_unblended_cost) AS total_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE
line_item_resource_id != '' AND
product_location_type = 'AWS Region'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ WITH totals AS (
SELECT
line_item_line_item_type AS type,
SUM(line_item_unblended_cost) AS total
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_line_item_type IN ('Credit', 'Usage')
GROUP BY line_item_line_item_type
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ select
line_item_usage_type,
sum(cast(line_item_usage_amount AS double precision)) as sum_line_item_usage_amount_hours
from
{{ var('cost_usage_table') }}
{{ adapter.quote(var('cost_usage_table')) }}
where
line_item_line_item_type like '%Usage%'
group by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_cloudhsmv2_backups() %}
with cloudhsmv2_backups_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'AWS CloudHSM'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_docdb_cluster_snapshots(framework, check_id) %}
with docdb_cluster_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon DocumentDB'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_dynamodb_backups(framework, check_id) %}
with dynamodb_backups_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon DynamoDB'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_dynamodb_table_continuous_backups(framework, check_id) %}
with dynamodb_table_continuous_backups_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon DynamoDB'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_ec2_ebs_snapshots(framework, check_id) %}
with ec2_ebs_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon Elastic Block Store'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_elasticache_snapshots(framework, check_id) %}
with elasticache_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon ElastiCache'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_fsx_backups(framework, check_id) %}
with fsx_backups_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon FSx'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_fsx_snapshots(framework, check_id) %}
with fsx_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon FSx'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_lightsail_database_snapshots(framework, check_id) %}
with db_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon Lightsail'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_lightsail_disk_snapshots(framework, check_id) %}
with disk_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon Lightsail'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_lightsail_instance_snapshots(framework, check_id) %}
with instance_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon Lightsail'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_neptune_cluster_snapshots(framework, check_id) %}
with neptune_cluster_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon Neptune'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_rds_cluster_snapshots(framework, check_id) %}
with rds_cluster_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon RDS'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_rds_db_snapshots() %}
with rds_db_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon RDS'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro postgres__recovery_redshift_snapshots(framework, check_id) %}
with redshift_snapshots_cost as (
SELECT line_item_resource_id as resource_id, SUM(line_item_unblended_cost) as unblended_cost
FROM {{ var('cost_usage_table') }}
FROM {{ adapter.quote(var('cost_usage_table')) }}
WHERE line_item_product_code = 'Amazon Redshift'
GROUP BY line_item_resource_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cost_by_region_resource AS (
line_item_resource_id,
SUM(line_item_unblended_cost) AS cost
FROM
{{ var('cost_usage_table') }}
{{ adapter.quote(var('cost_usage_table')) }}
WHERE
line_item_resource_id != ''
AND line_item_product_code = 'AmazonDynamoDB'
Expand Down
Loading

0 comments on commit fc5d4b3

Please sign in to comment.