Skip to content

Commit

Permalink
Refactor album and genre models with gold fact review addition (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcrosher authored Jan 26, 2025
1 parent 49c6b4b commit 1c6a21e
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 101 deletions.
89 changes: 0 additions & 89 deletions models/albums_properties.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,54 +52,6 @@ models:
tests:
- not_null

- name: silver_dim_album
description: a dimension table of all albums reviewed
columns:
- name: youtube_id
description: The PK of the table, the YouTube album ID
data_type: string
tests:
- not_null
- unique
- name: spotify_id
description: The Spotify album ID
data_type: string
- name: apple_music_id
description: The Apple Music album ID
data_type: string
- name: tidal_id
description: The Tidal album ID
data_type: string
- name: amazon_music_id
description: The Amazon Music album ID
data_type: string
- name: qobuz_id
description: The Qobuz album ID
data_type: string
- name: deezer_id
description: The Deezer album ID
data_type: string
- name: album
description: The name of the album
data_type: string
tests:
- not_null
- name: artist
description: The name of the album artist
data_type: string
tests:
- not_null
- name: release_date
description: Year that the album was released
data_type: string
tests:
- not_null
- name: wikipedia_url
description: URL of the Wikipedia article for this album
data_type: string
tests:
- not_null

- name: silver_dim_date
description: a date dimension, materialised as a table using the dbt_date.get_date_dimension macro
columns:
Expand Down Expand Up @@ -212,47 +164,6 @@ models:
data_type: date
quote: true

- name: silver_dim_genre
description: a dimension table of all genres
columns:
- name: genre
description: The genre of the album
data_type: string
- name: subgenre
description: The subgenre of the album
data_type: string

- name: gold_fact_review
columns:
- name: Album
description: The album being rated
data_type: string
quote: true
- name: Artist
description: The album artist
data_type: string
quote: true
- name: Release Year
description: The year of release
data_type: int
quote: true
- name: My Rating
description: The rating I gave
data_type: bigint
quote: true
- name: Global Rating
description: The global rating
data_type: double
quote: true
- name: My Relative Rating
description: My rating indexed against the global rating
data_type: decimal(5,2)
quote: true
- name: Review Date
description: The date of the review
data_type: date
quote: true

exposures:
- name: 1001_albums_review_dashboard
type: dashboard
Expand Down
5 changes: 4 additions & 1 deletion models/gold_fact_review.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ select
da.album as `Album`,
da.artist as `Artist`,
cast(da.release_date as int) as `Release Year`,
da.genres as `Genres`,
dg.genres as `Genres`,
fr.my_rating as `My Rating`,
fr.global_rating as `Global Rating`,
cast(
Expand All @@ -15,5 +15,8 @@ from
inner join
{{ ref("silver_dim_album") }} as da
on fr.youtube_id = da.youtube_id
inner join
{{ ref("silver_dim_genre") }} as dg
on fr.youtube_id = dg.youtube_id
order by
fr.review_date desc
36 changes: 36 additions & 0 deletions models/gold_fact_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2
models:
- name: gold_fact_review
columns:
- name: Album
description: The album being rated
data_type: string
quote: true
- name: Artist
description: The album artist
data_type: string
quote: true
- name: Release Year
description: The year of release
data_type: int
quote: true
- name: Genres
description: The genres of the album
data_type: string
quote: true
- name: My Rating
description: The rating I gave
data_type: bigint
quote: true
- name: Global Rating
description: The global rating
data_type: double
quote: true
- name: My Relative Rating
description: My rating indexed against the global rating
data_type: decimal(5,2)
quote: true
- name: Review Date
description: The date of the review
data_type: date
quote: true
49 changes: 49 additions & 0 deletions models/silver_dim_abum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: 2
models:
- name: silver_dim_album
description: a dimension table of all albums reviewed
columns:
- name: youtube_id
description: The PK of the table, the YouTube album ID
data_type: string
tests:
- not_null
- unique
- name: spotify_id
description: The Spotify album ID
data_type: string
- name: apple_music_id
description: The Apple Music album ID
data_type: string
- name: tidal_id
description: The Tidal album ID
data_type: string
- name: amazon_music_id
description: The Amazon Music album ID
data_type: string
- name: qobuz_id
description: The Qobuz album ID
data_type: string
- name: deezer_id
description: The Deezer album ID
data_type: string
- name: album
description: The name of the album
data_type: string
tests:
- not_null
- name: artist
description: The name of the album artist
data_type: string
tests:
- not_null
- name: release_date
description: Year that the album was released
data_type: string
tests:
- not_null
- name: wikipedia_url
description: URL of the Wikipedia article for this album
data_type: string
tests:
- not_null
2 changes: 0 additions & 2 deletions models/silver_dim_album.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ with cte_all as (
h.album.name as album,
h.album.artist,
h.album.releasedate as release_date,
h.album.genres,
h.album.wikipediaurl as wikipedia_url,
h.generatedat as reviewed_on
from
Expand Down Expand Up @@ -38,7 +37,6 @@ select
album,
artist,
release_date,
genres,
wikipedia_url
from
cte_dedup
10 changes: 1 addition & 9 deletions models/silver_dim_genre.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ cte_dedup as (
cte_all
order by
reviewed_on
),

cte_genres as (
select distinct
genre,
subgenres
from
cte_dedup lateral view explode(genres) as genre
)

select *
from cte_genres
from cte_dedup
14 changes: 14 additions & 0 deletions models/silver_dim_genre.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
models:
- name: silver_dim_genre
description: a dimension table of all genres
columns:
- name: youtube_id
description: The YouTube album ID
data_type: string
- name: genres
description: The genre of the album
data_type: string
- name: subgenre
description: The subgenre of the album
data_type: string

0 comments on commit 1c6a21e

Please sign in to comment.