SlideShare a Scribd company logo
1 of 29
Download to read offline
Become a super modeler
Patrick McFadin @PatrickMcFadin
Senior Solutions Architect
DataStax
Thursday, May 16, 13
Become a super modeler
Patrick McFadin @PatrickMcFadin
Senior Solutions Architect
DataStax
Thursday, May 16, 13
... the saga continues.
This is the second part of a data modeling series
Part 1:The data model is dead, long live the data model!
• Relational -> Cassandra topics
• Basic entity modeling
• one-to-many
• many-to-many
•Transaction like modeling
Thursday, May 16, 13
Becoming a super modeler
• Data model is the key to happiness
• Successful deployments depend on it
• Not just a Cassandra problem...
3
Thursday, May 16, 13
Time series - Basic
CREATE TABLE temperature (
weatherstation_id text,
event_time timestamp,
temperature text,
PRIMARY KEY (weatherstation_id,event_time)
);
• Weather station collects regular temperature
• Each weather station is a row
• Each event is a new column in a wide row
Thursday, May 16, 13
Time series - Super!
• Every second? Row would be too big
• Order by access pattern
• Partition the rows by day
- One weather station by day
5
CREATE TABLE temperature_by_day (
weatherstation_id text,
date text,
event_time timestamp,
temperature text,
PRIMARY KEY ((weatherstation_id,date),event_time)
) WITH CLUSTERING ORDER BY (event_time DESC);
Compound row key
Reverse sort: Last event, first on row
Thursday, May 16, 13
User model - basic
• Plain ole entity table
• One primary key
• Booooring
6
CREATE TABLE users (
username text PRIMARY KEY,
first_name text,
last_name text,
address1 text,
city text,
postal_code text,
last_login timestamp
);
Thursday, May 16, 13
Cassandra feature - Collections
• Collections give you three types:
- Set
- List
- Map
• Each allow for dynamic updates
• Fully supported in CQL 3
• Requires serialization so don’t go crazy
7
CREATE TABLE collections_example (
! id int PRIMARY KEY,
! set_example set<text>,
! list_example list<text>,
! map_example map<int,text>
);
Thursday, May 16, 13
Cassandra Collections - Set
• Set is sorted by CQL type comparator
8
INSERT INTO collections_example (id, set_example)
VALUES(1, {'1-one', '2-two'});
set_example set<text>
Collection name Collection type CQLType
Thursday, May 16, 13
Cassandra Collections - Set Operations
9
UPDATE collections_example
SET set_example = set_example + {'3-three'} WHERE id = 1;
UPDATE collections_example
SET set_example = set_example + {'0-zero'} WHERE id = 1;
UPDATE collections_example
SET set_example = set_example - {'3-three'} WHERE id = 1;
• Adding an element to the set
• After adding this element, it will sort to the beginning.
• Removing an element from the set
Thursday, May 16, 13
Cassandra Collections - List
• Ordered by insertion
10
list_example list<text>
Collection name Collection type CQLType
INSERT INTO collections_example (id, list_example)
VALUES(1, ['1-one', '2-two']);
Thursday, May 16, 13
Cassandra Collections - List Operations
• Adding an element to the end of a list
11
UPDATE collections_example
SET list_example = list_example + ['3-three'] WHERE id = 1;
UPDATE collections_example
SET list_example = ['0-zero'] + list_example WHERE id = 1;
• Adding an element to the beginning of a list
UPDATE collections_example
SET list_example = list_example - ['3-three'] WHERE id = 1;
• Deleting an element from a list
Thursday, May 16, 13
Cassandra Collections - Map
• Key and value
• Key is sorted by CQL type comparator
12
INSERT INTO collections_example (id, map_example)
VALUES(1, { 1 : 'one', 2 : 'two' });
map_example map<int,text>
Collection name Collection type Value CQLTypeKey CQLType
Thursday, May 16, 13
Cassandra Collections - Map Operations
• Add an element to the map
13
UPDATE collections_example
SET map_example[3] = 'three' WHERE id = 1;
UPDATE collections_example
SET map_example[3] = 'tres' WHERE id = 1;
DELETE map_example[3]
FROM collections_example WHERE id = 1;
• Update an existing element in the map
• Delete an element in the map
Thursday, May 16, 13
User model - Super!
•Take boring user table and kick it up
• Great for static + some dynamic
•Takes advantage of row level isolation
14
CREATE TABLE user_with_location (
! username text PRIMARY KEY,
! first_name text,
! last_name text,
! address1 text,
! city text,
! postal_code text,
! last_login timestamp,
! location_by_date map<timeuuid,text>
);
Thursday, May 16, 13
Super user profile - Operations
• Adding new login locations to the map
15
UPDATE user_with_location
SET last_login = now(), location_by_date = {now() : '123.123.123.1'}
WHERE username='PatrickMcFadin';
UPDATE user_with_location
USING TTL 2592000 // 30 Days
SET last_login = now(), location_by_date = {now() : '123.123.123.1'}
WHERE username='PatrickMcFadin';
• Adding new login locations to the map +TTL!
Thursday, May 16, 13
Indexing
• Indexing expresses application intent
• Fast access to specific queries
• Secondary indexes != relational indexes
• Use information you have. No pre-reads.
16
Goals:
1. Create row key for speed
2. Use wide rows for efficiency
Thursday, May 16, 13
Keyword index
• Use a word as a key
• Columns are the occurrence
• Ex: Index of tag words about videos
17
CREATE TABLE tag_index (
tag varchar,
videoid uuid,
timestamp timestamp,
PRIMARY KEY (tag, videoid)
);
VideoId1 .. VideoIdNtag
Fast
Efficient
Thursday, May 16, 13
Partial word index
• Where row size will be large
•Take one part for key, rest for columns name
18
CREATE TABLE email_index (
domain varchar,
user varchar,
username varchar,
PRIMARY KEY (domain, user)
);
INSERT INTO email_index (domain, user, username)
VALUES ('@relational.com','tcodd', 'tcodd');
User: tcodd Email: tcodd@relational.com
Thursday, May 16, 13
Partial word index - Super!
• Create partitions + partial indexes FTW
19
CREATE TABLE product_index (
store int,
part_number0_3 int,
part_number4_9 int,
count int,
PRIMARY KEY ((store,part_number0_3), part_number4_9)
);
INSERT INTO product_index (store,part_number0_3,part_number4_9,count)
VALUES (8675309,7079,48575,3);
SELECT count
FROM product_index
WHERE store = 8675309
AND part_number0_3 = 7079
AND part_number4_9 = 48575;
Compound row key!
Fast and efficient!
• Store #8675309 has 3 of part# 7079748575
Thursday, May 16, 13
Bit map index
• Multiple parts to a key
• Create a truth table of the different combinations
• Inserts == the number of combinations
- 3 fields? 7 options (Not going to use null choice)
- 4 fields? 15 options
20
Thursday, May 16, 13
Bit map index
• Find a car in a lot by variable combinations
21
Make Model Color Combination
x Color
x Model
x x Model+Color
x Make
x x Make+Color
x x Make+Model
x x x Make+Model+Color
Thursday, May 16, 13
Bit map index -Table create
• Make a table with three different key combos
22
CREATE TABLE car_location_index (
make varchar,
model varchar,
color varchar,
vehical_id int,
lot_id int,
PRIMARY KEY ((make,model,color),vehical_id)
);
Compound row key with three different options
Thursday, May 16, 13
Bit map index - Adding records
• Pre-optimize for 7 possible questions on insert
23
INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)
VALUES ('Ford','Mustang','Blue',1234,8675309);
INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)
VALUES ('Ford','Mustang','',1234,8675309);
INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)
VALUES ('Ford','','Blue',1234,8675309);
INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)
VALUES ('Ford','','',1234,8675309);
INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)
VALUES ('','Mustang','Blue',1234,8675309);
INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)
VALUES ('','Mustang','',1234,8675309);
INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)
VALUES ('','','Blue',1234,8675309);
Thursday, May 16, 13
Bit map index - Selecting records
• Different combinations now possible
24
SELECT vehical_id,lot_id
FROM car_location_index
WHERE make = 'Ford'
AND model = ''
AND color = 'Blue';
vehical_id | lot_id
------------+---------
1234 | 8675309
SELECT vehical_id,lot_id
FROM car_location_index
WHERE make = ''
AND model = ''
AND color = 'Blue';
vehical_id | lot_id
------------+---------
1234 | 8675309
8765 | 5551212
Thursday, May 16, 13
Feeling super yet?
• Use these skills. Save you they will.
• Don’t settle for boring data models
• Stay tuned for more!
25
• Final will be at the Cassandra Summit: June 11th
The worlds next top data model
Thursday, May 16, 13
Be there!!!
26
Sony, eBay, Netflix, Intuit, Spotify... the list goes on. Don’t miss it.
Here is my discount code! Use it: PMcVIP
Thursday, May 16, 13
Bonus!
• DataStax Java Driver Preso - June 12th
• Download today!
27
https://github.com/datastax/java-driver
Thursday, May 16, 13
ThankYou
Q&A
Thursday, May 16, 13

