This document discusses Cypher for Gremlin, which provides the ability to run Cypher queries against Gremlin databases. It covers the Gremlin and Cypher query languages, examples of translating Cypher to Gremlin, and the Java APIs for client-side and server-side translation of Cypher to Gremlin.
2. 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.
9. Declarative vs imperative querying
// Cypher: what to get
MATCH (b:Boat)-[:SAILS_TO]->(:Location {name: 'Denmark'})
RETURN b
// Gremlin: how to get it
g.V().hasLabel('Boat').as('b')
.out('SAILS_TO')
.hasLabel('Location').has('name', 'Denmark')
.select('b')
11. 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
12. 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"
13. 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"}
14. Null handling in Gremlin
gremlin> g.addV('Boat').property('name', 'Roar Ege')
==>v[0]
gremlin> g.addV('Boat')
==>v[1]
gremlin> g.V().count()
==>2
gremlin> g.V().hasLabel('Boat').values('name')
==>Roar Ege
gremlin> 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)]
19. ● 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
20. Cypher for Gremlin integration
Gremlin Server
without Cypher plugin
Gremlin Server
with Cypher plugin
Gremlin driver ❌ ✔ server-side translation
Cypher Gremlin client
for Java
✔ client-side translation ✔ server-side translation
Gremlin Console ❌ ❌
Gremlin Console
with Cypher plugin
✔ client-side translation ✔ server-side translation
22. ● 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