an introduction to tinkerpop

36
An Introduction to Tinkerpop @doryokujin GraphDB Meet-Up Japan #1

Upload: takahiro-inoue

Post on 15-Jan-2015

31.431 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: An Introduction to Tinkerpop

An Introductionto Tinkerpop

@doryokujin

GraphDB Meet-Up Japan #1

Page 2: An Introduction to Tinkerpop

・Takahiro Inoue(age 26)

・twitter: doryokujin

・Majored in Math (Statistics & Graph Algorithm)

・Data Scientist

・Leader of MongoDB JP

・Interest: DataProcessing, GraphDB

About Me

Page 3: An Introduction to Tinkerpop

Open source software development group focused on technologies in the emerging graph database ecosystem

・ : A Property Graph Model Interface

・ : A Dataflow Framework using Process Graphs

・ : A Graph Traversal Language

・ : A RESTful Graph Shell

TinkerPop

Page 4: An Introduction to Tinkerpop

TinkerPop

http://www.tinkerpop.com/

Page 5: An Introduction to Tinkerpop

TinkerPop

・Must read to understand a philosophy of Tinkerpop“Applying Graph Analysis and Manipulation to Data Stores.”

Page 6: An Introduction to Tinkerpop

TinkerPop

Page 7: An Introduction to Tinkerpop
Page 10: An Introduction to Tinkerpop

・TinkerGraph: Lightweight, POJO based, in-memory property graph

・Handy use with GraphML reader and writer library// An Exapmle of TinkerGraph

Graph graph = new TinkerGraph();

Vertex a = graph.addVertex(null);

Vertex b = graph.addVertex(null);

a.setProperty("name", "marko");

b.setProperty("name", "peter");

Edge e = graph.addEdge(null, a, b, "knows");

// marko--knows-->peter

https://github.com/tinkerpop/blueprints/wiki/Code-Examples

Page 11: An Introduction to Tinkerpop

public void testIteratingGraph() {

Graph graph = TinkerGraphFactory.createTinkerGraph();

System.out.println("Vertices of " + graph);

for (Vertex vertex : graph.getVertices()) {

System.out.println(vertex);

}

System.out.println("Edges of " + graph);

for (Edge edge : graph.getEdges()) {

System.out.println(edge);

}

}Vertices of tinkergraph[vertices:6 edges:6]

v[3]

v[2]

...

Edges of tinkergraph[vertices:6 edges:6]

e[10][4-created->5]

e[7][1-knows->2]

... https://github.com/tinkerpop/blueprints/wiki/Code-Examples

Page 12: An Introduction to Tinkerpop
Page 13: An Introduction to Tinkerpop

・Rexster: Multi-faceted graph server using Jersey (deployable through Tomcat)

- Provides flexible methods not only GET, POST, DELETE but also Gremlin

・Extentions support of standard traversal goals- such as search, score, rank, and, in concert, recommendation

・The Dog House provides browser based interface - Vertex and Edge Browser: View vertices and edges for a selected graph

- Gremlin Console: Simulates a Gremlin console session against a selected graph

・Rexster Console is a REPL similar to the REPL available from Gremlin.

Page 14: An Introduction to Tinkerpop

The Dog House

Page 16: An Introduction to Tinkerpop

curl -sX GET "http://aHost:8182/graphs/neo4jsample/indices/vertices?key=ID&value=52"

{

"version": "0.4-SNAPSHOT",

"results": [

{

"_id": 149,

"_type": "vertex",

"Name": "King",

"Type": "Card",

"ID": "52"

}

],

"totalSize": 1,

"queryTime": 3.876749

}

https://github.com/martinhbramwell/Rexster-Stuff

Page 17: An Introduction to Tinkerpop

Basic Rest API[GET]

[POST]...

...

https://github.com/tinkerpop/rexster/wiki/Basic-REST-API

Page 18: An Introduction to Tinkerpop

~$ gremlin

\,,,/

(o o)

-----oOOo-(_)-oOOo-----

gremlin>

Page 20: An Introduction to Tinkerpop

https://github.com/tinkerpop/gremlin/wiki/Gremlin-Steps

Gremlin Steps

Page 21: An Introduction to Tinkerpop

https://github.com/tinkerpop/gremlin/wiki/Gremlin-Methods

Gremlin Methods

Page 22: An Introduction to Tinkerpop

gremlin> g = TinkerGraphFactory.createTinkerGraph()

==>tinkergraph[vertices:6 edges:6]

gremlin> v = g.v(1)

==>v[1]

gremlin> v.outE

==>e[7][1-knows->2]

==>e[9][1-created->3]

==>e[8][1-knows->4]

gremlin> v.outE.inV

==>v[2]

==>v[3]

==>v[4]

Code Exapmles

https://github.com/tinkerpop/gremlin/wiki/Basic-Graph-Traversals

Page 23: An Introduction to Tinkerpop

# vertex jump

gremlin> v.outE.inV.outE.inV

==>v[5]

==>v[3]

# shortcut

gremlin> v.out.out

==>v[5]

==>v[3]

# using filter

gremlin> v.outE.filter{it.label=='knows'}.inV.filter{it.age >

30}.name

==>josh