More Related Content

What's hot

Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres Monitoring
Denish Patel
 
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
 Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo... Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
Enkitec
 
Data Modeling - Enhanced ER diagrams & Mapping.pdf
Data Modeling - Enhanced ER diagrams & Mapping.pdfData Modeling - Enhanced ER diagrams & Mapping.pdf
Data Modeling - Enhanced ER diagrams & Mapping.pdf
Christalin Nelson
 

What's hot (20)

FS2 mongo reactivestreams
FS2 mongo reactivestreamsFS2 mongo reactivestreams
FS2 mongo reactivestreams
 
Deep Dive into Cassandra
Deep Dive into CassandraDeep Dive into Cassandra
Deep Dive into Cassandra
 
MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index Cookbook
 
Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizer
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres Monitoring
 
DataStax: A deep look at the CQL WHERE clause
DataStax: A deep look at the CQL WHERE clauseDataStax: A deep look at the CQL WHERE clause
DataStax: A deep look at the CQL WHERE clause
 
Polymorphic Table Functions in 18c
Polymorphic Table Functions in 18cPolymorphic Table Functions in 18c
Polymorphic Table Functions in 18c
 
Sql server performance tuning
Sql server performance tuningSql server performance tuning
Sql server performance tuning
 
Wait events
Wait eventsWait events
Wait events
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
Oracle goldengate 11g schema replication from standby database
Oracle goldengate 11g schema replication from standby databaseOracle goldengate 11g schema replication from standby database
Oracle goldengate 11g schema replication from standby database
 
Introduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache CassandraIntroduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache Cassandra
 
Understanding and Improving Code Generation
Understanding and Improving Code GenerationUnderstanding and Improving Code Generation
Understanding and Improving Code Generation
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZE
 
Cassandra Summit 2014: CQL Under the Hood
Cassandra Summit 2014: CQL Under the HoodCassandra Summit 2014: CQL Under the Hood
Cassandra Summit 2014: CQL Under the Hood
 
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
 Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo... Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
 
Data Modeling - Enhanced ER diagrams & Mapping.pdf
Data Modeling - Enhanced ER diagrams & Mapping.pdfData Modeling - Enhanced ER diagrams & Mapping.pdf
Data Modeling - Enhanced ER diagrams & Mapping.pdf
 
My SYSAUX tablespace is full - please help
My SYSAUX tablespace is full - please helpMy SYSAUX tablespace is full - please help
My SYSAUX tablespace is full - please help
 

Similar to Become a super modeler

PerlApp2Postgresql (2)
PerlApp2Postgresql (2)PerlApp2Postgresql (2)
PerlApp2Postgresql (2)
Jerome Eteve
 

Similar to Become a super modeler (20)

Cassandra Community Webinar | Become a Super Modeler
Cassandra Community Webinar | Become a Super ModelerCassandra Community Webinar | Become a Super Modeler
Cassandra Community Webinar | Become a Super Modeler
 
