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

Handle missing remaining balance #120

Merged
merged 5 commits into from
Jun 21, 2023
Merged
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
18 changes: 10 additions & 8 deletions models/daily_rates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ current_account()

with
dates_base as (
select dateadd(
'day',
'-' || row_number() over (order by null),
dateadd('day', '+1', current_date)
) as date
from table(generator(rowcount => (365 * 3)))
select date_day as date from (
{{ dbt_utils.date_spine(
datepart="day",
start_date="'2018-01-01'",
end_date="dateadd(day, 1, current_date)"
)
}}
)
),

rate_sheet_daily_base as (
Expand Down Expand Up @@ -119,15 +121,15 @@ rates_w_overage as (
) as currency,
base.usage_type like 'overage-%' as is_overage_rate,
replace(base.usage_type, 'overage-', '') as associated_usage_type,
coalesce(remaining_balance_daily.is_account_in_overage, latest_remaining_balance_daily.is_account_in_overage) as _is_account_in_overage,
coalesce(remaining_balance_daily.is_account_in_overage, latest_remaining_balance_daily.is_account_in_overage, false) as _is_account_in_overage,
case
when _is_account_in_overage and is_overage_rate then 1
when not _is_account_in_overage and not is_overage_rate then 1
else 0
end as rate_priority

from base
inner join latest_remaining_balance_daily
left join latest_remaining_balance_daily on latest_remaining_balance_daily.date is not null
left join remaining_balance_daily
on base.date = remaining_balance_daily.date
left join rate_sheet_daily
Expand Down
2 changes: 1 addition & 1 deletion models/hourly_spend.sql
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ materialized_view_spend_hourly as (
left join {{ ref('daily_rates') }}
on hours.hour::date = daily_rates.date
and daily_rates.service_type = 'COMPUTE'
and daily_rates.usage_type = 'materialized view' {# TODO: need someone to confirm whether its materialized 'view' or 'views' #}
and daily_rates.usage_type = 'materialized views'
group by 1, 2, 3, 4
),

Expand Down