Top Banner
TinkerPop The Pathology of Graph Databases Marko A. Rodriguez Graph Systems Architect http://markorodriguez.com http://twitter.com/twarko http://tinkerpop.com WindyCityDB - Chicago, Illinois – June 25, 2011
240

The Pathology of Graph Databases

Aug 20, 2015

Download

Technology

Marko Rodriguez
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Pathology of Graph Databases

TinkerPop

The Pathology of Graph Databases

Marko A. RodriguezGraph Systems Architect

http://markorodriguez.com http://twitter.com/twarko

http://tinkerpop.com

WindyCityDB - Chicago, Illinois – June 25, 2011

Page 2: The Pathology of Graph Databases

There is nothing more fascinating and utterly mind-bending than traversing a graph. Those who succumb to this data processing pattern euphorically suffer from graph pathology.

This is a case study of the Graph Addict.

Abstract

GremlinG = (V,E)

What is presented is as of Gremlin 1.1 (Released July 15, 2011)

Page 3: The Pathology of Graph Databases

What you are about to see may disturb you.

It has infected Neo4j, OrientDB, DEX, RDF Sail, TinkerGraph, and ReXster.

...it will infect others.

reXster

Page 4: The Pathology of Graph Databases
Page 5: The Pathology of Graph Databases
Page 6: The Pathology of Graph Databases
Page 7: The Pathology of Graph Databases
Page 8: The Pathology of Graph Databases

??

?

Page 9: The Pathology of Graph Databases
Page 10: The Pathology of Graph Databases

~$ cd /tmp/graphdb

Page 11: The Pathology of Graph Databases

graphdb$ gremlin

Page 12: The Pathology of Graph Databases

\,,,/ (o o)-----o00o(_)-o00o-----gremlin>

Page 13: The Pathology of Graph Databases
Page 14: The Pathology of Graph Databases

The Basics

Page 15: The Pathology of Graph Databases

'Gremlin is a Groovy DSL and as such, has native JVM access.'

Gremlin is a Groovy DSL and as such, has native JVM access.

Page 16: The Pathology of Graph Databases

1+2

3

Page 17: The Pathology of Graph Databases

'gremlin'

gremlin

Page 18: The Pathology of Graph Databases

'gremlin'.substring(2)

emlin

Page 19: The Pathology of Graph Databases

list = [1,2,3,4,5]

[1,2,3,4,5]

Page 20: The Pathology of Graph Databases

map = [key1:'value',key2:123]

key1=valuekey2=123

Page 21: The Pathology of Graph Databases

socket = new Socket('127.0.0.1',8182)

<modem sound/>

Page 22: The Pathology of Graph Databases

TextAnalysis.isMean('You are that which is not good.')

true

Page 23: The Pathology of Graph Databases

Graph Traversing

Page 24: The Pathology of Graph Databases

/tmp/graphdb

g = new Neo4jGraph('/tmp/graphdb')

Page 25: The Pathology of Graph Databases

/tmp/graphdb

g

Page 26: The Pathology of Graph Databases

g.v(1)

1

Page 27: The Pathology of Graph Databases

g.v(1).name

1

name=marko

Page 28: The Pathology of Graph Databases

g.v(1)

1

Page 29: The Pathology of Graph Databases

g.v(1).city

1

city=santafe

Page 30: The Pathology of Graph Databases

g.v(1)

1

Page 31: The Pathology of Graph Databases

g.v(1).map()

1

name=markocity=santafe

Page 32: The Pathology of Graph Databases

g.v(1)

1

Page 33: The Pathology of Graph Databases

g.v(1).outE

knows

knows

created

1

Page 34: The Pathology of Graph Databases

g.v(1).outE

knows

knows

created

1

Page 35: The Pathology of Graph Databases

g.v(1).outE.since

knows

knows

created

1since=2010

since=2005

null

Page 36: The Pathology of Graph Databases

g.v(1).outE

knows

knows

created

1

Page 37: The Pathology of Graph Databases

g.v(1).outE.inV

1 knows

knows

created

2

3

4

Page 38: The Pathology of Graph Databases

g.v(1).outE.inV.name

1 knows

knows

created

2

3

4

name=rexster

name=stephen

name=peter

Page 39: The Pathology of Graph Databases

/tmp/graphdb

g

Page 40: The Pathology of Graph Databases

g.v(1)

1

Page 41: The Pathology of Graph Databases

g.v(1).outE

1 knows

knows

created

Page 42: The Pathology of Graph Databases

