Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes problems with quoting: true #139

Merged
merged 14 commits into from
Nov 30, 2023
2 changes: 1 addition & 1 deletion macros/create_merge_objects_udf.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% macro create_merge_objects_udf(relation) %}

create or replace function {{ relation.database }}.{{ relation.schema }}.merge_objects(obj1 variant, obj2 variant)
create or replace function {{ adapter.quote_as_configured(this.database, 'database') }}.{{ adapter.quote_as_configured(this.schema, 'schema') }}.merge_objects(obj1 variant, obj2 variant)
Copy link
Contributor

Choose a reason for hiding this comment

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

@NiallRees can you have a look at this?

returns variant
language javascript
comment = 'Created by dbt-snowflake-monitoring dbt package.'
Expand Down
4 changes: 2 additions & 2 deletions models/cost_per_query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ query_cost as (
inner join credits_billed_hourly
on query_seconds_per_hour.warehouse_id = credits_billed_hourly.warehouse_id
and query_seconds_per_hour.hour = credits_billed_hourly.hour
inner join {{ ref('daily_rates') }}
inner join {{ ref('daily_rates') }} as daily_rates
on date(query_seconds_per_hour.start_time) = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'compute'
Expand Down Expand Up @@ -157,7 +157,7 @@ select
from all_queries
inner join credits_billed_daily
on date(all_queries.start_time) = credits_billed_daily.date
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on date(all_queries.start_time) = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'cloud services'
Expand Down
48 changes: 24 additions & 24 deletions models/hourly_spend.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ storage_spend_hourly as (
any_value(daily_rates.currency) as currency
from hours
left join storage_terabytes_daily on hours.date = convert_timezone('UTC', storage_terabytes_daily.date)
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on storage_terabytes_daily.date = daily_rates.date
and daily_rates.service_type = 'STORAGE'
and daily_rates.usage_type = 'storage'
Expand All @@ -100,7 +100,7 @@ data_transfer_spend_hourly as (
spend as spend_net_cloud_services,
stg_usage_in_currency_daily.currency as currency
from hours
left join {{ ref('stg_usage_in_currency_daily') }} on
left join {{ ref('stg_usage_in_currency_daily') }} as stg_usage_in_currency_daily on
stg_usage_in_currency_daily.account_locator = {{ account_locator() }}
and stg_usage_in_currency_daily.usage_type = 'data transfer'
and hours.hour::date = stg_usage_in_currency_daily.usage_date
Expand All @@ -122,11 +122,11 @@ compute_spend_hourly as (
spend as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_metering_history') }} on
left join {{ ref('stg_metering_history') }} as stg_metering_history on
hours.hour = convert_timezone(
'UTC', stg_metering_history.start_time
)
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'compute'
Expand All @@ -151,9 +151,9 @@ serverless_task_spend_hourly as (
spend as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_serverless_task_history') }} on
left join {{ ref('stg_serverless_task_history') }} as stg_serverless_task_history on
hours.hour = date_trunc('hour', stg_serverless_task_history.start_time)
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'serverless tasks'
Expand All @@ -176,9 +176,9 @@ adj_for_incl_cloud_services_hourly as (
0 as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_metering_daily_history') }} on
left join {{ ref('stg_metering_daily_history') }} as stg_metering_daily_history on
hours.hour = stg_metering_daily_history.date
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'cloud services'
Expand All @@ -201,7 +201,7 @@ _cloud_services_usage_hourly as (
sum(stg_metering_history.credits_used_cloud_services), 0
) as credits_used_cloud_services
from hours
left join {{ ref('stg_metering_history') }} on
left join {{ ref('stg_metering_history') }} as stg_metering_history on
hours.hour = convert_timezone(
'UTC', stg_metering_history.start_time
)
Expand Down Expand Up @@ -241,7 +241,7 @@ cloud_services_spend_hourly as (
from _cloud_services_usage_hourly
inner join _cloud_services_billed_daily on
_cloud_services_usage_hourly.date = _cloud_services_billed_daily.date
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on _cloud_services_usage_hourly.date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'cloud services'
Expand All @@ -264,12 +264,12 @@ automatic_clustering_spend_hourly as (
spend as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_metering_history') }} on
left join {{ ref('stg_metering_history') }} as stg_metering_history on
hours.hour = convert_timezone(
'UTC', stg_metering_history.start_time
)
and stg_metering_history.service_type = 'AUTO_CLUSTERING'
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'automatic clustering'
Expand All @@ -292,12 +292,12 @@ materialized_view_spend_hourly as (
spend as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_metering_history') }} on
left join {{ ref('stg_metering_history') }} as stg_metering_history on
hours.hour = convert_timezone(
'UTC', stg_metering_history.start_time
)
and stg_metering_history.service_type = 'MATERIALIZED_VIEW'
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'materialized views'
Expand All @@ -320,12 +320,12 @@ snowpipe_spend_hourly as (
spend as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_metering_history') }} on
left join {{ ref('stg_metering_history') }} as stg_metering_history on
hours.hour = convert_timezone(
'UTC', stg_metering_history.start_time
)
and stg_metering_history.service_type = 'PIPE'
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'snowpipe'
Expand All @@ -348,12 +348,12 @@ snowpipe_streaming_spend_hourly as (
spend as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_metering_history') }} on
left join {{ ref('stg_metering_history') }} as stg_metering_history on
hours.hour = convert_timezone(
'UTC', stg_metering_history.start_time
)
and stg_metering_history.service_type = 'SNOWPIPE_STREAMING'
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'snowpipe streaming'
Expand All @@ -376,12 +376,12 @@ query_acceleration_spend_hourly as (
spend as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_metering_history') }} on
left join {{ ref('stg_metering_history') }} as stg_metering_history on
hours.hour = convert_timezone(
'UTC', stg_metering_history.start_time
)
and stg_metering_history.service_type = 'QUERY_ACCELERATION'
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'query acceleration'
Expand All @@ -404,12 +404,12 @@ replication_spend_hourly as (
spend as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_metering_history') }} on
left join {{ ref('stg_metering_history') }} as stg_metering_history on
hours.hour = convert_timezone(
'UTC', stg_metering_history.start_time
)
and stg_metering_history.service_type = 'REPLICATION'
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'replication'
Expand All @@ -432,12 +432,12 @@ search_optimization_spend_hourly as (
spend as spend_net_cloud_services,
any_value(daily_rates.currency) as currency
from hours
left join {{ ref('stg_metering_history') }} on
left join {{ ref('stg_metering_history') }} as stg_metering_history on
hours.hour = convert_timezone(
'UTC', stg_metering_history.start_time
)
and stg_metering_history.service_type = 'SEARCH_OPTIMIZATION'
left join {{ ref('daily_rates') }}
left join {{ ref('daily_rates') }} as daily_rates
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'search optimization'
Expand Down
2 changes: 1 addition & 1 deletion models/query_history_enriched.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ query_history as (
end as _dbt_json_query_tag_meta,
case
when _dbt_json_comment_meta is not null or _dbt_json_query_tag_meta is not null then
{{ this.database }}.{{ this.schema }}.merge_objects(coalesce(_dbt_json_comment_meta, { }), coalesce(_dbt_json_query_tag_meta, { }))
{{ adapter.quote_as_configured(this.database, 'database') }}.{{ adapter.quote_as_configured(this.schema, 'schema') }}.merge_objects(coalesce(_dbt_json_comment_meta, { }), coalesce(_dbt_json_query_tag_meta, { }))
end as dbt_metadata

from {{ ref('stg_query_history') }}
Expand Down
Loading