teil xi nosql i/_/kapitel11.pdf · nosql 1. motivation f¨ur nosql 2. datenmodelle fur nosql¨ 3....

54
Teil XI NoSQL

Upload: others

Post on 13-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Teil XI

NoSQL

Page 2: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

NoSQL

1. Motivation fur NoSQL

2. Datenmodelle fur NoSQL

3. KV-Stores und Wide Column

4. Document Stores

5. Graph Stores

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–1

Page 3: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Motivation fur NoSQL

Page 4: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Motivation fur NoSQL

NoSQL = Not only SQL

• im Umfeld vieler aktueller Buzzwords

• NoSQL

• Big Data

• BASE

• ....

• oft einfach als Etikett einer Neuentwicklung eines DBMS

pauschal vergeben

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–2

Page 5: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Was ist NoSQL?

• SQL - No!

• SQL-Datenbanken sind zu komplex, nicht skalierbar, ...

• man braucht was einfacheres!

• Not only SQL

• SQL-Datenbanken haben zu wenig (oder die falsche)

Funktionalitat

• Operationen auf Graphen, Data Mining Operatoren, ...

• New SQL

• SQL-Datenbanken sind (software-technisch) in die Jahre

gekommen

• eine neue Generation von DBMS muss her (ohne die

etablierten Vorteile von SQL zu ignorieren)

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–3

Page 6: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Kritik an RDBMS / SQL

• nicht skalierbar• Normalisierung von Relationen, viele Integritatsbedingungen zu

prufen

• kann man in RDBMS auch vermeiden!

• starre Tabellen nicht flexibel genug• schwach typisierte Tabellen (Tupel weichen in den tatsachlich

genutzten Attributen ab)• viele Nullwerte wenn alle potentiellen Attribute definiert

• alternativ Aufspaltung auf viele Tabellen

• Schema-Evolution mit alter table skaliert bei Big Data nicht

• tatsachlich in vielen Anwendungen ein Problem

• Integration von spezifischen Operationen (Graphtraversierung,

Data-Mining-Primitive) mit Stored Procedures zwar moglich

fuhrt aber oft zu schwer interpretierbarem Code

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–4

Page 7: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Datenmodelle fur NoSQL

Page 8: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Datenmodelle fur NoSQL

• KV-Stores

• Wide Column Stores

• Dokumenten-orientierte Datenhaltung

• Graph-Speicher

• ....

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–5

Page 9: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Anfragesprachen fur NoSQL

• unterschiedliche Ansatze:

• einfache funktionale API

• Programmiermodell fur parallele Funktionen

• angelehnt an SQL-Syntax

• ....

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–6

Page 10: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

KV-Stores und Wide Column

Page 11: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Datenmodell: Key-Value-Stores

• Key-Value-Store: binare Relationen, bestehend aus

• einem Zugri↵sschlussel (dem Key) und

• den Nutzdaten (dem Value)

• Nutzdaten

• binare Daten ohne Einschrankung,

• Dateien oder Dokumente,

! Document Databases

• oder schwachstrukturierte Tupel

! Wide Column Store

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–7

Page 12: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Anfragen an KV-Stores

• einfache API

store.put(key, value)

value = store.get(key)

store.delete(key)

• aufgesetzte hoherer Sprache angelehnt an SQL

• Map-Reduce

• Framework zur Programmierung paralleler Datenaggregation

auf KV-Stores

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–8

Page 13: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Beispielsysteme fur KV-Stores

• Amazon DynamoDB

• Riak

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–9

Page 14: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Datenmodell: Wide Column

• Basisidee: KV-Store mit schwachstrukturiertem Tupel als

Value

• Value = Liste von Attributname-Attributwert-Paaren

• schwache Typisierung fur Attributwerte (auch

Wiederholgruppen)

• nicht alle Eintrage haben die selben Attributnamen

• o↵ene Tupel

• Hinzufugen eines neuen Attributs unproblematisch

• Nullwerte aus SQL ersetzt durch fehlende Eintrage

• Beispiel in DynamoDB

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–10

Page 15: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Datenmodell: Wide Column /2

Key Value (Attributliste)

WeinID = 1 Name = Zinfandel Farbe = Rot Jahrgang = 2004