g.v(1).outE[[label:'knows']]

1 knows

knows

created

Page 43: The Pathology of Graph Databases

g.v(1)

1

Page 44: The Pathology of Graph Databases

g.v(1).outE

1 knows

knows

created

Page 45: The Pathology of Graph Databases

g.v(1).outE.filter{it.label=='knows'}

1 knows

knows

created

Page 46: The Pathology of Graph Databases

g.v(1).outE.filter{it.label=='knows'}.count()

2

Page 47: The Pathology of Graph Databases

g.v(1).outE

1 knows

knows

created

Page 48: The Pathology of Graph Databases

g.v(1).outE.filter{it.label=='knows' & since > 2006}

1 knows

knows

created

Page 49: The Pathology of Graph Databases

g.v(1).outE[[label:'knows']].inV.toString()

[OutEdgesPipe, LabelFilterPipe(NOT_EQUAL,knows), InVertexPipe]

Page 50: The Pathology of Graph Databases

g.v(1)

1

Page 51: The Pathology of Graph Databases

g.v(1).outE('knows')

1 knows

knows

Page 52: The Pathology of Graph Databases

g.v(1).outE('knows').inV

1 knows

knows

3

4

Page 53: The Pathology of Graph Databases

g.v(1).outE('knows').inV.toString()

[OutEdgesPipe(knows), InVertexPipe]

Page 54: The Pathology of Graph Databases

g.v(1)

1

Page 55: The Pathology of Graph Databases

g.v(1).out('knows')

1 knows

knows

3

4

Page 56: The Pathology of Graph Databases

g.v(1).out('knows').name

1 knows

knows

3

4

name=stephen

name=peter

Page 57: The Pathology of Graph Databases

g.v(1).out('knows').name.filter{it.startsWith('st')}

1 knows

knows

3

4

name=stephen

name=peter

Page 58: The Pathology of Graph Databases

g.v(1).out('knows').name.filter{it.matches('p.{4}')}

1 knows

knows

3

4

name=stephen

name=peter

Page 59: The Pathology of Graph Databases

g.v(1).out('knows').name.filter{it.matches('p.{4}') & false}

1 knows

knows

3

4

name=stephen

name=peter

Page 60: The Pathology of Graph Databases

g.v(1).out('knows').toString()

[OutPipe(knows)]

Page 61: The Pathology of Graph Databases

g.v(1)

1

Page 62: The Pathology of Graph Databases

g.v(1).filter{new Random().nextBoolean()}

1

WooHoo

!

Page 63: The Pathology of Graph Databases

g.v(1)

1

Page 64: The Pathology of Graph Databases

g.v(1).filter{new Random().nextBoolean()}

1

Alright!

Page 65: The Pathology of Graph Databases

g.v(1)

1

Page 66: The Pathology of Graph Databases

g.v(1).filter{new Random().nextBoolean()}

1

Doh!

Page 67: The Pathology of Graph Databases

1

Page 68: The Pathology of Graph Databases

1

Page 69: The Pathology of Graph Databases

1

Page 70: The Pathology of Graph Databases

1

Page 71: The Pathology of Graph Databases

Graph Inference

Page 72: The Pathology of Graph Databases

g.v(1)

1

Page 73: The Pathology of Graph Databases

g.v(1).out('created')

1

created

2

Page 74: The Pathology of Graph Databases

g.v(1).out('created').name

1

created

2 name=rexster

Page 75: The Pathology of Graph Databases

g.v(1)

1

Page 76: The Pathology of Graph Databases

g.v(1).out('created')

1

created

2

Page 77: The Pathology of Graph Databases

g.v(1).out('created').in('created')

1

created

2

3

created

Page 78: The Pathology of Graph Databases

g.v(1).out('created').in('created').except([g.v(1)])

1

created

2

3

created

Page 79: The Pathology of Graph Databases

g.v(1).out('created').in('created').except([g.v(1)]).name

1

created

2

3

created

name=stephen

Page 80: The Pathology of Graph Databases

g.v(1).out('created').in('created').except([g.v(1)]).name.back(1)

1

created

2

3

created

name=stephen

Page 81: The Pathology of Graph Databases

g.v(1).out('created').in('created').except([g.v(1)]).name.back(1). sideEffect{g.addEdge(g.v(1),it,'collaborator')}

1 collaborator

created

2

3

created

name=stephen

Page 82: The Pathology of Graph Databases

