cypher for gremlin and more and more and more match p
play

Cypher for Gremlin And more... And more... And - PowerPoint PPT Presentation

Cypher for Gremlin And more... And more... And more... MATCH (p:Planet)-[orbit:ORBITS]->(:Star {name: 'Sun'}) WHERE orbit.au < 5 RETURN p AS planet; g.V().as('p').hasLabel('Planet')


  1. • • • • • • •

  2. Cypher for Gremlin And more... And more... And more...

  3. MATCH (p:Planet)-[orbit:ORBITS]->(:Star {name: 'Sun'}) WHERE orbit.au < 5 RETURN p AS planet; g.V().as('p').hasLabel('Planet') .outE('ORBITS').has('au', lt(5)) .inV().hasLabel('Star').has('name', eq('Sun')) .select('p').project('planet').by(valueMap().with(tokens))

  4. ● ● ● ● ● And more...

  5. ● ○ ● ○

  6. • gremlin(...) • • • • MATCH (n:person {name: 'marko'}) RETURN gremlin("select('n').outE().label()") as r

  7. Translator<String, GroovyPredicate> translator = Translator.builder() .gremlinGroovy() .enableCypherExtensions() .enable(TranslatorFeature.EXPERIMENTAL_GREMLIN_FUNCTION) .build();

  8. * As suggested in GQL Scope and Features

  9. Prototype QUERY friends($a VERTEX) { MATCH ($a)-[:FRIEND_OF]-(b) RETURN count(b) AS num_friends } CALL friends(a) YIELD num_friends QUERY friends($a VERTEX) { FOREIGN "gremlin" CALL "a.outE('FRIEND_OF').count().as('num_friends')" YIELD num_friends::NUMERIC }

  10. Prototype • MATCH (n) FOREIGN "gremlin" USING n CALL "n.hasLabel('person').as('p').values('age').as('b')" YIELD p, b RETURN labels(p)[0] as a, b LIMIT 1

  11. Prototype MATCH (n) FOREIGN "gremlin" CALL "select('n').hasLabel('person').as('p').values('age').as('b')" YIELD p, b RETURN labels(p)[0] as a, b LIMIT 1

  12. Prototype • MATCH (n) FOREIGN "gremlin" CALL "select('n').hasLabel('person').as('p').values('age').as('b')" YIELD p::NODE, b::NUMERIC RETURN labels(p)[0] as a, b LIMIT 1

  13. Prototype • • WITH 1 as n FOREIGN "gremlin" CALL "constant(2).as('n')" RETURN n //n = 1

  14. • • • • •

  15. • • • • gremlin> g.cypher("MATCH (n) RETURN n").select("n").outE().label().dedup() ==>created ==>knows

  16. 1. 2. 3.

  17. SELECT ?a ?b ?c WHERE { ?a v:label "person" . ?a e:knows ?b . ?a e:created ?c . ?b e:created ?c . ?a v:age ?d . FILTER (?d <= 30) } g.V() .match ( match()-step .as(‘a’).hasLabel(‘person’), .as(‘a’).out(‘knows’).as(‘b’), .as(‘a’).out(‘created’).as(‘c’), .as(‘b’).out(‘created’).as(‘c’), .as(‘a’).values(‘age’).as(‘d’). where ('d',lte(30))). select (‘a’,’b’,’c’)

  18. ● ● gremlin> :install org.apache.tinkerpop sparql-gremlin 3.4.0 ==>Loaded: [org.apache.tinkerpop, sparql-gremlin, 3.4.0] gremlin> :plugin use tinkerpop.sparql ==>tinkerpop.sparql activated gremlin> graph = TinkerFactory.createModern() ==>tinkergraph[vertices:6 edges:6] gremlin> g = graph.traversal( SparqlTraversalSource ) ==>sparqltraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> g.sparql("""SELECT ?name ?age WHERE { ?person v:name ?name . ?person v:age ?age } ORDER BY ASC(?age)""") ==>[name:vadas,age:27] ==>[name:marko,age:29] ==>[name:josh,age:32] ==>[name:peter,age:35]

  19. ● ● ● gremlin>g. sparql ("SELECT * WHERE { }").outE().label().dedup() ==>created ==>knows similar to … gremlin> g.cypher("MATCH (n) RETURN n").select("n").outE().label().dedup() ==>created ==>knows

  20. ● ● ● conceptual example: SELECT ?a WHERE { ?a v:label "person" . { GREMLIN(select(“a”).values(“name”)) } }

  21. SELECT •

  22. http://gremlinator.iai.uni-bonn.de:8080/Demo/ http://195.201.31.31:8080/Demo/ (mirror)

  23. ● ●

  24. Cypher for Gremlin • • •

Recommend


More recommend