WeinID = 2 Name = Pinot Noir Weingut = {Creek,Helena}

WeinID = 3 Name = Chardonnay Jahrgang = 2002 Weingut = Bighorn

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–11

Page 16: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Anfragen bei Wide Column

• CRUD: Create, Read, Update und Delete

• in DynamoDB

• PutItem fugt einen neuen Datensatz mit der gegebenen

Attribut-Wert-Liste ein bzw. ersetzt einen existierenden

Datensatz mit gleichem Schlussel.

• GetItem-Operation liest alle Felder eines uber einen

Primarschlussel identifizierten Datensatzes.

• Scan erlaubt einen Lauf uber alle Datensatze mit Angabe von

Filterkriterien.

• Aufruf uber HTTP oder aus Programmiersprachen heraus

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–12

Page 17: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Beispielanfrage in DynamoDB

POST / HTTP/1.1

x-amz-target: DynamoDB 20111205.GetItem

content-type: application/x-amz-json-1.0

{ "TableName": "Weine",

" Key ":

{ "HashKeyElement": {"N": "1" }"RangeKeyElement": {"S": "Zinfandel" }

},"AttributesToGet": ["Farbe", "Jahrgang"],

"ConsistentRead": false

}

• Primarschlussel (HashKeyElement) ist numerisch (N)

• Feld Name ist Bereichsschlussel vom Typ String (S)

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–13

Page 18: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Beispielanfrage in DynamoDB: Ergebnis

HTTP/1.1 200

x-amzn-RequestId: ...

content-type: application/x-amz-json-1.0

content-length: ...

{"Item":{"Farbe": {"S": "Rot" },"Jahrgang": {"N": "2004" }},

"ConsumedCapacityUnits": 0.5

}

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–14

Page 19: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Document Stores

Page 20: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Datenmodell: dokumentenorientierte Speicherung

• Basisidee: KV-Store mit (hierarchisch) strukturiertem

Dokument als Value

• strukturiertes Dokument:• JSON-Format

• geschachtelte Wide Column-Daten

• XML (eher unublich auf KV-Stores)

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–15

Page 21: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Beispiel fur Dokument in JSON

{"id" : "kritiker08154711",

"Name" : "Bond",

"Vorname" : "Jamie",

"Alter" : 42,

"Adresse" :

{"Strasse" : "Breiter Weg 1",

"PLZ" : 39007,

"Stadt" : "Machdeburch"

},"Telefon" : [7007, 110]

}

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–16

Page 22: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Anfragen bei dokumentenorientierter Speicherung

• CRUD erweitert um dokumentspezifische Suche

• Beispiele (MongoDB mit BSON statt JSON)

db.kritiker.find({Name: "Bond"})db.kritiker.find({Alter: 40})db.kritiker.find({Alter{$lt: 50}})db.kritiker.find({Name: "Bond", Alter: 42})db.kritiker.find($or[{Name: "Bond"},

{ Alter: 42}}])

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–17

Page 23: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Beispielsysteme fur dokumentenorientierte Speicherung

• MongoDB

• CouchDB

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–18

Page 24: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Graph Stores

Page 25: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Graph-Datenmodelle: Grundlagen

• spezielle Form der Datenreprasentation = Graphen, insb.

Beziehungen zwischen Objekten

• Anwendungsgebiete:

• Transportnetze

• Networking: Email-Verkehr, Mobilfunk-Nutzer

• Soziale Netzwerke: Eigenschaften, Communities

• Web: Verlinkte Dokumente

• Chemie: Struktur chemischer Komponenten

• Bioinformatik: Proteinstrukturen, metabolische Pathways,

Genexpressionen

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–19

Page 26: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Grundbegri↵e

• Graph G = (V ,E )

• V : Menge der Knoten (vertices)

• E ✓ V ⇥ V : Menge der Kanten (edges)

v1 v2

v4v3

• Kanten konnen mit Gewicht versehen werden

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–20

Page 27: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Grundbegri↵e: Adjazenzmatrix

• Reprasentation von Graphen durch Matrix (Knoten als Zeilen

und Spalten)

• ungerichteter Graph: symmetrische Matrix

• ungewichteter Graph: Zellen nur 0 oder 1