g.v(1).out('created').in('created').except([g.v(1)]).name.back(1). sideEffect{g.addEdge(g.v(1),it,'collaborator')}.filter{false}

1 collaborator

created

2

3

created

name=stephen

Page 83: The Pathology of Graph Databases

Graph Backtracking and Looping

Page 84: The Pathology of Graph Databases

g.v(1)

1

Page 85: The Pathology of Graph Databases

g.v(1).out('created')

1

created

2

Page 86: The Pathology of Graph Databases

g.v(1).out('created').out('imports')

1

created

2 imports 6

imports

5

imports

7

Page 87: The Pathology of Graph Databases

g.v(1).out('created').out('imports').name

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

Page 88: The Pathology of Graph Databases

g.v(1).out('created').out('imports').name.back(1)

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

Page 89: The Pathology of Graph Databases

g.v(1).out('created').out('imports').name.back(1).out('imports')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8

Page 90: The Pathology of Graph Databases

g.v(1).out('created').out('imports').name.back(1).out('imports')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8

Page 91: The Pathology of Graph Databases

g.v(1).out('created').out('imports').name.back(1).out('imports').name

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 92: The Pathology of Graph Databases

g.v(1).out('created').out('imports').name.back(1).out('imports').name .back(1)

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 93: The Pathology of Graph Databases

g.v(1).out('created').out('imports').name.back(1).out('imports').name .back(1).out('imports')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 94: The Pathology of Graph Databases

g.v(1).out('created').out('imports').name.back(1).out('imports').name .back(1).out('imports').out('imports')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 95: The Pathology of Graph Databases

g.v(1).out('created').out('imports').name.back(1).out('imports').name .back(1).out('imports').out('imports').out('imports')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 96: The Pathology of Graph Databases

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 97: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 98: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 99: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 100: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 101: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 102: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 103: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

2

Page 104: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

3

Page 105: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

4

Page 106: The Pathology of Graph Databases

g.v(1).out('created').out('imports').loop(1){it.loops < 5}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 107: The Pathology of Graph Databases

m = [:]

m

Page 108: The Pathology of Graph Databases

m

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 109: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

m

Page 110: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

m

Page 111: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

m

Page 112: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

v[5]=1v[6]=1v[7]=1

m

Page 113: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

v[5]=1v[6]=1v[7]=1

m

Page 114: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

v[5]=3v[6]=2v[7]=1v[8]=1

m

Page 115: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

v[5]=3v[6]=2v[7]=1v[8]=1

m

Page 116: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

v[5]=4v[6]=2v[7]=1v[8]=3

m

Page 117: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

v[5]=4v[6]=2v[7]=1v[8]=3

m

Page 118: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

v[5]=4v[6]=2v[7]=1v[8]=4

m

Page 119: The Pathology of Graph Databases

g.v(1).out('created').out('import').groupCount(m).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

v[5]=4v[6]=2v[7]=1v[8]=4

m

Page 120: The Pathology of Graph Databases

m = [:]

m

Page 121: The Pathology of Graph Databases

m

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 122: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

m

Page 123: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

m

Page 124: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

m

Page 125: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

m

Page 126: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=1pipes=1gremlin=1

m

Page 127: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=1pipes=1gremlin=1

m

Page 128: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=1pipes=1gremlin=1

m

Page 129: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=1pipes=1gremlin=1

m

Page 130: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=3pipes=2gremlin=1neo4j=1

m

Page 131: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=3pipes=2gremlin=1neo4j=1

m

Page 132: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=3pipes=2gremlin=1neo4j=1

m

Page 133: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=3pipes=2gremlin=1neo4j=1

m

Page 134: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=4pipes=2gremlin=1neo4j=3

m

Page 135: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=4pipes=2gremlin=1neo4j=3

m

Page 136: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=4pipes=2gremlin=1neo4j=3

m

Page 137: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=4pipes=2gremlin=1neo4j=3

m

Page 138: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=4pipes=2gremlin=1neo4j=4

m

Page 139: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=4pipes=2gremlin=1neo4j=4

m

Page 140: The Pathology of Graph Databases

g.v(1).out('created').out('import').name.groupCount(m).back(2).loop(2){true}

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

blueprints=4pipes=2gremlin=1neo4j=4

m

Page 141: The Pathology of Graph Databases

Graph Paths

Page 142: The Pathology of Graph Databases

g.v(1)

1

Page 143: The Pathology of Graph Databases

g.v(1).as('x')

1

Page 144: The Pathology of Graph Databases

g.v(1).as('x').in('child')

1

child

