Giter VIP home page Giter VIP logo

dend-project_4_data_lake's Introduction

Project: Data Lake

Introduction

A music streaming startup, 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 aimed at establishing an ETL pipeline to extract song and log data hosted in an S3 bucket " s3a://udacity-dend ".
  • Then Spark is used to process the data via pyspark into different parquet formatted fact and dimensional tables ( star schema ) that will be loaded back into s3,
  • This should improve the performance and support provided to the analysts' team to glean insights on the listeners' behavior, songs performance, and a lot more.

Datasets

Sparkify provided two datasets that reside in S3. Here are the S3 links for each:

  • Song data: s3://udacity-dend/song_data
  • Log data: s3://udacity-dend/log_data

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 are partitioned by year and month.

  • Sample Data:

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

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

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

ETL Pipeline

  • The Extraction step is straight forward with pyspark
  • The transformation is needed to fix some issues with the data like:
    • The timestamp is originally in uniz format that shoudl be coverted to a readable timestamp format from which the year, month, day, hour entries can be extracted.
    • The step of fixing the timestamp is involved in the creation of the time dimension table and the songplays fact table.
    • Removing duplicates has been conducted as well as part of the transformation.

Star Schema Database

OLAP queries on the songplays fact table are straightforward, and additional fields can be easily accessed in the four dimension tables users, songs, artists, and time. A star schema is a robust choice for this use case since it's streamlined through denormalization and simple queries are valid to get the required results.

Fact Table

  1. songplays - records in event data associated with song plays i.e. records with page NextSong
  • Fields songplay_id, timestamp, user_id, level, song_id, artist_id, session_id, location, user_agent, month, year

Dimension Tables

  1. users - users in the app
  • Fields userId, firstName, lastName, gender, level
  1. songs - songs in music database
  • Fields song_id, title, artist_id, artist_name, year, duration
  1. artists - artists in music database
  • Fields artist_id, name, location, lattitude, longitude
  1. time - timestamps of records in songplays broken down into specific units
  • Fields datetime, Hour, DOW, DOM, DOY, week, Month, year,

Project Files

etl.py

This is our main engine, by running it: * The song and log data are loaded from the s3 bucket, * Processed and transformed to create the fact and dimension tables of the star schema and * Finally, the tables are written into parquet files and uploaded to another s3 bucket.

etl_locat_test.py

This is to try and test the scirpt locally before implemnting it on an EMR context.

dl.cfg:

This file holds the aws credentials.

How to run locally:

Installation:

In the terminal run the following commands

$ unzip data/log_data.zip -d song_data
$ unzip data/song_data.zip -d events
$ mkdir output_data

$ pip install -r requirements.txt

Execution:

  1. Set environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
  2. Run ETL pipeline : python etl.py

How to run on an EMR cluster:

  1. Create an AWS account
  2. Create an EMR cluster
  3. Create a S3 bucket to recieve the output data
  4. SSH into the Cluster's master node, scp the etl.py file into it and spark-submit etl.py file.

dend-project_4_data_lake's People

Contributors

osamahamdyosman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.