v1 v2

v4v3

3

1

1

2

2

5

05 1v4 2

0v3 20 0

v2 0 10 0

v1 0 003

v4v3v2v1

nach

von

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–21

Page 28: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Grundbegri↵e: Knotengrad

• Eigenschaft eines Knotens: Anzahl der verbundenen Knoten

• bei gerichteren Graphen: Unterscheidung in Eingangs- und

Ausgangsgrad

v1 v2

v4v3

3

1

1

2

2

5

01 1v4 1

0v3 10 0

v2 0 10 0

v1 0 001

v4v3v2v1

nach

von

3

1

1

1

2121

Ausgangsgrad

Eingangsgrad

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–22

Page 29: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Grundbegri↵e: Traversierung

• Tiefensuche (DFS): zunachst rekursiv alle Kindknotenbesuchen bevor alle Geschwisterknoten besucht werden

• Bestimmung der Zusammenhangskomponente

• Wegsuche um Labyrinth

• Breitensuche (BFS): zunachst alle Geschwisterknotenbesuchen bevor die Kindknoten besucht werden

• Bestimmung des kurzesten Weges

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–23

Page 30: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Subjekt-Pradikat-Objekt-Modell: RDF

• Sprache zur Reprasentation von Informationen uber

(Web)-Ressourcen

• Ziel: automatisierte Verarbeitung

• zentraler Bestandteil von Semantic Web, Linked (Open) Data

• Reprasentation von Daten, aber auch Wissensreprasentation

(z.B. Ontologie)

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–24

Page 31: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Ontologien

• Ontologie = formale Spezifikation einer Konzeptualisierung,

d.h. einer Reprasentation von Begri↵en (Konzepten) und

deren Beziehungen

• Anwendung: Annotation von Daten, semantische Suche

Wein

Dessertwein Schaumwein Spätlese

Getränk

Weinbeschreibung

Farbe

Süße

Geschmack

Körper Abgang

Weingut wird beschriebenhat Hersteller

produziert

inverse zu

ist

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–25

Page 32: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

RDF: Graphen & Tripel

• Graph = Menge von Tripeln, die Aussagen uber

Web-Ressourcen reprasentieren

• Identifikation der Web-Ressourcen uber Uniform Resource

Identifier (URI)

• Tripel:

subjekt pradikat objekt .

• Beispiel

<http://weindb.org/weine/2171> \<http://weindb.org/ontologie/name> "Pinot Noir".

Pinot Noirhttp://weindb.org/weine/3478 http://weindb.org/ontologie/name

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–26

Page 33: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

RDF: Graphen & Tripel

• Subjekt: URI-Referenz, d.h. Ressource, auf die sich die

Aussage bezieht

• Pradikat: Eigenschaft, ebenfalls in Form einer URI-Referenz

• Objekt: Wert der Eigenschaft als Literal (Konstante) oder

URI- Referenz

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–27

Page 34: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

RDF: Abkurzende Notation

• abkurzende Notation fur Namensraume uber Prafixe:

prefix wo: <http://weindb.org/ontologie/>

prefix weine: <http://weindb.org/weine/>

weine:2171 wo:name "Pinot Noir".

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–28

Page 35: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

RDF: Komplexe Graphen

• mehrere Aussagen zum gleichen Subjekt

• Objekte nicht nur Literale sondern selbst Objekte (URI)

weine:2171 wo:name "Pinot Noir".

weine:2171 wo:farbe "Rot".

weine:2171 wo:jahrgang "1999".

weine:2171 wo:erzeuger werzeuger:567 .

Rot

Pinot Noir

1999

werzeuger:567

weine:3478wo:farbe

wo:name

wo:jahrgang

wo:erzeuger

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–29

Page 36: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

RDF: Reprasentation, Schema und Vokabulare

• Reprasentation von RDF-Daten: N-Tripel (siehe oben),

RDF/XML

• RDF Schema:

• objektorientierte Spezifikationssprache

• erweitert RDF um Typsystem: Definition von Klassen und

Klassenhierarchien mit Eigenschaften, Ressourcen als Instanzen

von Klassen

• RDF Schema ist selbst RDF-Spezifikation

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–30