9

child

10

Page 145: The Pathology of Graph Databases

1

child

9

child

10

g.v(1).as('x').in('child').loop('x')

Page 146: The Pathology of Graph Databases

1

child

9

child

10

g.v(1).as('x').in('child').loop('x'){it.object.in.count() != 0}

childchild

Page 147: The Pathology of Graph Databases

1

child

9

child

10

g.v(1).as('x').in('child').loop('x'){it.object.in.count() != 0}

child

childchildchild

Page 148: The Pathology of Graph Databases

1

child

9

child

10

g.v(1).as('x').in('child').loop('x'){it.object.in.count() != 0}

child

child

child

child

childchild

Page 149: The Pathology of Graph Databases

1

child

9

child

10

g.v(1).as('x').in('child').loop('x'){it.object.in.count() != 0}

child...

100,000,000 100,000,001

child

child

child

child...

child

childchild

Page 150: The Pathology of Graph Databases

1

child

9

child

10

g.v(1).as('x').in('child').loop('x'){it.object.in.count() != 0}.paths

child...

100,000,000 100,000,001

child

child

child

child

childchild

[v[1], v[9], ..., v[100,000,000]][v[1], v[10], ..., v[100,000,001]]...

child...

Page 151: The Pathology of Graph Databases

1

child

9

child

10

g.v(1).as('x').in('child').loop('x'){it.object.in.count() != 0}.name

child...

100,000,000 100,000,001

child

child

child

child

childchild

child...

name=angelina name=brad

Page 152: The Pathology of Graph Databases

1

child

9

child

10

g.v(1).as('x').in('child').loop('x'){it.object.in.count() != 0}.name.paths

child...

100,000,000 100,000,001

child

child

child

child

childchild

child...

name=angelina name=brad

[v[1], v[9], ..., v[100,000,000], angelina][v[1], v[10], ..., v[100,000,001], brad]...

Page 153: The Pathology of Graph Databases

1

g.v(1)

Page 154: The Pathology of Graph Databases

1

child child

g.v(1).inE('child')

Page 155: The Pathology of Graph Databases

1

child child

thinks="You suck." thinks="You're great."

g.v(1).inE('child').filter{TextAnalysis.isMean(it.thinks)}

Page 156: The Pathology of Graph Databases

1

child

thinks="You suck."

g.v(1).inE('child').filter{TextAnalysis.isMean(it.thinks)}

Page 157: The Pathology of Graph Databases

1

thinks="You suck."

g.v(1).inE('child').filter{TextAnalysis.isMean(it.thinks)}.outV

9

child

Page 158: The Pathology of Graph Databases

1

child

thinks="You suck."

g.v(1).inE('child').filter{TextAnalysis.isMean(it.thinks)}.outV.loop(3){true}

9

thinks="You're fat."thinks="Get a real job."

thinks="You throw like a girl."

thinks="No pony!"

Page 159: The Pathology of Graph Databases

1

child

thinks="You suck."

g.v(1).inE('child').filter{TextAnalysis.isMean(it.thinks)}.outV.loop(3){true}

9

thinks="You're fat."thinks="Get a real job."

thinks="You throw like a girl."

thinks="No pony!"

Page 160: The Pathology of Graph Databases

Graph Pattern Matching

Page 161: The Pathology of Graph Databases

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 162: The Pathology of Graph Databases

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

SELECT ?x ?y WHERE { 1 created ?x . ?x imports ?y}

Page 163: The Pathology of Graph Databases

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

SELECT ?x ?y WHERE { 1 created ?x . ?x imports ?y}

Page 164: The Pathology of Graph Databases

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

SELECT ?x ?y WHERE { 1 created ?x . ?x imports ?y}

Page 165: The Pathology of Graph Databases

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

SELECT ?x ?y WHERE { 1 created ?x . ?x imports ?y}

v[2] v[5]v[2] v[6]v[2] v[7]

?x ?y

Page 166: The Pathology of Graph Databases

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

Page 167: The Pathology of Graph Databases

t = new Table()

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

Page 168: The Pathology of Graph Databases

g.v(1)

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

Page 169: The Pathology of Graph Databases

g.v(1).out('created')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

Page 170: The Pathology of Graph Databases

g.v(1).out('created').as('x')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

x

Page 171: The Pathology of Graph Databases

g.v(1).out('created').as('x').out('imports')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

x

Page 172: The Pathology of Graph Databases

g.v(1).out('created').as('x').out('imports').as('y')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

x

y

y

