Skip to content

ScottFitzgerald83/data-lake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Lake

Udacity Data Engineer Nanodegree - Project 4

Sparkify has grown their user base and song database even more and want to move their data warehouse to a data lake. 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.

This project entails building an ETL pipeline that extracts their data from S3, processes them using Spark, and loads the data back into S3 as a set of dimensional tables. This will allow their analytics team to continue finding insights in what songs their users are listening to.

Song Dataset

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 filepaths 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}

Log Dataset

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 filepaths to two files in this dataset.

  • log_data/2018/11/2018-11-12-events.json
  • log_data/2018/11/2018-11-13-events.json

Below is an example of what the data in a log file, 2018-11-12-events.json, looks like. log data

Schema for Song Play Analysis

Using the song and log datasets, you'll need to create a star schema optimized for queries on song play analysis. This includes the following tables.

Fact Table

table name: songplays

description: records in log data associated with song plays i.e. records with page NextSong

column type description
songplay_id monotonically_increasing_id unique identifier for songplay
start_time timestamp TODO
user_id integer TODO
level varchar TODO
song_id varchar TODO
artist_id varchar TODO
session_id integer TODO
location varchar TODO
user_agent varchar TODO

Dimension Tables

users - users in the app

column type description
user_id integer TODO
first_name varchar TODO
last_name varchar TODO
gender varchar TODO
level varchar TODO

songs - songs in music database

column type description
song_id varchar TODO
title varchar TODO
artist_id varchar TODO
year varchar TODO
duration varchar TODO

artists - artists in music database

column type description
artist_id varchar TODO
name varchar TODO
location varchar TODO
latitude varchar TODO
longitude varchar TODO

time - timestamps of records in songplays broken down into specific units

column type description
start_time integer TODO
hour integer TODO
day integer TODO
week integer TODO
month integer TODO
year integer TODO
weekday integer TODO

Rationale for schema design

users: there should be a unique row per user, with no duplicates for user_id. It's possible that a user shows up in both the free and paid tiers, but these are not considered duplicates.

songs: duplicates on song_id are dropped here as well as they don't convey any additional useful information. We don't need multiple rows for the same song.

artists: same thing as songs, drop any duplicate artist_id

time: not sure what the purpose of this table has been throughout these projects, but this is just a list of date parts for each songplay from the log events. Duplicates are not dropped here, as multiple users may listen at the same time. That said, there's nothing intrinsic to this table alone that gives any meaning to any of the timestamps, whether or not they are duplicates.

songplays: These are log events where the page column of the event is equal to NextSong. These pages indicate a discrete songplay. Duplicates are dropped for the column start_time are dropped if they exist.

ETL explanation

The job reads in a config file to get the AWS credentials and target S3 bucket. From there, it creates a SparkSession, reads song data and log events from a destination bucket. It does a number of transformations to get the appropriate dataframe structures, and writes to the target bucket.

About

Data Engineering nanodegree project 4

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages