Skip to content

Commit df0c4ed

Browse files
author
Student
committed
add initial dimensions
1 parent 2df8380 commit df0c4ed

3 files changed

Lines changed: 167 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
with
2+
3+
calendar_dates as (
4+
5+
{{ dbt_utils.date_spine(
6+
datepart="day",
7+
start_date="cast('2018-01-01' as date)",
8+
end_date="cast('2050-12-31' as date)"
9+
)
10+
}}
11+
12+
),
13+
14+
final as (
15+
16+
select
17+
-- Surrogate Key
18+
{{ dbt_utils.generate_surrogate_key(
19+
['date(date_day)']
20+
)}} as calendar_date_sk,
21+
22+
-- Descriptive Values
23+
date_day::date as date_day,
24+
extract(isodow from date_day) as day_of_week_number,
25+
extract(day from date_day) as day_of_month_number,
26+
extract(doy from date_day) as day_of_year_number,
27+
28+
extract(week from date_day) as week_of_year_number,
29+
extract(month from date_day) as month_of_year_number,
30+
extract(quarter from date_day) as quarter_of_year_number,
31+
extract(year from date_day) as year_number,
32+
33+
to_char(date_day, 'Dy') as short_weekday_name,
34+
to_char(date_day, 'Day') as full_weekday_name,
35+
to_char(date_day, 'Mon') as short_month_name,
36+
to_char(date_day, 'Month') as full_month_name,
37+
38+
concat(to_char(date_day, 'Mon'), ' ', extract(year from date_day)) as short_month_year,
39+
40+
concat(to_char(date_day, 'Month'), ' ', extract(year from date_day)) as full_month_year
41+
42+
from calendar_dates
43+
44+
)
45+
46+
select * from final
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
with
2+
3+
games as (
4+
select * from {{ ref('stg_nba__games') }}
5+
),
6+
7+
final as (
8+
9+
select
10+
-- Surrogate Key
11+
{{ dbt_utils.generate_surrogate_key(
12+
['game_id']
13+
)}} as game_sk,
14+
15+
-- Descriptive Values
16+
game_id,
17+
home_team_id,
18+
home_team_name,
19+
away_team_id,
20+
away_team_name,
21+
league_id,
22+
league_name,
23+
season,
24+
25+
status_long,
26+
status_short,
27+
country_id,
28+
country_code,
29+
country_name,
30+
timezone,
31+
32+
-- Booleans
33+
is_home_team_win,
34+
is_away_team_win,
35+
36+
-- Dates
37+
game_date,
38+
game_time,
39+
game_at,
40+
created_at
41+
42+
/*
43+
-- DW Values
44+
null as dw_is_active,
45+
null as dw_created_at,
46+
null as dw_updated_at,
47+
null as dw_is_deleted,
48+
null as dw_deleted_at
49+
*/
50+
51+
from games
52+
53+
)
54+
55+
select * from final
56+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
with
2+
3+
teams as (
4+
select * from {{ ref('stg_nba__teams') }}
5+
),
6+
7+
franchises as (
8+
select * from {{ ref('stg_gsheets__franchise_actives') }}
9+
),
10+
11+
managers as (
12+
select * from {{ ref('stg_gsheets__franchise_general_managers') }}
13+
),
14+
15+
coaches as (
16+
select * from {{ ref('stg_gsheets__franchise_head_coaches') }}
17+
),
18+
19+
final as (
20+
21+
select
22+
-- Surrogate Key
23+
{{ dbt_utils.generate_surrogate_key(
24+
['teams.team_id',
25+
'franchises.team_id',
26+
'coaches.head_coach_id',
27+
'managers.general_manager_id']
28+
)}} as team_sk,
29+
30+
-- Descriptive Values
31+
teams.team_id,
32+
teams.team_name,
33+
teams.team_logo_url,
34+
teams.country_name,
35+
franchises.year_started,
36+
coaches.head_coach,
37+
managers.general_manager,
38+
managers.division,
39+
managers.conference
40+
41+
/*
42+
-- DW Values
43+
null as dw_is_active,
44+
null as dw_created_at,
45+
null as dw_updated_at,
46+
null as dw_is_deleted,
47+
null as dw_deleted_at
48+
*/
49+
50+
from teams
51+
52+
left join franchises
53+
on teams.team_name = franchises.franchise_name
54+
and franchises.is_current
55+
56+
left join managers
57+
on teams.team_name = managers.team_name
58+
59+
left join coaches
60+
on teams.team_name = coaches.team_name
61+
62+
)
63+
64+
select * from final
65+

0 commit comments

Comments
 (0)