y

Page 173: The Pathology of Graph Databases

g.v(1).out('created').as('x').out('imports').as('y').table(t)

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

x

y

y

y

tv[2] v[5]v[2] v[6]v[2] v[7]

x y

Page 174: The Pathology of Graph Databases

t.get(0,1)

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

x

y

y

y

tv[2] v[5]v[2] v[6]v[2] v[7]

x y

v[5]

Page 175: The Pathology of Graph Databases

t.get(0,'x')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

x

y

y

y

tv[2] v[5]v[2] v[6]v[2] v[7]

x y

v[2]

Page 176: The Pathology of Graph Databases

t.getColumn('y')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

x

y

y

y

tv[2] v[5]v[2] v[6]v[2] v[7]

x y

v[5]v[6]v[7]

Page 177: The Pathology of Graph Databases

t.getColumnNames()

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

x

y

y

y

tv[2] v[5]v[2] v[6]v[2] v[7]

x y

[x, y]

Page 178: The Pathology of Graph Databases

t = new Table()

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

Page 179: The Pathology of Graph Databases

g.v(1)

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

Page 180: The Pathology of Graph Databases

g.v(1).out('created')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

Page 181: The Pathology of Graph Databases

g.v(1).out('created').as('x')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

x

Page 182: The Pathology of Graph Databases

g.v(1).out('created').as('x').out('imports')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

x

Page 183: The Pathology of Graph Databases

g.v(1).out('created').as('x').out('imports').as('y')

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

t

x

y

y

y

Page 184: The Pathology of Graph Databases

g.v(1).out('created').as('x').out('imports').as('y').table(t){it.id}{it.name}

t2 blueprints2 pipes2 gremlin

x y

1

created

2 imports 6

imports

5

imports

7 name=gremlin

name=blueprints

name=pipes

importsimports

imports

imports

8name=neo4j

x

y

y

y

Page 185: The Pathology of Graph Databases

g.clear()

Page 186: The Pathology of Graph Databases

Graph Construction

Page 187: The Pathology of Graph Databases

a = g.addVertex()

1

Page 188: The Pathology of Graph Databases

a.name = 'pierre'

1

name=pierre

Page 189: The Pathology of Graph Databases

a.city = 'brussels'

1

name=pierrecity=brussels

Page 190: The Pathology of Graph Databases

b = g.addVertex([name:'stephen',city:'dc'])

1

name=pierrecity=brussels

2

name=stephencity=dc

Page 191: The Pathology of Graph Databases

c = g.addVertex([name:'rexster',logo:[a12f04b312bc...]])

1

name=pierrecity=brussels

2

name=stephencity=dc

3

name=rexsterlogo= . reXster

Page 192: The Pathology of Graph Databases

g.addEdge(b,c,'created',[since:2011])

1

name=pierrecity=brussels

2

name=stephencity=dc

3

created

since=2011

name=rexsterlogo= . reXster

Page 193: The Pathology of Graph Databases

g.addEdge(a,c,'reviews',[since:2011])

1

2

name=stephencity=dc

3

created

since=2011

reviews

since=2011

name=pierrecity=brussels

name=rexsterlogo= . reXster

Page 194: The Pathology of Graph Databases

