opencypher.org | [email protected]

Report 3 Downloads 32 Views
opencypher.org | [email protected]

opencypher.org | [email protected]

opencypher.org | [email protected]

opencypher.org | [email protected]

● ●

opencypher.org | [email protected]



opencypher.org | [email protected]

● ● ●

opencypher.org | [email protected]

opencypher.org | [email protected]

● ●



opencypher.org | [email protected]

opencypher.org | [email protected]

opencypher.org | [email protected]

Person

Person Director

name: Ed Jones age: 37 favColor: blue

FRIENDS since: 2003-05-12 qualified: good

opencypher.org | [email protected]

name: Peter Fry nick: Lil’ Pete bio: ...

● MATCH (me:Person)-[:FRIEND]->(friend)

● WHERE me.name = "Frank Black" AND friend.age > me.age

● RETURN friend.name, friend.title

● CREATE (you:Person) SET you.name = "Aaron Fletcher" CREATE (you)-[:FRIEND]->(me) ● MATCH (me:Person{name:$name})-[:FRIEND]-(friend) WITH me, count(friend) AS friends MATCH (me)-[:ENEMY]-(enemy) RETURN friends, count(enemy) AS enemies

opencypher.org | [email protected]

MATCH (), (node), (node:Node), (:Node), (node {type:"NODE"}) MATCH ()-->(), ()-[edge]->(), ()-[edge:RELATES]->(), ()-[:RELATES]->(), ()-[edge {score:5}]->(), (a)-[edge]->(b) (a)(movie)(m:Movie), (a:Actor)-[:ACTED_IN]->(m) RETURN min(a.age) } RETURN dtor.name AS young_director

opencypher.org | [email protected]

... WITH ... AS my_list RETURN [ UNWIND my_list AS item WHERE item.size < 15 RETURN item ] AS small_items

opencypher.org | [email protected]

... RETURN



opencypher.org | [email protected]

{ }

