Graph cafe-lightning

Post on 28-Nov-2014

1.553 views 0 download

description

lightning talk at graph cafe London about date and time modelling in Neo4j

Transcript of Graph cafe-lightning

http://xkcd.com/230/

The problem with perspective is that it’s bidirectional

representing dates/times (using neo4j 1.9.5)

root (0)

Year: 2013Month: 05

Month 01

:year_2014

:month_01

:year_2013

Year: 2014

Month: 06Day: 24 Day: 25

:day_24

Day: 26

Event 1 Event 2 Event 3

:happens

representing dates/times

:month_06

:month_05

:day_25 :day_26

:happens :happens :happens

find all events on a specific day

START root=node(0)MATCH root-[:year_2013]-()-[:month_05]-()-[:day_24]-()- [:happens]-event RETURN event

root (0)

Year: 2013Month: 05

Month 01

:year_2014

:month_01

:year_2013

Year: 2014

Month: 06Day: 24 Day: 25

:day_24

Day: 26

Event 1 Event 2 Event 3

:happens

representing dates/times

:month_06

:month_05

:day_25 :day_26

:happens :happens :happens

find all events for a given range

root (0)

Year: 2013Month: 05

Month 01

:year_2014

:month_01

:year_2013

Year: 2014

Month: 06Day: 24 Day: 25

:day_24

Day: 26

Event 1 Event 2 Event 3

:happens

:month_06

:month_05

:day_25 :day_26

:happens :happens :happens

:next :next

find all events for a given range

START root=node(0)MATCH root-[:year_2013]-()-[:month_05]-()-[:day_24]-start, root-[:year_2013]-()-[:month_05]-()-[:day_26]-end, start-[:next*0..]-middle-[:next*0..]-end, middle-[:happens]-event RETURN event

find all events for a given range

root (0)

Year: 2013Month: 05

Month 01

:year_2014

:month_01

:year_2013

Year: 2014

Month: 06Day: 24 Day: 25

:day_24

Day: 26

Event 1 Event 2 Event 3

:happens

:month_06

:month_05

:day_25 :day_26

:happens :happens :happens

:next :next

find all events for a given range

root (0)

Year: 2013Month: 05

Month 01

:year_2014

:month_01

:year_2013

Year: 2014

Month: 06Day: 24 Day: 25

:day_24

Day: 26

Event 1 Event 2 Event 3

:happens

:month_06

:month_05

:day_25 :day_26

:happens :happens :happens

:next :next

find all events for a given range

root (0)

Year: 2013Month: 05

Month 01

:year_2014

:month_01

:year_2013

Year: 2014

Month: 06Day: 24 Day: 25

:day_24

Day: 26

Event 1 Event 2 Event 3

:happens

:month_06

:month_05

:day_25 :day_26

:happens :happens :happens

:next :next

find all events for a given range

root (0)

Year: 2013Month: 05

Month 01

:year_2014

:month_01

:year_2013

Year: 2014

Month: 06Day: 24 Day: 25

:day_24

Day: 26

Event 1 Event 2 Event 3

:happens

:month_06

:month_05

:day_25 :day_26

:happens :happens :happens

:next :next

find all events for a given range

START root=node(0)MATCH root-[:year_2013]-()-[:month_05]-()-[:day_24]-start, root-[:year_2013]-()-[:month_05]-()-[:day_26]-end, start-[:next*0..]-middle-[:next*0..]-end, middle-[:happens]-event RETURN event

does an event happen on a certain date?

START event=node(20)MATCH event-[:day_24]-()-[:month_05]-()-[:year_2013]-() RETURN event

root (0)

Year: 2013Month: 05

Month 01

:year_2014

:month_01

:year_2013

Year: 2014

Month: 06Day: 24 Day: 25

:day_24

Day: 26

Event 1 (20) Event 2 Event 3

:happens

does an event happen on a certain date?

:month_06

:month_05

:day_25 :day_26

:happens :happens :happens

property vs. relationship type

constructing cypher queries execution plan cache vs. property load creating and deleting calendar graph

START root=node(0)MATCH root-[:year_2013]-()-[:month_05]-()-[:day_24]-()- [:hour] - (hour_node) - [:happens]-event WHERE hour_node.hour = {hour}RETURN event

mixed property/relationship type

START ref_node = node(0)CREATE UNIQUE ref_node - [:year_2013] -> (year_node {year: {year}}) - [:month_11] -> (month_node {month: {month}}) - [:day_27] -> (day_node {day: {day}}) - [:hour] -> (hour_node {hour: {hour}}) RETURN hour_node

calendar creation

root (0)

Year: 2013Month: 05

Month 01

:year_2014

:month_01

:year_2013

Year: 2014

Month: 06Day: 24 Day: 25

:day_24

Day: 26

Event 1 Event 2 Event 3

:happens

deleting calendar

:month_06

:month_05

:day_25 :day_26

:happens :happens :happens

QUESTIONS?

Volker Pacher !

volker@shutl.com www.shutl.com