-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstg_boardgames__rankings.sql
44 lines (35 loc) · 1018 Bytes
/
stg_boardgames__rankings.sql
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
35
36
37
38
39
40
41
42
43
44
{{ config(
tags="daily"
) }}
with
rankings as (
select * from {{ ref('rankings') }}
),
final as (
select
dbt_scd_id as ranking_key,
id as boardgame_id,
"Name" as boardgame_name,
"Year" as boardgame_year_published,
"Rank" as boardgame_rank,
"Average" as boardgame_avg_rating,
round(case
when "Bayes average" < 1 then '{{ var("min_accepted_num") }}'
else "Bayes average"
end, 2) as boardgame_bayes_avg_rating,
"Users rated" as boardgame_total_reviews,
CONCAT('https://boardgamegeek.com', url) as boardgame_url,
"Thumbnail" as boardgame_thumbnail,
case
when dbt_valid_to is NULL then true
else false
end as is_current,
updated_at,
dbt_valid_from as valid_from,
coalesce(
dbt_valid_to,
cast( '{{ var("the_distant_future") }}' as timestamp)
) as valid_to
from rankings
)
select * from final