Git Product home page Git Product logo

data-modelling-with-cassandra's Introduction

Data Modelling with Apache Cassandra

Name: Darren Foley

Email: [email protected]


Project Index

FileName Description
event_data/ Contains event file logs from user activity on Sparkify
images/ Contains screenshots for project Documentation
.gitignore .gitignore, lists files not to be included
etl_cassandra.ipynb Python notebook with prototype etl source code
README.md Documenation
event_datafile_new.csv CSV file which contains data from event_data/ directory

Introduction

A startup called Sparkify wants to analyze the data they've been collecting on songs and user activity on their new music streaming app. The analysis team is particularly interested in understanding what songs users are listening to. Currently, there is no easy way to query the data to generate the results, since the data reside in a directory of CSV files on user activity on the app.

They'd like a data engineer to create an Apache Cassandra database which can create queries on song play data to answer the questions, and wish to bring you on the project. Your role is to create a database for this analysis. You'll be able to test your database by running queries given to you by the analytics team from Sparkify to create the results.

Table Design

In order to design tables on Apache Cassandra, you must first start with the queries that will run against the data and work back. The following three queries will be run against the data:

  1. Return the artist, song title and song's length in the music app history that was heard during sessionId = 338, and itemInSession = 4

  2. Return only the following: name of artist, song (sorted by itemInSession) and user (first and last name) for userid = 10, sessionid = 182

  3. Return every user name (first and last) in my music app history who listened to the song 'All Hands Against His Own'

For query 1, there is no requirement for a clustering column so just a simple composite key (session_id & item_in_session) is sufficient.

CREATE TABLE IF NOT EXISTS artist_song_session (
    session_id int,
    item_in_session int,
    artist text,
    first_name text,
    gender text,
    last_name text,
    length float,
    level text,
    location text,
    song text,
    user_id int,
    PRIMARY KEY (session_id, item_in_session)
    );

For query 2, we are asked to filter by user_id then session_id so they should come first in that order. Then we are asked to order by item_in_session which could benefit from being added as a clustering column.

CREATE TABLE IF NOT EXISTS song_playlist_session (
    user_id int,
    session_id int,
    item_in_session int,
    artist text,
    first_name text,
    gender text,
    last_name text,
    length float,
    level text,
    location text,
    song text,
    PRIMARY KEY ((user_id, session_id), item_in_session)
    );

For query 3, we are asked to filter by song so that should come first. Adding user_id should be sufficent for providing a unique primary key. Only a single filter in the where clause so no need for a clustering column.

CREATE TABLE IF NOT EXISTS song_list_of_users (
    song text,
    user_id int,
    artist text,
    first_name text,
    gender text,
    item_in_session int,
    last_name text,
    length float,
    level text,
    location text,
    session_id int,
    PRIMARY KEY (song, user_id)
    );

If you need more detail, check out etl_cassandra.ipynb in the repository.

data-modelling-with-cassandra's People

Contributors

thelinuxenthusiast 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.