# backtracking and an in-line regular expression

gremlin> v.out('knows').filter{it.age >

21}.name.filter{it.matches('jo.{2}|JO.{2}')}.back(3).age

==>32 https://github.com/tinkerpop/gremlin/wiki/Basic-Graph-Traversals

Page 24: An Introduction to Tinkerpop

# return path

gremlin> g.v(1).outE.inV.name.paths

==>[v[1], e[7][1-knows->2], v[2], vadas]

==>[v[1], e[9][1-created->3], v[3], lop]

==>[v[1], e[8][1-knows->4], v[4], josh]

gremlin> g.v(1).outE.inV.paths{it.name}{it.weight}{it.name}

==>[marko, 0.5, vadas]

==>[marko, 0.4, lop]

==>[marko, 1.0, josh]https://github.com/tinkerpop/gremlin/wiki/Basic-Graph-Traversals

Page 25: An Introduction to Tinkerpop

# loop

gremlin> g.v(89).outE.inV.paths

==>[v[89], e[7021][89-followed_by->83], v[83]]

==>[v[89], e[7022][89-followed_by->21], v[21]]

==>[v[89], e[7006][89-followed_by->127], v[127]]

...

gremlin> g.v(89).outE.inV.loop(2){it.loops < 3}.paths

==>[v[89], e[7021][89-followed_by->83], v[83], e[1411][83-followed_by->13],

v[13]]

==>[v[89], e[7021][89-followed_by->83], v[83], e[1410][83-followed_by->12],

v[12]]

==>[v[89], e[7021][89-followed_by->83], v[83], e[1415][83-followed_by->114],

v[114]]

==>[v[89], e[7021][89-followed_by->83], v[83], e[1414][83-followed_by->15],

v[15]]

...

gremlin> g.v(89).outE.inV.loop(2){it.loops < 3} == g.v(89).outE.inV.outE.inV

==>true

https://github.com/tinkerpop/gremlin/wiki/Loop-Pattern

2 step away from node89

loop 11step 2step

Page 26: An Introduction to Tinkerpop
Page 27: An Introduction to Tinkerpop

・transform: Given an object of type S, emit an object of type E

・filter: Given an object of type S, emit it or not

・sideEffect: Given an object of type S, emit it, but yield some computational side-effect in the process

Pipes: Dataflow framework using process graphs

Page 29: An Introduction to Tinkerpop

[Transform Pipes]

gremlin> g.v(1).out.name

==>vadas

==>lop

==>josh

・Pipes is a lazy evaluation framework, the mappings are computing as needed

gremlin>

g.v(1).out.name.paths

==>[v[1], v[2], vadas]

==>[v[1], v[3], lop]

==>[v[1], v[4], josh]

On the Nature of Pipes

Page 30: An Introduction to Tinkerpop

[Filter Pipes]

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

==>v[2]

==>v[4]

gremlin> g.v(1).out('knows').filter{it.age < 30}

==>v[2]

gremlin> g.v(1).out('knows').filter{it.age < 30}.name

==>vadas

gremlin> g.v(1).out('knows').filter{it.age <

30}.name.transform{it.length()}

==>5 On the Nature of Pipes

Page 31: An Introduction to Tinkerpop

[Side Effect Pipes]

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

==>v[2]

==>v[4]

gremlin> g.v(1).out('knows').filter{it.age < 30}

==>v[2]

gremlin> g.v(1).out('knows').filter{it.age < 30}.name

==>vadas

gremlin> g.v(1).out('knows').filter{it.age <

30}.name.transform{it.length()}

==>5 On the Nature of Pipes

Page 32: An Introduction to Tinkerpop

[Branch Pipes]

gremlin> g.v(1).out('knows').ifThenElse{it.age < 30}

{it.name}{it.out('created').name}

==>vadas

==>ripple

==>lop

On the Nature of Pipes

Page 33: An Introduction to Tinkerpop

[Meta Back Pipes]

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

==>vadas

==>josh

gremlin> g.v(1).out('knows').name.filter{it[0]=='v'}

==>vadas

gremlin>

g.v(1).out('knows').name.filter{it[0]=='v'}.back(2)

==>v[2]

Meta Pipes: “wraps” another pipe

On the Nature of Pipes

Page 34: An Introduction to Tinkerpop

gremlin>

g.v(1).out('knows').name.filter{it[0]=='v'}.back(2)

==

g.v(1).out('knows').as('here').name.filter{it[0]=='v'}.back('here')

[Meta Back Pipes]

On the Nature of Pipes

Page 35: An Introduction to Tinkerpop

[Meta Loop Pipes]

gremlin> g.v(1).out.loop(1){it.loops < 3}

==>v[5]

==>v[3]

loop 1 loop 2

1 step away from node1

loop condition

On the Nature of Pipes

Page 36: An Introduction to Tinkerpop

・Tinkerpop merges graph database ecosystem

・TinkerPop is based on the low-level Blueprints API

・Neo4j, OrientDB, DEX, RDF Sail, TinkerGraph, and Rexster are supported. (Infinite Graph near future)

・HBase (GraphBase) and Redis (Blueredis) are developed by a community

・Gremlin is a data flow graph processing using pipes

Summary