Skip to content

Automating and monitoring the data warehouse ETL pipeline using Apache Airflow.

Notifications You must be signed in to change notification settings

fahadfiaz/Data-Pipeline-with-Apache-Airflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Data Pipelines with Airflow


A music streaming startup, Sparkify's, has decided to introduce more automation and monitoring to their Amazon Redshift Data Warehouse ETL pipelines using Apache Airflow. This project creates the required ETL pipeline where the data resides in S3 and processed in Sparkify's data warehouse in Amazon Redshift.

Introduction


This project create a high grade data pipelines for music streaming startup named Sparkify's. The data pipeline are dynamic and built from reusable tasks, can be monitored, and allow easy backfills. As, the data quality plays a big part when analyses are executed on top the data warehouse, tests against the company datasets after the ETL steps have been executed to catch any discrepancies in the datasets.

The source data resides in S3 and needs to be processed in Sparkify's data warehouse in Amazon Redshift. The source datasets consist of JSON logs that tell about user activity in the application and JSON metadata about the songs the users listen to.

Datasets


Following two datasets resides in S3 bucket:

  1. 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 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}

  2. 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 activity logs from a music streaming app based on specified configurations. 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

ETL pipeline


Apache Airflow is used to organizes, schedule and orchestrate the ELT pipeline. Internally, it uses Directed Acyclic Graphs (DAGs) to collect Tasks together, organize with dependencies and relationships to say how they should run.

The custom operators are created to perform tasks such as staging the data, filling the data warehouse, and running checks on the data as the final step. The helpers class contains all the SQL transformations.

Our DAG along with task dependencies looks like this:

DAG

Star Schema


Star schema is used to build our data model and optimized for queries for the song play analysis. This includes the following tables:

Fact Table:
  • The songplays fact table records in event data associated with song plays
Dimension Tables:
  • The users dimension table records users in the app
  • The songs dimension table records songs in music database
  • The artists dimension table records artists in music database
  • The time dimension table stores timestamps of records in songplays broken down into specific units

Description of the Project Files


The Project has two directories named dags and plugins.

Files in dags directory:
  1. create_tables.sql : This file contains all the sql statements to create the staging tables and star schema fact and dimensional tables
  2. sparkify_etl_dag.py: This file contains the configuration to run etl pipeline. It runs four different operators that will stage the data, transform the data, and run checks on data quality
Files in plugins directory:
  1. stage_redshift.py : This file defines the StageToRedshiftOperator that copy JSON data from S3 to staging tables in the Amazon Redshift Warehouse
  2. load_fact.py: This file defines the LoadFactOperator that loads a data from staging tables to the fact table
  3. load_dimension.py: This file defines the LoadDimensionOperator that loads a data from staging tables to the dimension tables
  4. data_quality.py: This file defines the DataQualityOperator that performs data quality checks on tables
  5. sql_queries.py: This file defines the SQL statements for the etl pipeline

Instructions to run python scripts


  • Create an IAM User in AWS.
  • Create a redshift cluster in AWS.
  • Connect Airflow with AWS and AWS Redshift Cluster
  • Run create_tables.sql file on AWS Redshift Cluster
  • Run sparkify_etl_dag.py file to execute the ETL pipeline

About

Automating and monitoring the data warehouse ETL pipeline using Apache Airflow.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages