cypher for gremlin - amazon s3€¦ · apache tinkerpop apache tinkerpop™ is a graph computing...
TRANSCRIPT
Cypher for GremlinoCIG 7
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.
Gremlin in the wild
Gremlin language
gremlin> g.V().count()==>0gremlin> g.addV('person').properties('name', 'Marko')gremlin> g.V().count()==>1gremlin> g.V().hasLabel('person').values('name')==>Marko
MATCH (p:Planet)-[orbit:ORBITS]->(:Star {name: 'Sun'}) WHERE orbit.au < 5RETURN p AS planet;
g.V().as('p').outE('ORBITS').as('orbit').inV().as(' UNNAMED34') .where(and( select('p').hasLabel('Planet'), select(' UNNAMED34').values('name').is(eq('Sun')), select(' UNNAMED34').hasLabel('Star'), select('orbit').values('au').is(lt(5)) )) .select('p').map(project('planet').by(identity()))
The gist
Clauses Other Patterns Functions
MATCH
RETURN
UNWIND
OPTIONAL MATCH
WITH
UNION
CREATE
MERGE
SET
DETACH DELETE
ON CREATE
ON MATCH
WHERE
ORDER BY
SKIP
LIMIT
DISTINCT
(n:L {k: ‘v’})
()-->()
()--()
()-[r:L {k: ‘v’}]-()
(n)-[r]-(m)
()-[]-()-[]-()
()-[*n]-()
[x IN … | …]
avg, collect, count,
max, min, sum
keys, labels, nodes,
relationships, size
type, exists,
type conversion,
string matching
It is not guaranteed, however, that all combinations of the listed clauses, patterns, or functions will work.You are welcome to report any issues with the translation that you encounter.
Cypher → Gremlin translation
● Cypher to Gremlin translation library for Java
● Cypher for Gremlin Server (plugin)
● Cypher for Gremlin Console (plugin)
● Cypher wrapper for Gremlin client
● Neo4j driver-like API wrapper
● TCK implementation for Gremlin
Cypher for Gremlin open source
https://github.com/opencypher/cypher-for-gremlin
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
59%523 scenarios
Cypher Technology Compatibility Kit
Query performance tests
● Setup:○ “Movies” graph (171 nodes, 506 rels)○ One benchmark = one query execution○ Warmup: 1 iteration, 1 sec each○ Measurement: 5 iterations, 1 sec each
● Targets:○ Gremlin Server with TinkerGraph backend
and Cypher for Gremlin plugin○ No-op with query translation only
● Hardware:○ Intel Core i5-6200U CPU @ 2.30GHz○ Linux 4.14.4-1-ARCH x86_64○ JDK 1.8.0_144, VM 25.144-b01○ JMH 1.17.4
BenchmarkTinkerGraphavg ms/op
Translationavg ms/op
allNodes 7.019 1.069allPaths 7.208 1.495byLabel 4.367 1.246byLongPath 6.899 2.407byMultiplePaths 306.611 3.442byPath 3.902 1.923byProperty 3.618 1.468byUndirectedPath 5.037 2.113byVariablePath 448.726 2.079countWithPivot 3.917 1.790groupByProperty 5.295 1.766limit 3.261 1.229orderBy 5.268 2.808relationshipTypes 3.823 1.747wherePropertyBetween 3.884 2.097
Java APIs: translation/* * 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);
Java APIs: Gremlin Server client/* * 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();
Neo4j, Gremlin
Server, and Cosmos
DB running
side-by-side