cypher for gremlin ocim 4 - amazon s3 · cypher for gremlin ocim 4. apache tinkerpop apache...
TRANSCRIPT
![Page 1: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/1.jpg)
Cypher for GremlinoCIM 4
![Page 2: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/2.jpg)
Apache TinkerPop
Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP).
Gremlin is a graph traversal language developed by Apache TinkerPop.
![Page 3: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/3.jpg)
Gremlin in the wild
![Page 4: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/4.jpg)
Gremlin in the wild
IBM Graph
![Page 5: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/5.jpg)
Gremlin in the wild
IBM Graph
![Page 6: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/6.jpg)
Gremlin in the wild
IBM Graph
Azure Cosmos DB
![Page 7: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/7.jpg)
Gremlin in the wild
IBM Graph
Azure Cosmos DB
Amazon Neptune
![Page 8: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/8.jpg)
Gremlin language
gremlin> g.V().count()==>0gremlin> g.addV('City').property('name', 'København')gremlin> g.V().count()==>1gremlin> g.V().hasLabel('City').values('name')==>København
![Page 9: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/9.jpg)
Declarative vs imperative querying
// Cypher: what to getMATCH (b:Boat)-[:SAILS_TO]->(:Location {name: 'Denmark'})RETURN b
// Gremlin: how to get itg.V().hasLabel('Boat').as('b') .out('SAILS_TO') .hasLabel('Location').has('name', 'Denmark') .select('b')
![Page 10: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/10.jpg)
Gremlin traversal
g.V().hasLabel('Boat').as('b') .out('SAILS_TO') .hasLabel('Location').has('name', 'Denmark') .select('b') .profile()
Step Count
TinkerGraphStep(vertex,[~label.eq(Boat)])@[b] 100000
VertexStep(OUT,[SAILS_TO],vertex) 100000
HasStep([~label.eq(Location), name.eq(Denmark)]) 1
SelectOneStep(last,b) 1
![Page 11: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/11.jpg)
Gremlin traversal (the right way)
g.V().hasLabel('Location').has('name', 'Denmark') .in('SAILS_TO') .hasLabel('Boat') .profile()
Step Count
TinkerGraphStep(vertex,[~label.eq(Location), name.eq(Denmark)]) 1
VertexStep(IN,[SAILS_TO],vertex) 1
HasStep([~label.eq(Boat)]) 1
![Page 12: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/12.jpg)
Cypher in Gremlin
// MATCH (b:Boat)-[:SAILS_TO]->(:Location {name: 'Denmark'})// RETURN b.name
g.V().hasLabel('Boat').as('b') .out('SAILS_TO') .hasLabel('Location').has('name', 'Denmark') .select('b').values('name')
==>"Havhingsten fra Glendalough"==>"Roar Ege"
![Page 13: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/13.jpg)
Cypher in Gremlin: return columns
// MATCH (b:Boat)-[:SAILS_TO]->(:Location {name: 'Denmark'})// RETURN b.name
g.V().hasLabel('Boat').as('b') .out('SAILS_TO') .hasLabel('Location').has('name', 'Denmark') .select('b').project('b.name').by(values('name'))
==>{"b.name": "Havhingsten fra Glendalough"}==>{"b.name": "Roar Ege"}
![Page 14: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/14.jpg)
Null handling in Gremlin
gremlin> g.addV('Boat').property('name', 'Roar Ege')==>v[0]gremlin> g.addV('Boat')==>v[1]gremlin> g.V().count()==>2gremlin> g.V().hasLabel('Boat').values('name')==>Roar Egegremlin> g.V().hasLabel('Boat').project('name').by(values('name'))==>[name:Roar Ege]The provided traverser does not map to a value: v[5]->[PropertiesStep([name],value)]
![Page 15: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/15.jpg)
Cypher in Gremlin: nulls
// MATCH (b:Boat)-[:SAILS_TO]->(:Location {name: 'Denmark'})// RETURN b.name
g.V().hasLabel('Boat').as('b') .out('SAILS_TO') .hasLabel('Location').has('name', 'Denmark') .select('b').project('b.name').by( choose(neq('NULL'), coalesce(values('name'), constant('NULL')), constant('NULL')))
![Page 16: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/16.jpg)
Cypher in Gremlin: traversal-based logic
// RETURN $a AND $b
g.inject('START').project('$a AND $b').by( choose( and(constant(a).is(eq(true)), constant(b).is(eq(true))), constant(true), choose( or(constant(a).is(eq(false)), constant(b).is(eq(false))), constant(false), constant('NULL'))))
![Page 17: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/17.jpg)
Translation flow
![Page 18: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/18.jpg)
82.5%731 scenarios
(with Server plugin)
Cypher TCK progress
![Page 19: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/19.jpg)
● Functionality exclusive to Gremlin Servers with Cypher plugin:
○ List access by non-constant index
○ Map access
○ Non-numeric plus operator
○ Path comprehensions
○ Functions with non-native implementation: length, nodes, percentileCont, percentileDisc, properties,
relationships, size, toBoolean, toFloat, toInteger, toString
● Multiple labels and label modification are not supported
○ TinkerPop graph elements have a single, immutable string label
○ No plans for a workaround
Major limitations
![Page 20: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/20.jpg)
Cypher for Gremlin integration
Gremlin Serverwithout Cypher plugin
Gremlin Serverwith Cypher plugin
Gremlin driver ❌ ✔ server-side translation
Cypher Gremlin clientfor Java ✔ client-side translation ✔ server-side translation
Gremlin Console ❌ ❌
Gremlin Consolewith Cypher plugin ✔ client-side translation ✔ server-side translation
![Page 21: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/21.jpg)
It’s on GitHub!
https://github.com/opencypher/cypher-for-gremlin
![Page 22: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/22.jpg)
● Cypher to Gremlin translation library for Java
● Cypher plugin for Gremlin Server
● Cypher plugin for Gremlin Console
● Cypher wrapper for Gremlin client
● Neo4j driver API wrapper
● TCK implementation for Gremlin
It’s on GitHub!
https://github.com/opencypher/cypher-for-gremlin
![Page 23: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/23.jpg)
Java APIs: translation
String cypher = "MATCH (p:Person) WHERE p.age > 25 RETURN p.name";CypherAstWrapper ast = CypherAstWrapper.parse(cypher);
Translator<String, GroovyPredicate> translator =Translator.builder().gremlinGroovy().build();
String gremlin = ast.buildTranslation(translator);
![Page 24: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/24.jpg)
Java APIs: Gremlin Server client
Cluster cluster = Cluster.open(configuration);Client gremlinClient = cluster.connect();CypherGremlinClient cypherGremlinClient =
CypherGremlinClient.translating(gremlinClient);
String cypher = "MATCH (p:person) WHERE p.age > 25 RETURN p.name";CypherResultSet resultSet = cypherGremlinClient.submit(cypher);List<Map<String, Object>> results = resultSet.all();
![Page 25: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/25.jpg)
Java APIs: Neo4j driver
Config config = Config.build() .withTranslation() .toConfig();Driver driver = GremlinDatabase.driver("//localhost:8182", config);
String cypher = "MATCH (p:person) WHERE p.age > 25 RETURN p.name";try (Session session = driver.session()) { StatementResult result = session.run(cypher); List<Record> records = result.list();}
![Page 26: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/26.jpg)
Java APIs: In-memory graphs
TinkerGraph graph = TinkerFactory.createModern();GraphTraversalSource traversal = graph.traversal();
// Gremlin Server clientCypherGremlinClient cypherGremlinClient = CypherGremlinClient.inMemory(traversal);
// Neo4j driverDriver driver = GremlinDatabase.driver(traversal);
![Page 27: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/27.jpg)
Java APIs: In-memory graphs
// SimpleGraph ExcelExcelSystem excelSystem = new ExcelSystem();excelSystem.connect();excelSystem.moveTo(new File("graph.xlsx").toURI().toString());GraphTraversalSource traversal = excelSystem.g();
CypherGremlinClient cypherGremlinClient = CypherGremlinClient.inMemory(traversal);
![Page 28: Cypher for Gremlin oCIM 4 - Amazon S3 · Cypher for Gremlin oCIM 4. Apache TinkerPop Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) ... Step Count](https://reader030.vdocuments.us/reader030/viewer/2022040308/5ed736a0d37f9f58ca6a7b42/html5/thumbnails/28.jpg)
Quick start
// Add dependenciescompile "org.apache.tinkerpop:tinkergraph-gremlin:3.3.2"compile "org.opencypher.gremlin:cypher-gremlin-neo4j-driver:0.9.6"
// Create an in-memory graphTinkerGraph graph = TinkerFactory.createModern();GraphTraversalSource traversal = graph.traversal();Driver driver = GremlinDatabase.driver(traversal);
// Query as usual: driver.session()... etc// (Except transactions)