MATCH { // authored tweets MATCH (me:User {name: 'Alice'})-[:FOLLOWS]->(user:User), (user)(user:User), (user)(tweet:Tweet) RETURN tweet, favourite.time AS time, user.country AS country } WHERE country = 'se' RETURN DISTINCT tweet ORDER BY time DESC

opencypher.org | [email protected]

MATCH (u:User {id: $userId}) MATCH (f:Farm {id: $farmId})-[:IS_IN]->(country:Country) MATCH { MATCH (u)-[:LIKES]->(b:Brand)-[:PRODUCES]->(p:Lawnmower) RETURN b.name AS name UNION MATCH (u)-[:LIKES]->(b:Brand)-[:PRODUCES]->(v:Vehicle) WHERE v.leftHandDrive = country.leftHandDrive RETURN b.name AS name } RETURN f, name

opencypher.org | [email protected]

MANDATORY

OPTIONAL MATCH

MANDATORY MATCH (p:Person {name: 'Petra'}) MANDATORY MATCH (conf:Conference {name: $conf}) MANDATORY MATCH { MATCH (p)-[:ATTENDS]->(conf) RETURN conf } OPTIONAL MATCH { MATCH (p)-[:KNOWS]->(a:Attendee)-[:PUBLISHED_AT]->(conf) RETURN a.name AS name } RETURN name

opencypher.org | [email protected]

opencypher.org | [email protected]

● ● ● ●

opencypher.org | [email protected]

Graph => CYPHER 9 => Table

CYPHER 9 = Clause Clause Clause ... RETURN *

opencypher.org | [email protected]

opencypher.org | [email protected]

● WITH * ● ○ ○

WITH

val res1 = cypher("MATCH (a)-[r]->(b) RETURN *") val res2 = res1.cypher(" WITH a, r, b MATCH (b)-->(c) RETURN DISTINCT c") opencypher.org | [email protected]

Table => CYPHER => Table => CYPHER => ...

MATCH (a) MATCH { MATCH (a)-->(b) RETURN * } WITH * // keep going ...

opencypher.org | [email protected]

Graph => CYPHER => Graph => CYPHER => ...

Graph|Table => CYPHER => Graph|Table => CYPHER => ...

opencypher.org | [email protected]

Graph Transformation

Why Multiple Graphs? -

Combining and transforming graphs from multiple sources

-

Versioning, snapshotting, computing difference graphs

-

Graph views for access control

-

Provisioning applications with tailored graph views

-

Shaping and integrating heterogenous graph data

-

Roll-up and drill-down at different levels of detail

Graph Management

Graph Modeling

Cypher today: Single graph model Graph Database System (e.g. a cluster) Application Server Client 1 Client 2 Client 3

The (single) Graph

Cypher: Multiple graphs model Graph Database System (e.g. a cluster) Application Server Client 1 Client 2 Client 3

Graph Space

● ● ●

● opencypher.org | [email protected]

Tables from graphs... It's easy to construct tables from a graph... but what's the inverse? MATCH (a)-->(b) WITH a, b ...

...graphs from tables ...a graph is a set of pattern matches! WITH a, r, b RETURN GRAPH OF (a)-[r]->(b) AS foo

Current CAPS Multiple Graphs Syntax FROM GRAPH graph_A AT "bolt://.../people" MATCH (a:Person)-[:KNOWS]-(b:Person) FROM GRAPH graph_B AT "hdfs://.../products" MATCH (:Customer {name: a.name})-[:BOUGHT]->(p:Product) RETURN GRAPH OF (b)-[:SHOULD_BUY]->(p)

(Ongoing work in CIP2017-06-18: Multiple Graphs)

Cypher queries with multiple graphs

Cypher query pipeline composition

Cypher support for multiple graphs -

Graphs are addressed using URIs Graphs and tabular data are passed into and returned from a query

Extensions -

Set operations and subqueries over multiple graphs Updating graphs (DML) Managing graph persistence (Move, Snapshot, Version, ...) Creating views Schema and constraint definitions for multiple graphs ... => Join the openCypher MG Task Force

All this is made available in

(:Cypher)-[:FOR]->(:Apache:Spark) github.com/opencypher/cypher-for-apache-spark

opencypher.org | [email protected]

● ● ●



opencypher.org | [email protected]

● ●







opencypher.org | [email protected]

● ● ● ● ● ● ● ● ● ● ● ● ●

⟦ε⟧G = {(v,v) | v ∈ V} ⟦_⟧G = {(v,w)| (v,a,w) ∈ E a} ⟦a⟧G = {(v,w)| (v,a,w) ∈ E} ⟦a-⟧G = {(v,w) | (w,a,v) ∈ E} ⟦ɑ*⟧G = ɑ G G G ⟦ɑ · β⟧ = ⟦ɑ⟧ ⸰ ⟦β⟧ ⟦ɑ ∪ β⟧G = ⟦ɑ⟧G ∪ ⟦β⟧G ⟦¬ɑ⟧G = V ⨯ V - ⟦ɑ⟧G ⟦[φ]⟧G = {(v,v) | v ∈ ⟦φ⟧G} ⟦ɑn,m⟧G = ⋃k=nm(⟦ɑ⟧G)k ⟦ɑ=⟧G = {(v,w) ∈ ⟦ɑ=⟧G | ρ(v)=ρ(w)} ⟦ɑ≠⟧G = {(v,w) ∈ ⟦ɑ=⟧G | ρ(v)≠ρ(w)} ⟦ɑ ∩ β⟧G = ⟦ɑ⟧G ∩ ⟦β⟧G

grouped Edge label

direction

Edge label

MATCH (actor)-/[:ACTED_IN> a.age MATCH p = (me)-/ ~older_friends + /-(you) WHERE me.name = $myName AND you.name = $yourName RETURN p AS friendship

opencypher.org | [email protected]

PATH PATTERN older_friends = (a)-[:FRIEND]-(b) WHERE b.age > a.age PATH PATTERN same_city = (a)-[:LIVES_IN]->(:City)(msg), (b)-[:RECEIVED]->(msg) COST 1 / count(msg) MATCH p = (me)-/ ~influential_friends * /-(them) WHERE me.name = $myName AND them.name IN $names ORDER BY cost(p) ASC LIMIT 10 RETURN nodes(p)[1] AS target opencypher.org | [email protected]

opencypher.org | [email protected]

Recommend Documents