SlideShare a Scribd company logo
1 of 41
NOSQL-KURS KVELD 2
Grafdatabaser
NoSQL-kurs for studenter ved UiO
Jørgen Braseth – jorgen.braseth@bekk.no
18. Mars 2015
AGENDA
•INTRO
•DEL 1 – TEORI: GRAFER OG GRAFDATABASER
•DEL 2 - HANDS ON
•DEL 3 - MER TEORI
•OPPSUMMERING
GRAFER OG GRAFDATABASER
HVA ER EN GRAF?
Noder og kanter
Property graph:
Noder og kanter har egenskaper
Kanter har retning
Name:
Rex
Name:
Alice
Owns
Name:
Rover
Name:
Tom
Name:
Floyd
Knows
HatesMarried to
Like
People
Dogs
Den mest naturlige måten å tenke på!
Alle grafdatabaser snakker «grafisk»
«Native» grafdatabaser lagrer dataene som en graf
HVA ER EN GRAFDATABASE
Databasen vi skal se på i kveld!
Markedsledende
«Native» grafdatabase
Eget spørrespråk: Cypher
OLTP: Laget for real time spørringer
Fungerer best på deler av datasettet
HVA ER NEO4J?
HANDS ON
HANDS ON
•DATASETTET
•SETUP
•NEO4J-ADMIN, CYPHER
•DEL 1 – NODER OG RELASJONER
•DEL 3 – OPPRETTE DATA
•DEL 4 – AVANSERTE SPØRRINGER
KVELDENS DATASETT
Noder:
36.957 Totalt, fordelt på:
14.526 produkter, med:
13.875 typer (produktnavn)
4.381 produsenter
904 opprinnelsessteder
41 flaskestørrelser
30 produktkategorier
16 innpakningsvarianter
2.684 Handlekurver
500 brukere
Relasjoner:
115.042 totalt, fordelt på:
14.526 produkter av en type
14.526 produkter i kategorier
14.526 størrelser på innpakning for produkter
14.526 opprinnelsessteder for produkter
14.526 innpakningstyper for produkter
14.363 produsenter av produkter
13.466 produkter i handlekurv
11.899 vennskap mellom brukere
2684 brukere som har kjøpt handlekruver
KVELDENS DATASETT
ProductCategory
Liquor
Type
Container
Size
Producer
UserShoppingCart
Origin
Packaging
WAS_PART_OF_CART WAS_PURCHASED_BY
IS_FRIEND_OF
SETUP
• Velg deg en server: http://bit.ly/neo4j-ip
• Gå inn i admingrensesnittet (åpne adressen i browser)
MATCH (n) RETURN n LIMIT 4
NEO4J - ADMINGRENSESNITTET
CYPHER
Deklarativt spørrespråk
ASCII-art!
Mønstergjenkjenning
HANDS ON – NODER OG RELASJONER
«Lær å tegne med Cypher»
CYPHER - NOEN NØKKELORD
MATCH - Beskriver et mønster å søke etter
WHERE - Begrenser søket
RETURN - Returnerer ønskede verdier
CREATE - Oppretter ny informasjon
MERGE - Oppretter ny informasjon – om den ikke finnes fra før
NODER I CYPHER
()
navn: ”Ole”
({navn: ”Ole”})
:Person
(:Person)
MATCH
// Alle noder
MATCH (n) RETURN n
// Fire vilkårlige noder
MATCH (n) RETURN n LIMIT 4
// Alle noder med label ”User”
MATCH (n:User) RETURN n
n
MATCH - PROPERTIES
// Alle user-noder med navn ”john doe”
MATCH (p:user {name:”john doe”}) RETURN p
// Eller
MATCH (p:user)
WHERE p.name = ”john doe”
RETURN p
p
Name:
”John Doe”
RETURN PROPERTY
// Navn på alle brukere
MATCH (p:user) RETURN p.name
p.name
John Doe
Jane Doe
Ozzy Doe
RELASJONER I CYPHER
() -- ()
() --> ()
() –[:IS_A]-> ()
IS_A
MATCH PÅ RELASJONER
p2
p2p1
p1
MATCH (p1) –[r]- (p2) RETURN p1,r,p2
MATCH (p1) --> (p2) RETURN p1,p2
MATCH PÅ RELASJONER – STØRRE MØNSTRE
p2
p1
MATCH
(p1) --> (p2) <-- (p3),
(p4)-->(p2)
RETURN p1,p2,p3,p4
p3
p4
GO DO STUFF!
http://bit.ly/oppgaver2
HANDS ON - OPPRETTE DATA
CREATE
// Oppretter node
CREATE (n1)
// Oppretter node med property
CREATE (n1 {name:”ole”})
// Eller
CREATE (n1)
SET n1.name="ole"
n1
Name:”Ole”
n1
CREATE
// Oppretter noder og relasjon
CREATE (n1) -[r:relates_to]-> (n2)
// Oppretter ny node med relasjon til ekisterende
MATCH (n1)
CREATE (n1) -[r:relates_to]-> (n2)
n2n1
n2
RELATES_TO
RELATES_TO
n1
MERGE
// 1. gang: oppretter noder og relasjon
MERGE (n1) -[:RELATES_TO]-> (n2)
// 2. gang: gjør ingen ting
MERGE (n1) -[:RELATES_TO]-> (n2)
n2n1
RELATES_TO
n2n1
RELATES_TO
GO DO STUFF!
http://bit.ly/oppgaver2
DEL 4 – AVANSERTE SPØRRINGER
AGGREGERING
// Antall noder
MATCH (n) RETURN count(n)
// Summen av pris
MATCH (n) RETURN sum(n.pris)
// Høyeste pris
MATCH (n) RETURN max(n.pris)
ANTALL HOPP I RELASJONER
qp
// Ett til to hopp
MATCH (p) –[*1..2]-> (q)
RETURN p, q
q
// Vilkårlig antall hopp
MATCH (p) –[*]-> (q)
RETURN p, q
qp q
PATHS
// Alle direkte fra n til m
MATCH p = (n)-->(m)
RETURN p
// Én korteste vei mellom m og n, men max lengde 3.
MATCH p = shortestPath( (n)-[*..3]->(m) )
RETURN p
// Alle korteste veier mellom m og n
MATCH p = allShortestPath( (n)-->(m) )
RETURN p
m
mn
n
mn
GO DO STUFF!
http://bit.ly/oppgaver2
LITT MER TEORI
Lynrask traversering av relasjoner
Relasjoner er en del av språket
Egner seg for:
Anbefalingsmotorer
Pathfinding
Mønstergjenkjenning
Prediktiv analyse
HVORFOR NEO4J?
HVA MED RELASJONSDATABASER?
Basert på relasjonsalgebra
Joins er dyrt
Ingen egentlig støtte for relasjoner
HVA MED MONGODB?
Ikke egnet for
Analyse av store deler av datasettet
Relasjonsløse data
Høyvolum skriving av data
Bruksmønstere knyttet til enkeltagregater
HVORFOR IKKE NEO4J?
?
TAKK FOR I KVELD!
Jørgen Braseth
Jorgen.braseth@bekk.no

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

BEKK - NOSQL-kurs Kveld 2

Editor's Notes

  1. Forklaring til grafikken: Noder kan ha forskjellig type Relasjoner er en egen type data
  2. OLTP: Online Transaction Processing OLAP: Online Analytical Processing
  3. Med og uten retning Type
  4. Med og uten retning Type
  5. Med og uten retning Type
  6. Med og uten retning Type
  7. Med og uten retning Type
  8. Relasjoner, relasjoner, relasjoner!
  9. Grafikken: Alt som har forskjellig struktur må i forskjellig tabell. Relasjoner er pekere til andre (eller samme tabell) Mange-til-mange krever koblingstabeller
  10. Forklaring til grafikk: Data i samme collection kan ha forskjellig format Ingen relasjoner