Do You Have the Time
Do You Have the TimeDo You Have the Time
Do You Have the Time
 
Cassandra Data Modeling
Cassandra Data ModelingCassandra Data Modeling
Cassandra Data Modeling
 
Project A Data Modelling Best Practices Part II: How to Build a Data Warehouse?
Project A Data Modelling Best Practices Part II: How to Build a Data Warehouse?Project A Data Modelling Best Practices Part II: How to Build a Data Warehouse?
Project A Data Modelling Best Practices Part II: How to Build a Data Warehouse?
 
Just in time (series) - KairosDB
Just in time (series) - KairosDBJust in time (series) - KairosDB
Just in time (series) - KairosDB
 
Sql analytic queries tips
Sql analytic queries tipsSql analytic queries tips
Sql analytic queries tips
 
Quick dive to pandas
Quick dive to pandasQuick dive to pandas
Quick dive to pandas
 
PL/SQL New and Advanced Features for Extreme Performance
PL/SQL New and Advanced Features for Extreme PerformancePL/SQL New and Advanced Features for Extreme Performance
PL/SQL New and Advanced Features for Extreme Performance
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineering
 
MariaDB Temporal Tables
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
 
mis4200notes4_2.ppt
mis4200notes4_2.pptmis4200notes4_2.ppt
mis4200notes4_2.ppt
 
Webinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
Webinar slides: Adding Fast Analytics to MySQL Applications with ClickhouseWebinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
Webinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
PerlApp2Postgresql (2)
PerlApp2Postgresql (2)PerlApp2Postgresql (2)
PerlApp2Postgresql (2)
 
Cassandra
CassandraCassandra
Cassandra
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.ppt
 
TechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - Trivadis
TechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - TrivadisTechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - Trivadis
TechEvent 2019: Uses of Row Pattern Matching; Kim Berg Hansen - Trivadis
 
Advanced data modeling with apache cassandra
Advanced data modeling with apache cassandraAdvanced data modeling with apache cassandra
Advanced data modeling with apache cassandra
 

More from Patrick McFadin

Apache cassandra & apache spark for time series data
Apache cassandra & apache spark for time series dataApache cassandra & apache spark for time series data
Apache cassandra & apache spark for time series data
Patrick McFadin
 

More from Patrick McFadin (20)

Successful Architectures for Fast Data
Successful Architectures for Fast DataSuccessful Architectures for Fast Data
Successful Architectures for Fast Data
 
Open source or proprietary, choose wisely!
Open source or proprietary,  choose wisely!Open source or proprietary,  choose wisely!
Open source or proprietary, choose wisely!
 
An Introduction to time series with Team Apache
An Introduction to time series with Team ApacheAn Introduction to time series with Team Apache
An Introduction to time series with Team Apache
 
Laying down the smack on your data pipelines
Laying down the smack on your data pipelinesLaying down the smack on your data pipelines
Laying down the smack on your data pipelines
 
Help! I want to contribute to an Open Source project but my boss says no.
Help! I want to contribute to an Open Source project but my boss says no.Help! I want to contribute to an Open Source project but my boss says no.
Help! I want to contribute to an Open Source project but my boss says no.
 
Analyzing Time Series Data with Apache Spark and Cassandra
Analyzing Time Series Data with Apache Spark and CassandraAnalyzing Time Series Data with Apache Spark and Cassandra
Analyzing Time Series Data with Apache Spark and Cassandra
 
Storing time series data with Apache Cassandra
Storing time series data with Apache CassandraStoring time series data with Apache Cassandra
Storing time series data with Apache Cassandra
 