Page 37: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

RDF: Reprasentation, Schema und Vokabulare /2

• Beispiel RDF Schema

Wein rdf:type rdfs:Class .

Schaumwein rdf:type rdfs:Class .

Schaumwein rdfs:subClassOf Wein .

Name rdf:type rdf:Property .

Jahrgang rdf:type rdf:Property .

Jahrgang rdfs:domain Wein .

Jahrgang rdfs:range xsd:integer .

• fur komplexere Ontologien: OWL (Web Ontology Language)

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–31

Page 38: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

RDF: Reprasentation, Schema und Vokabulare /3

• Vokabular: vordefinierte Klassen und Eigenschaften

• Bsp: Dublin Core (Metadaten fur Dokumente), FOAF (Soziale

Netze), ...

• wichtig z.B. fur Linked Open Data

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–32

Page 39: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

SPARQL als RDF-Anfragesprache

• SPARQL Protocol And RDF Query Language: Anfragesprache

fur RDF

• W3C-Recommendation

• unterschiedliche Implementierungen moglich:

• Aufsatz fur SQL-Backends (z.B. DB2, Oracle)

• Triple Stores (RDF-Datenbank)

• SPARQL-Endpoints

• syntaktisch an SQL angelehnt, aber Unterstutzung fur

Graph-Anfragen

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–33

Page 40: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

SPARQL-Elemente

• Grundelemente: select-where-Block und Tripelmuster

?wein wo:name ?name .

• Auswertung: finden aller Belegungen (Bindung) fur Variable

(?name) bei Ubereinstimmung mit nicht-variablen Teilen

<http://weindb.org/weine/2171> wo:name "Pinot Noir".

<http://weindb.org/weine/2168> wo:name "Creek Shiraz".

<http://weindb.org/weine/2169> wo:name "Chardonnay".

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–34

Page 41: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

SPARQL: Basic Graph Pattern

• Graphmuster (BGP = Basic Graph Pattern): Kombination vonTripelmustern uber gemeinsame Variablen

?wein wo:name ?name .

?wein wo:farbe ?farbe .

?wein wo:erzeuger ?erzeuger .

?erzeuger wo:weingut ?ename .

• Einsatz in SPARQL-Anfragen im where-Teil

select ?wein ?name ?farbe ?ename

where { ?wein wo:name ?name .

?wein wo:farbe ?farbe .

?wein wo:erzeuger ?erzeuger .

?erzeuger wo:weingut ?ename . }

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–35

Page 42: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

SPARQL: Weitere Elemente

• filter: Filterbedingungen fur Bindungen

• optional: optionale Muster – erfordern nicht zwingend ein

Matching

prefix wo: <http://weindb.org/ontologie/>

select ?name

where { ?wein wo:name ?name . }optional { ?wein wo:jahrgang ?jahrgang } .

filter ( bound(?jahrgang) && ?jahrgang < 2010 )

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–36

Page 43: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Property-Graph-Modell

• Knoten und (gerichtete) Kanten mit Eigenschaften

(Properties)

• nicht streng typisiert, d.h. Eigenschaften als Name-Wert-Paare

• Unterstutzung in diversen Graph-Datenbanksystemen: neo4j,

Microsoft Azure Cosmos DB, OrientDB, Amazon Neptune,

. . .

Helena

Pinot Noir

produziert

Spätbur-gundername: Helena

farbe: Rotjahrgang: 1999

beerenfarbe: Schwarzherkunft: Frankreich

anteil: 100%besteht aus

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–37

Page 44: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Property-Graph-Modell in Neo4j

• Elemente: Nodes, Relationships, Properties, Labels

• Properties = Key-Value-Paare: Key (=String), Value

(=Java-Datentypen + Felder)

• Nodes mit Labels (⇡ Klassenname)

• Relationships: sind gerichtet, mit Namen und ggf. Properties

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–38

Page 45: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Property-Graph-Modell: Beispiel

anteil: 100%

Napa Valley

Pinot Noir

liegt in

produziert

Spätbur-gunder

besteht aus

gebiet: Napa Valleyregion: Kalifornien

farbe: Rotjahrgang: 2014

beerenfarbe: Schwarzherkunft: Frankreich

