A music streaming startup, Sparkify, has grown their user base and song database and want to move their processes and data onto the cloud. Their data resides in S3, in a directory of JSON logs on user activity on the app, as well as a directory with JSON metadata on the songs in their app.
As their data engineer, we are tasked with building an ETL pipeline that extracts their data from S3, stages them in Redshift, and transforms data into a set of dimensional tables for their analytics team to continue finding insights into what songs their users are listening to. You'll be able to test your database and ETL pipeline by running queries given to you by the analytics team from Sparkify and compare your results with their expected results.
--> First, we'll need an AWS Redshift Cluster up and running.
--> Now, fill up the params of Redshift Cluster in the dwh.cfg file.
-
Run
create_tables.pyfile. -
Run
etl.pyfile.
--> Now the analytics tables are ready on the Redshift Cluster for our business user to query our data get useful insights.
The first dataset is a subset of real data from the Million Song Dataset. Each file is in JSON format and contains metadata about a song and the artist of that song. The files are partitioned by the first three letters of each song's track ID. For example, here are file paths to two files in this dataset.
song_data/A/B/C/TRABCEI128F424C983.json
song_data/A/A/B/TRAABJL12903CDCF1A.json
And below is an example of what a single song file, TRAABJL12903CDCF1A.json, looks like.
{"num_songs": 1, "artist_id": "ARJIE2Y1187B994AB7", "artist_latitude": null, "artist_longitude": null, "artist_location": "", "artist_name": "Line Renaud", "song_id": "SOUPIRU12A6D4FA1E1", "title": "Der Kleine Dompfaff", "duration": 152.92036, "year": 0}
The second dataset consists of log files in JSON format generated by this event simulator based on the songs in the dataset above. These simulate app activity logs from an imaginary music streaming app based on configuration settings.
The log files in the dataset you'll be working with are partitioned by year and month. For example, here are file paths to two files in this dataset.
log_data/2018/11/2018-11-12-events.json
log_data/2018/11/2018-11-13-events.json
Here we have chosen Star schema for our analytical tables. The reason to choose Star Schema is that a star schema can be more efficient to query than a snowflake schema, because there are fewer JOINs between tables.
Fact Table: songplays Dimension Tables: users, songs, artists, time_of_use
Here we have chosen song_id and artist_id as distkey for our Redshift cluser since we are our main focus is on the query that which songs users are listening to most.
-
create_tables.py: It creates a connection to the Redshift database using params fromdwh.cfgand drops any existing tables with the same name and creates our staging tables and analytical tables. -
etl.py: First it creates a connection to the Redshift database. Then copies all log and song JSON files into staging tables then inserts the data into analytical tables in our Redshift database. -
sql_quueries.py: It has all the drop, create and insert into table queries for both of our staging tables and analytical tables. -
dwh.cfg: It has all the params we need to establish the connection to our Redshift Database. Make sure to fill this up before running any files. -
dashboard: I have made a tableau dashboard using some sample queries.
dwh.cfg:
[CLUSTER]
HOST=
DB_NAME=
DB_USER=
DB_PASSWORD=
DB_PORT=
[IAM_ROLE]
ARN=''
[S3]
LOG_DATA='s3://udacity-dend/log_data'
LOG_JSONPATH='s3://udacity-dend/log_json_path.json'
SONG_DATA='s3://udacity-dend/song_data'