A Cassandra + Solr + Spark Love Triangle Using DataStax Enterprise
A Cassandra + Solr + Spark Love Triangle Using DataStax EnterpriseA Cassandra + Solr + Spark Love Triangle Using DataStax Enterprise
A Cassandra + Solr + Spark Love Triangle Using DataStax Enterprise
 
Cassandra 3.0 advanced preview
Cassandra 3.0 advanced previewCassandra 3.0 advanced preview
Cassandra 3.0 advanced preview
 
Introduction to data modeling with apache cassandra
Introduction to data modeling with apache cassandraIntroduction to data modeling with apache cassandra
Introduction to data modeling with apache cassandra
 
Apache cassandra and spark. you got the the lighter, let's start the fire
Apache cassandra and spark. you got the the lighter, let's start the fireApache cassandra and spark. you got the the lighter, let's start the fire
Apache cassandra and spark. you got the the lighter, let's start the fire
 
Owning time series with team apache Strata San Jose 2015
Owning time series with team apache   Strata San Jose 2015Owning time series with team apache   Strata San Jose 2015
Owning time series with team apache Strata San Jose 2015
 
Nike Tech Talk: Double Down on Apache Cassandra and Spark
Nike Tech Talk:  Double Down on Apache Cassandra and SparkNike Tech Talk:  Double Down on Apache Cassandra and Spark
Nike Tech Talk: Double Down on Apache Cassandra and Spark
 
Apache cassandra & apache spark for time series data
Apache cassandra & apache spark for time series dataApache cassandra & apache spark for time series data
Apache cassandra & apache spark for time series data
 
Introduction to cassandra 2014
Introduction to cassandra 2014Introduction to cassandra 2014
Introduction to cassandra 2014
 
Making money with open source and not losing your soul: A practical guide
Making money with open source and not losing your soul: A practical guideMaking money with open source and not losing your soul: A practical guide
Making money with open source and not losing your soul: A practical guide
 
Time series with Apache Cassandra - Long version
Time series with Apache Cassandra - Long versionTime series with Apache Cassandra - Long version
Time series with Apache Cassandra - Long version
 
Time series with apache cassandra strata
Time series with apache cassandra   strataTime series with apache cassandra   strata
Time series with apache cassandra strata
 
Cassandra EU - Data model on fire
Cassandra EU - Data model on fireCassandra EU - Data model on fire
Cassandra EU - Data model on fire
 
Cassandra 2.0 and timeseries
Cassandra 2.0 and timeseriesCassandra 2.0 and timeseries
Cassandra 2.0 and timeseries
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 