g.addEdge(c,g.addVertex([name:'gremlin',logo:[ab1346f47...]),'imports')

1

2

name=stephencity=dc

3

created

since=2011

reviews

since=2011

name=pierrecity=brussels

4

importsname=rexsterlogo= . reXster

name=gremlinlogo= . Gremlin

G = (V,E)

Page 195: The Pathology of Graph Databases

g.addEdge(c,g.addVertex([name:'pipes',logo:[12cbef46...]]),'imports')

1

2

name=stephencity=dc

3

created

since=2011

reviews

since=2011

name=pierrecity=brussels

4

imports

5

imports

name=gremlinlogo= . Gremlin

G = (V,E)

name=rexsterlogo= . reXster

name=pipeslogo= .Pipes

Page 196: The Pathology of Graph Databases

g.addEdge(c,g.addVertex([name:'blueprints',logo:[f13cd1467...]]),'imports')

1

2

name=stephencity=dc

3

created

since=2011

reviews

since=2011

name=pierrecity=brussels

4

imports

5

imports

6

imports

name=gremlinlogo= . Gremlin

G = (V,E)

name=rexsterlogo= . reXster

name=pipeslogo= .Pipes

name=blueprintslogo= .Blueprints

Page 197: The Pathology of Graph Databases

g.V

1

2

3

4

56

Page 198: The Pathology of Graph Databases

g.V.count()

6

Page 199: The Pathology of Graph Databases

g.V.name

pierre

rexster

stephen

gremlin

blueprintspipes

Page 200: The Pathology of Graph Databases

g.V

1

2

3

4

56

Page 201: The Pathology of Graph Databases

g.V.logo

GremlinG = (V,E)

reXster

PipesBlueprints

Page 202: The Pathology of Graph Databases

g.V.logo.count()

4

Page 203: The Pathology of Graph Databases

g.V.transform{it.map()}

name=stephencity=dc

name=pierrecity=brussels

name=gremlinlogo= . Gremlin

G = (V,E)

name=rexsterlogo= . reXster

name=pipeslogo= .Pipes

name=blueprintslogo= .Blueprints

Page 204: The Pathology of Graph Databases

6

g.V.transform{it.map()}.count()

Page 205: The Pathology of Graph Databases

7

g.V.transform{it.map()}.count() + 1

Page 206: The Pathology of Graph Databases

8

g.V.transform{it.map()}.count() + 1 + 1

Page 207: The Pathology of Graph Databases

4

(g.V.transform{it.map()}.count() + 1 + 1) / 2

Page 208: The Pathology of Graph Databases

4 is a number.

((g.V.transform{it.map()}.count() + 1 + 1) / 2) + ' is a number.'

Page 209: The Pathology of Graph Databases

14

(((g.V.transform{it.map()}.count() + 1 + 1) / 2) + ' is a number.').length()

Page 210: The Pathology of Graph Databases

g.E

created

reviews

imports

importsimports

Page 211: The Pathology of Graph Databases

g.E.transform{it.map()}

since=2011

since=2011

Page 212: The Pathology of Graph Databases

g.clear()

Page 213: The Pathology of Graph Databases

Graph Ranking

Page 214: The Pathology of Graph Databases

g.loadGraphML('loopy-lou-and-the-loops.xml')

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

Page 215: The Pathology of Graph Databases

m = [:]

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

m

Page 216: The Pathology of Graph Databases

c = 0

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

mm

c 0

Page 217: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

m

c 0

Page 218: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

m

c 0

Page 219: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[2]=1v[6]=1m

c 0

Page 220: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[2]=1v[6]=1m

c 2

Page 221: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[2]=1v[3]=1v[6]=2v[7]=1

m

c 2

Page 222: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[2]=1v[3]=1v[6]=2v[7]=1

m

c 5

Page 223: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=1v[2]=1v[3]=1v[4]=1v[6]=2v[7]=2v[8]=1

m

c 5

Page 224: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=1v[2]=1v[3]=1v[4]=1v[6]=2v[7]=2v[8]=1

m

c 9

Page 225: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=3v[2]=2v[3]=1v[4]=1v[5]=1v[6]=3v[7]=2v[8]=2

m

c 9

Page 226: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=3v[2]=2v[3]=1v[4]=1v[5]=1v[6]=3v[7]=2v[8]=2

m

c 15

Page 227: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=4v[2]=4v[3]=3v[4]=1v[5]=1v[6]=7v[7]=3v[8]=2

m

c 15

Page 228: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=4v[2]=4v[3]=3v[4]=1v[5]=1v[6]=7v[7]=3v[8]=2

m

c 25

Page 229: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=5v[2]=5v[3]=5v[4]=3v[5]=1v[6]=10v[7]=7v[8]=3

m

c 25

Page 230: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=5v[2]=5v[3]=5v[4]=3v[5]=1v[6]=10v[7]=7v[8]=3

m

c 39

Page 231: The Pathology of Graph Databases

g.v(1).out.groupCount(m).loop(2){c++ < 35}.filter{false}

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=5v[2]=5v[3]=5v[4]=3v[5]=1v[6]=10v[7]=7v[8]=3

m

c 39

Page 232: The Pathology of Graph Databases

println 'do you understand the concept of centrality?'

1

friend

2 3

4

5

67

8

friend

friend

friend

friend

friend

friend

friend friend

friend

friend

friend

v[1]=5v[2]=5v[3]=5v[4]=3v[5]=1v[6]=10v[7]=7v[8]=3

m

c 39

Page 233: The Pathology of Graph Databases

g.clear()

Page 235: The Pathology of Graph Databases

Via any JVM language (JSR 223)

Neo4j Server

Page 239: The Pathology of Graph Databases
Page 240: The Pathology of Graph Databases