111
1 Graph databases: time for serious stuDavid Funaro Alessandro Nadalin

Graph db: time for serious stuff @ codemotion 23/03/2012

Embed Size (px)

DESCRIPTION

Graph databases are not widespread in the development communities, although they are a swiss-army knife for problem that the relational model can't simple handle well. In this talk we're gonna talk for a few minutes about the graph theory, see how to easily solve a few relational anti-patterns with graph databases and how to integrate them in your next project. At the end we will take a practical look to OrientDB, "next big thing" of the NoSQL ecosystem, through its PHP Data Mapper, "Orient".

Citation preview

Page 1: Graph db: time for serious stuff @ codemotion 23/03/2012

1

Graph databases:time for serious stuff

David FunaroAlessandro Nadalin

Page 16: Graph db: time for serious stuff @ codemotion 23/03/2012

Your data is a graph

23

Page 17: Graph db: time for serious stuff @ codemotion 23/03/2012

a tree is a graph

24

Page 18: Graph db: time for serious stuff @ codemotion 23/03/2012

parent_id is a graph

25

Page 21: Graph db: time for serious stuff @ codemotion 23/03/2012

maximum flowGiven a dataset, calculate how to best organize it

Page 30: Graph db: time for serious stuff @ codemotion 23/03/2012

✓Relational Database

(mysql, oracle)

✓Document Oriented DB

(mongodb, couchdb)

✓XML Database

(MarkLogic, eXist-db)

http://www.slideshare.net/slidarko/problemsolving-using-graph-traversals-searching-scoring-ranking-and-recommendation#

Representing a Graph in:

37

Page 35: Graph db: time for serious stuff @ codemotion 23/03/2012

Tree-based DB WAY

41

1

find

http://davidfunaro.com

3

David Funaro

put in the Search Engine2

The cost to find a single friend HP grows as the friends HP tables grows

Page 43: Graph db: time for serious stuff @ codemotion 23/03/2012

How ?

49

PREFIX geospecies: <http://rdf.geospecies.org/ont/geospecies#>PREFIX lycopodiophyta: <http://lod.geospecies.org/phyla/Pc2>PREFIX door_county: <http://sws.geonames.org/5250768/>PREFIX dcterms: <http://purl.org/dc/terms/>

SELECT DISTINCT ?family_name ?canonicalName ?commonName ?identifier ?wikipedia_url

WHERE {?x geospecies:hasFamilyName ?family_name; geospecies:hasCanonicalName ?canonicalName; geospecies:hasCommonName ?commonName; dcterms:identifier ?identifier; geospecies:inPhylum lycopodiophyta:; geospecies:isUSDA_ExpectedIn door_county:. OPTIONAL { ?x geospecies:hasCommonName ?commonName; geospecies:hasWikipediaArticle ?wikipedia_url} }

ORDER BY ?family_name ?canonicalName

Page 60: Graph db: time for serious stuff @ codemotion 23/03/2012

68SELECT FROM fellas WHERE any() traverse(0,-1) ( @rid = [Michelle @rid] )

Page 61: Graph db: time for serious stuff @ codemotion 23/03/2012

SELECT FROM fellas WHERE any() traverse(0,2) ( @rid = [Michelle @rid] )

Page 63: Graph db: time for serious stuff @ codemotion 23/03/2012

beyond SQL

Page 65: Graph db: time for serious stuff @ codemotion 23/03/2012

ACID

Page 68: Graph db: time for serious stuff @ codemotion 23/03/2012

Double Protocol

Page 86: Graph db: time for serious stuff @ codemotion 23/03/2012

Orient = PHP Library to work with OrientDB

101

https://github.com/congow/Orient

Page 87: Graph db: time for serious stuff @ codemotion 23/03/2012

Data Mapper

Query BuilderHTTP Binding

Page 88: Graph db: time for serious stuff @ codemotion 23/03/2012

HTTP Binding

Page 93: Graph db: time for serious stuff @ codemotion 23/03/2012

...and much more!

(connect, disconnect, ...)

Page 94: Graph db: time for serious stuff @ codemotion 23/03/2012

Query Builder

Page 96: Graph db: time for serious stuff @ codemotion 23/03/2012

               $query->select(array('name', 'username', 'email'), false)                ->from(array('12:0', '12:1'), false)                ->where('any() traverse ( any() like "%danger%" )')                ->orWhere("1 = ?", 1)                ->andWhere("links = ?", 1)                ->limit(20)                ->orderBy('username')                ->orderBy('name', true, true)                ->range("12:0", "12:1");

              SELECT name, username, email               FROM [12:0, 12:1]               WHERE any() traverse ( any() like "%danger%" )              OR 1 = "1" AND links = "1"               ORDER BY name, username               LIMIT 20               RANGE 12:0 12:1

Page 97: Graph db: time for serious stuff @ codemotion 23/03/2012

Data Mapper

Page 99: Graph db: time for serious stuff @ codemotion 23/03/2012

Domain Driven Design

Page 111: Graph db: time for serious stuff @ codemotion 23/03/2012

Credits

http://www.flickr.com/photos/sayamindu/5677281218/sizes/l/in/photostream/http://farm1.static.flickr.com/182/471383865_79d04aec36_o.pnghttp://farm1.static.flickr.com/134/318947873_12028f1b66_b.jpg

http://www.flickr.com/photos/atomdocs/3275758118/sizes/o/in/photostream/http://www.flickr.com/photos/pattipics/5229478393/sizes/o/in/photostream/

http://www.flickr.com/photos/kongharald/366597251/sizes/o/in/photostream/http://www.everaldo.com/

http://www.flickr.com/photos/tusnelda/6140792529/sizes/l/in/photostream/http://www.flickr.com/photos/mondi/5368644355/sizes/l/in/photostream/

http://www.flickr.com/photos/jayneandd/4191106566/sizes/l/in/photostream/http://www.flickr.com/photos/jooon/2093253534/sizes/l/in/photostream/

http://www.flickr.com/photos/bluedharma/89186151/sizes/o/in/photostream/http://www.flickr.com/photos/exfordy/2747089295/sizes/l/in/photostream/

http://www.flickr.com/photos/nostri-imago/3137422976/sizes/o/in/photostream/http://www.flickr.com/photos/fionasjournal/379587818/sizes/z/in/photostream/

http://www.flickr.com/photos/nperlapro/1297392267/http://www.flickr.com/photos/fastphive/28428808/sizes/m/in/photostream/

http://www.flickr.com/photos/rnugraha/2003147365/sizes/o/in/photostream/http://www.flickr.com/photos/zigazou76/4412946911/sizes/l/in/photostream/http://www.flickr.com/photos/greatnet/4667555436/sizes/l/in/photostream/

http://www.flickr.com/photos/mnsc/2768391365/sizes/l/in/photostream/http://www.flickr.com/photos/christmaswithak/4675962453/sizes/l/in/photostream/

http://www.amazon.com/Trainspotting-Irvine-Welsh/dp/0393314804http://www.flickr.com/photos/franconadalin59/5778176872/sizes/l/in/photostream/

http://farm6.static.flickr.com/5176/5474445627_875d621689_b.jpghttp://farm3.static.flickr.com/2243/2189435082_a16d3c89ae_b.jpghttp://farm3.static.flickr.com/2647/3816311930_ac52cff491_o.jpg

http://i130.photobucket.com/albums/p266/feike1977/PES6-4-3-3defencesettings.jpghttp://images.usatoday.com/life/_photos/2006/11/30/numb3rs-topper.jpg

http://www.flickr.com/photos/jakecaptive/3205277810/sizes/l/in/photostream/