Become a super modeler

  • 1. Become a super modeler Patrick McFadin @PatrickMcFadin Senior Solutions Architect DataStax Thursday, May 16, 13
  • 2. Become a super modeler Patrick McFadin @PatrickMcFadin Senior Solutions Architect DataStax Thursday, May 16, 13
  • 3. ... the saga continues. This is the second part of a data modeling series Part 1:The data model is dead, long live the data model! • Relational -> Cassandra topics • Basic entity modeling • one-to-many • many-to-many •Transaction like modeling Thursday, May 16, 13
  • 4. Becoming a super modeler • Data model is the key to happiness • Successful deployments depend on it • Not just a Cassandra problem... 3 Thursday, May 16, 13
  • 5. Time series - Basic CREATE TABLE temperature ( weatherstation_id text, event_time timestamp, temperature text, PRIMARY KEY (weatherstation_id,event_time) ); • Weather station collects regular temperature • Each weather station is a row • Each event is a new column in a wide row Thursday, May 16, 13
  • 6. Time series - Super! • Every second? Row would be too big • Order by access pattern • Partition the rows by day - One weather station by day 5 CREATE TABLE temperature_by_day ( weatherstation_id text, date text, event_time timestamp, temperature text, PRIMARY KEY ((weatherstation_id,date),event_time) ) WITH CLUSTERING ORDER BY (event_time DESC); Compound row key Reverse sort: Last event, first on row Thursday, May 16, 13
  • 7. User model - basic • Plain ole entity table • One primary key • Booooring 6 CREATE TABLE users ( username text PRIMARY KEY, first_name text, last_name text, address1 text, city text, postal_code text, last_login timestamp ); Thursday, May 16, 13
  • 8. Cassandra feature - Collections • Collections give you three types: - Set - List - Map • Each allow for dynamic updates • Fully supported in CQL 3 • Requires serialization so don’t go crazy 7 CREATE TABLE collections_example ( ! id int PRIMARY KEY, ! set_example set<text>, ! list_example list<text>, ! map_example map<int,text> ); Thursday, May 16, 13
  • 9. Cassandra Collections - Set • Set is sorted by CQL type comparator 8 INSERT INTO collections_example (id, set_example) VALUES(1, {'1-one', '2-two'}); set_example set<text> Collection name Collection type CQLType Thursday, May 16, 13
  • 10. Cassandra Collections - Set Operations 9 UPDATE collections_example SET set_example = set_example + {'3-three'} WHERE id = 1; UPDATE collections_example SET set_example = set_example + {'0-zero'} WHERE id = 1; UPDATE collections_example SET set_example = set_example - {'3-three'} WHERE id = 1; • Adding an element to the set • After adding this element, it will sort to the beginning. • Removing an element from the set Thursday, May 16, 13
  • 11. Cassandra Collections - List • Ordered by insertion 10 list_example list<text> Collection name Collection type CQLType INSERT INTO collections_example (id, list_example) VALUES(1, ['1-one', '2-two']); Thursday, May 16, 13
  • 12. Cassandra Collections - List Operations • Adding an element to the end of a list 11 UPDATE collections_example SET list_example = list_example + ['3-three'] WHERE id = 1; UPDATE collections_example SET list_example = ['0-zero'] + list_example WHERE id = 1; • Adding an element to the beginning of a list UPDATE collections_example SET list_example = list_example - ['3-three'] WHERE id = 1; • Deleting an element from a list Thursday, May 16, 13
  • 13. Cassandra Collections - Map • Key and value • Key is sorted by CQL type comparator 12 INSERT INTO collections_example (id, map_example) VALUES(1, { 1 : 'one', 2 : 'two' }); map_example map<int,text> Collection name Collection type Value CQLTypeKey CQLType Thursday, May 16, 13
  • 14. Cassandra Collections - Map Operations • Add an element to the map 13 UPDATE collections_example SET map_example[3] = 'three' WHERE id = 1; UPDATE collections_example SET map_example[3] = 'tres' WHERE id = 1; DELETE map_example[3] FROM collections_example WHERE id = 1; • Update an existing element in the map • Delete an element in the map Thursday, May 16, 13
  • 15. User model - Super! •Take boring user table and kick it up • Great for static + some dynamic •Takes advantage of row level isolation 14 CREATE TABLE user_with_location ( ! username text PRIMARY KEY, ! first_name text, ! last_name text, ! address1 text, ! city text, ! postal_code text, ! last_login timestamp, ! location_by_date map<timeuuid,text> ); Thursday, May 16, 13
  • 16. Super user profile - Operations • Adding new login locations to the map 15 UPDATE user_with_location SET last_login = now(), location_by_date = {now() : '123.123.123.1'} WHERE username='PatrickMcFadin'; UPDATE user_with_location USING TTL 2592000 // 30 Days SET last_login = now(), location_by_date = {now() : '123.123.123.1'} WHERE username='PatrickMcFadin'; • Adding new login locations to the map +TTL! Thursday, May 16, 13
  • 17. Indexing • Indexing expresses application intent • Fast access to specific queries • Secondary indexes != relational indexes • Use information you have. No pre-reads. 16 Goals: 1. Create row key for speed 2. Use wide rows for efficiency Thursday, May 16, 13
  • 18. Keyword index • Use a word as a key • Columns are the occurrence • Ex: Index of tag words about videos 17 CREATE TABLE tag_index ( tag varchar, videoid uuid, timestamp timestamp, PRIMARY KEY (tag, videoid) ); VideoId1 .. VideoIdNtag Fast Efficient Thursday, May 16, 13
  • 19. Partial word index • Where row size will be large •Take one part for key, rest for columns name 18 CREATE TABLE email_index ( domain varchar, user varchar, username varchar, PRIMARY KEY (domain, user) ); INSERT INTO email_index (domain, user, username) VALUES ('@relational.com','tcodd', 'tcodd'); User: tcodd Email: tcodd@relational.com Thursday, May 16, 13
  • 20. Partial word index - Super! • Create partitions + partial indexes FTW 19 CREATE TABLE product_index ( store int, part_number0_3 int, part_number4_9 int, count int, PRIMARY KEY ((store,part_number0_3), part_number4_9) ); INSERT INTO product_index (store,part_number0_3,part_number4_9,count) VALUES (8675309,7079,48575,3); SELECT count FROM product_index WHERE store = 8675309 AND part_number0_3 = 7079 AND part_number4_9 = 48575; Compound row key! Fast and efficient! • Store #8675309 has 3 of part# 7079748575 Thursday, May 16, 13
  • 21. Bit map index • Multiple parts to a key • Create a truth table of the different combinations • Inserts == the number of combinations - 3 fields? 7 options (Not going to use null choice) - 4 fields? 15 options 20 Thursday, May 16, 13
  • 22. Bit map index • Find a car in a lot by variable combinations 21 Make Model Color Combination x Color x Model x x Model+Color x Make x x Make+Color x x Make+Model x x x Make+Model+Color Thursday, May 16, 13
  • 23. Bit map index -Table create • Make a table with three different key combos 22 CREATE TABLE car_location_index ( make varchar, model varchar, color varchar, vehical_id int, lot_id int, PRIMARY KEY ((make,model,color),vehical_id) ); Compound row key with three different options Thursday, May 16, 13
  • 24. Bit map index - Adding records • Pre-optimize for 7 possible questions on insert 23 INSERT INTO car_location_index (make,model,color,vehical_id,lot_id) VALUES ('Ford','Mustang','Blue',1234,8675309); INSERT INTO car_location_index (make,model,color,vehical_id,lot_id) VALUES ('Ford','Mustang','',1234,8675309); INSERT INTO car_location_index (make,model,color,vehical_id,lot_id) VALUES ('Ford','','Blue',1234,8675309); INSERT INTO car_location_index (make,model,color,vehical_id,lot_id) VALUES ('Ford','','',1234,8675309); INSERT INTO car_location_index (make,model,color,vehical_id,lot_id) VALUES ('','Mustang','Blue',1234,8675309); INSERT INTO car_location_index (make,model,color,vehical_id,lot_id) VALUES ('','Mustang','',1234,8675309); INSERT INTO car_location_index (make,model,color,vehical_id,lot_id) VALUES ('','','Blue',1234,8675309); Thursday, May 16, 13
  • 25. Bit map index - Selecting records • Different combinations now possible 24 SELECT vehical_id,lot_id FROM car_location_index WHERE make = 'Ford' AND model = '' AND color = 'Blue'; vehical_id | lot_id ------------+--------- 1234 | 8675309 SELECT vehical_id,lot_id FROM car_location_index WHERE make = '' AND model = '' AND color = 'Blue'; vehical_id | lot_id ------------+--------- 1234 | 8675309 8765 | 5551212 Thursday, May 16, 13
  • 26. Feeling super yet? • Use these skills. Save you they will. • Don’t settle for boring data models • Stay tuned for more! 25 • Final will be at the Cassandra Summit: June 11th The worlds next top data model Thursday, May 16, 13
  • 27. Be there!!! 26 Sony, eBay, Netflix, Intuit, Spotify... the list goes on. Don’t miss it. Here is my discount code! Use it: PMcVIP Thursday, May 16, 13
  • 28. Bonus! • DataStax Java Driver Preso - June 12th • Download today! 27 https://github.com/datastax/java-driver Thursday, May 16, 13