stefan plantikow, neo4j - amazon s3...2017/06/18  · 2017 stefan plantikow, neo4j match from graph...

49
2017 Stefan Plantikow, Neo4j Stefan Plantikow, Neo4j

Upload: others

Post on 06-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Stefan Plantikow, Neo4j

Page 2: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

2

Page 3: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 4: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

•••

••••••

4

Page 5: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

•• →•••

••

5

Page 6: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

•••••

••

6

Page 7: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 8: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j8

Page 9: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

●●●●

○○

Page 10: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 11: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j11

Page 12: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j12

Page 13: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j13

Page 14: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 15: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

••

15

Page 16: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

16

Page 17: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 18: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

CYPHER 2017

Page 19: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

CYPHER 2018

Page 20: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

●●●

Page 21: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

MATCH

FROM GRAPH cities

MATCH (city:City)-[:IN]->(:Country {name: "Germany"})

FROM GRAPH people

MATCH (person)-[:LIVES_IN]->(city)

RETURN person ORDER BY person.age LIMIT 1

Page 22: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

● GRAPH foo

● NEW GRAPH bar

● COPY GRAPH foo TO baz

● GRAPH foo AT "url"

● NEW GRAPH foo AT "url"

Page 23: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

CREATE, MERGE, DELETE

FROM GRAPH people

MATCH (alice)-[:KNOWS]->(bob)-[:KNOWS]->(charlie)

WHERE (bob)-[:LOVES]->(alice)<-[:LOVES]-(charlie)

AND (bob)<-[:LOVES]-(alice)-[:LOVES]->(charlie)

INTO GRAPH drama

CREATE (t:LoveTriangle)<-[:IN]-(alice),

(t)<-[:IN]-(bob), (t)<-[:IN]-(charlie)

RETURN DISTINCT alice.name

Page 24: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

● [OPTIONAL] MATCH

●● CREATE

○○

● MERGE

● SET/REMOVE

● DELETE

Page 25: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 26: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

MATCH (a)-->(b) WITH a, b ...

Page 27: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

WITH a, r, b RETURN GRAPH (a)-[r]->(b) AS foo

Page 28: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

MATCH (a:Person)-[:FRIEND*2]->(b:Person)

RETURN GRAPH (a)-[:FOAF]->(b) AS foo

MATCH (a:Person)-[:FRIEND*2]->(b:Person)

WITH GRAPH (a)-[:FOAF]->(b)

// Similar to (c)-[:FRIEND*4]->(d)

MATCH (c)-[:FOAF]->(d)

RETURN *

Page 29: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 30: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

WITH/RETURN

RETURN GRAPH foo

RETURN name, age, GRAPHS foo, bar, baz

WITH GRAPHS *

WITH GRAPHS *, NEW GRAPH myNewGraph AT "url"

WITH GRAPHS foo, bar, COPY GRAPH foo TO baz

Page 31: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

RETURN a, b, c, GRAPHS foo, bar

RETURN a, b, c

WITH a, b, c, GRAPHS foo, bar

WITH a, b, c

WITH GRAPHS ...

Page 32: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

● WITH ... GRAPH foo

● WITH ... GRAPHS foo, bar, baz

Page 33: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

WITH GRAPHS

FROM/INTO

WITH GRAPHS foo, bar >>

WITH GRAPHS foo, >> baz

WITH GRAPHS foo >> bar

Page 34: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

● COPY GRAPH foo TO "new-url"

● MOVE GRAPH foo TO "new-url"

● DELETE GRAPH foo

Page 35: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

●●●●●

Page 36: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 37: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 38: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

FROM GRAPH ActorsFilmsCities AT 'graph://actors_films_cities...'

MATCH (p:Person)-[:BORN_IN]->(c:City)INTO NEW GRAPH PersonCityEvents MERGE (p:Person {name: p.name, YOB: p.YOB})MERGE (c:City {name: c.name})MERGE (p)-[:BORN_IN]->(c)

RETURN GRAPH PersonCityEvents

Page 39: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

WITH GRAPH PersonCityEventsFROM GRAPH Events AT 'graph://events...'MATCH (c)<-[:IN_CITY]-(e)-[:IN_YEAR]->(y), (e)-[:IS_A]->(et {value: 'Criminal Event'})

// Do matches for all other event types: // Public Event, War Event.......INTO GRAPH PersonCityEventsMERGE (c:City {name: c.value})MERGE (e {title: e.value, year: y.value})MERGE (e)-[:HAPPENED_IN]->(c)SET e:WarEvent

// Do for all remaining event types...

RETURN count(*) AS matches

Page 40: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

WITH GRAPH PersonCityEventsMATCH (ce:CriminalEvent)-[:HAPPENED_IN]->(c:City)<-[:BORN_IN]-(p:Person)

INTO NEW GRAPH Temp-PersonCityCrimesMERGE (p:Person {name: p.name, YOB: p.YOB})MERGE (c:City {name: c.name})MERGE (ce:CriminalEvent

{title: ce.title, year: ce.year})MERGE (p)-[:BORN_IN]->(c)MERGE (ce)-[:HAPPENED_IN]->(c)

RETURN GRAPH Temp-PersonCityCrimes

Page 41: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 42: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

FROM GRAPH SalesDetail AT ‘graph://...’

MATCH (p:Product)-[rel:IN]->(:Order)<-[HAS]-(s:Store)-[:IN]->(r:Region)

WITH reg.name AS regionName,

s.code AS storeCode,

p.code AS productCode,

sum(rel.soldPrice * rel.numItemsSold)

AS storeProductTotal

regionName storeCode productCode storeProduct-Total

APAC AC-888 PEN-1 20.00

APAC AC-888 TOY-1 45.00

EMEA LK-709 BOOK-2 10.00

EMEA LK-709 TOY-1 40.00

EMEA LK-709 BOOK-5 15.00

EMEA WW-531 BOOK-5 18.00

EMEA WW-531 BULB-2 190.00

EMEA WW-531 PC-1 440.00

Page 43: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

RETURN regionName, storeCode, sum(storeProductTotal) AS totalStoreSalesGRAPH SalesSummary // not shown

regionName storeCode totalStoreSales

APAC AC-888 65.00

EMEA LK-709 65.00

EMEA WW-531 648.00

Page 44: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

Page 45: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

USE

FROM

INTO

Page 46: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

COPY GRAPH foo AS SNAPSHOT bar

CREATE (=p)

Page 47: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

SET GRAPH foo.prop = 42

REMOVE GRAPH foo.prop

SET GRAPH foo:SocialNetwork

REMOVE GRAPH foo:SocialNetwork

Page 48: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j

●●●●

MATCH (a:Person),

<g1 (a)-[:KNOWS]->(...)>,

<g2 (a)-[:LIVES_IN]->(...)>

RETURN GRAPH g1-g2 AS g

Page 49: Stefan Plantikow, Neo4j - Amazon S3...2017/06/18  · 2017 Stefan Plantikow, Neo4j MATCH FROM GRAPH cities MATCH (city:City)-[:IN]->(:Country {name: "Germany"}) FROM GRAPH people MATCH

2017 Stefan Plantikow, Neo4j