baut an

Merlot

baut an

Zinfandel

produziert

Helena

farbe: Rotjahrgang: 2019

beerenfarbe: Schwarzblauherkunft: Frankreich

Bighorn

name: Bighorn

liegt in

grenzt an

name: Helena

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–39

Page 46: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Anfragen auf Graphen

• keine Standardsprache

• aber wiederkehrende Grundelemente

• Graph Matching: Knoten, Kanten, Pfade (siehe BGP in

SPARQL)

• Filter fur Knoten- und Kanteneigenschaften

• Konstruktion neuer Graphen

• hier: Cypher (neo4j)

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–40

Page 47: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Anfragen in Cypher

• Basis: Muster der Form”Knoten ! Kante ! Knoten . . .“

(von)-[:relationship]->(nach)

• Beschrankung uber Label und Properties

(e:ERZEUGER)-[:LIEGT IN]->(a:ANBAUGEBIET {gebiet: ’Napa Valley’ } )

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–41

Page 48: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Cypher: Klauseln

• match: Beispielmuster fur Matching

• return: Festlegung der Ruckgabedaten (Projektion)

• where: Filterbedingung fur”gematchte“ Daten

• create: Erzeugen von Knoten oder Beziehungen

• set: Andern von Property-Werten

• . . .

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–42

Page 49: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Cypher: Beispiele

• Anlegen von Daten

create

(napavalley:ANBAUGEBIET {gebiet: ’Napa Valley’, region: ’Kalifornien’ }),

(helena:ERZEUGER { name: ’Helena’ }),...

(helena)-[:LIEGT IN]->(napavalley),

...

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–43

Page 50: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Cypher: Beispiele

• Alle Weinguter aus dem Napa Valley

match (e:ERZEUGER)-[:LIEGT IN]->(a:ANBAUGEBIET {gebiet: ’Napa Valley’ })

return e

• Alle Weinguter, die die Merlot-Traube anbauen

match (r:REBE { name: ’Merlot’ })<-[:BAUT AN]-(w) \-[:LIEGT IN]->(g)

return g

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–44

Page 51: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Cypher: Beispiele /2

• Alle Weinguter, die Weine mit eiem Spatburgunder-Anteil von

mehr als 50% produzieren sowie die Anzahl dieser Weine pro

Weingut

match (e:ERZEUGER)-[:PRODUZIERT]->(w:WEIN)-

[b:BESTEHT AUS]->(r:REBE { name: ’Spatburgunder’ })where b.anteil > 50

return e.name, count(w.name)

• Alle Weinguter, direkt an das Weingut Helena grenzen oder

an ein Weingut, das direkt an Helena grenzt

match (e1:ERZEUGER { name: ’Helena’ })-[:GRENZT AN*..2] \-(e2:ERZEUGER)

return e2

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–45

Page 52: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Cypher: Beispiele /3

• alle Knoten des Typs WEINE

match (w)

where w:WEINE

return w

• Knotengrade pro Knoten im Graph

match (n)-[r]-()

return n, count(r)

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–46

Page 53: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Zusammenfassung

• NoSQL als Oberbegri↵ fur diverse Datenbanktechniken

• große Bandbreite: von einfachen KV-Stores bis zu

Graphdatenbanken

• hohere Skalierbarkeit / Performance gegenuber SQL-DBMSmeist durch Einschrankungen erkauft

• Abschwachung von ACID-Eigenschaften

• begrenzte Anfragefunktionalitat

• Nicht-Standard bzw. proprietare Schnittstellen

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–47

Page 54: Teil XI NoSQL I/_/Kapitel11.pdf · NoSQL 1. Motivation f¨ur NoSQL 2. Datenmodelle fur NoSQL¨ 3. KV-Stores und Wide Column 4. Document Stores 5. Graph Stores Sattler/Saake — VL

Weiterfuhrende Literatur

• Lena Wiese: Advanced Data Management for SQL, NoSQL,

Cloud and Distributed Databases. De Gruyter / Oldenburg,

2015

• Ian Robinson, Jim Webber, Emil Eifrem: Graph Databases.

O’Reilly, 2015

Sattler/Saake — VL Datenbanksysteme — Januar 2019 11–48