【问题标题】:Temporal Graph Databases for event based data用于基于事件的数据的时态图数据库
【发布时间】:2015-05-07 01:04:47
【问题描述】:
我收到的数据告诉我发生了特定事件的事件。
例子:
- Box #1 于 2015-02-15 10:00 位于位置 A。
- Box #1 已于 2015-02-15 10:15 放入 Box #2。
- 2015 年 2 月 15 日 11:00 已将 Box #2 放入 Box #3。
- Box #3 于 2015-02-16 03:00 位于位置 B。
- 2015 年 2 月 16 日 04:30 从 Box #3 中删除了 Box #2。
- Box #3 于 2015-02-16 05:00 位于位置 C。
我有三个主要要求:
- 我现在应该能够知道我所有的盒子在哪里查询。
例如在 2015-02-16 06:00 查询应该得到。Box #1 在 Box #2 的位置 B。Box #3 在位置 C,里面什么都没有。
-
我应该能够看到发生在特定盒子上的一切。
例如对于框 #1:
- 2015-02-15 10:00 在位置 A
- 于 2015-02-15 10:15 被放入 Box #2 中
- 在 2015 年 2 月 15 日 11:00 放入 Box #3 的 Box #2 内
- 在 2015 年 2 月 16 日 03:00 位于位置 B 的 Box #3 中的 Box #2 内。
- 在 2015 年 2 月 16 日 04:30 从 Box #3 中移除的 Box #2 内。
我应该能够分辨出所有箱子在特定时间的位置。
例如2015-02-16 10:30,Box #1 在 Box #2 的位置 A。
我一直在研究图形数据库,因为它们似乎比关系数据库更好地处理这种类型的关系(尝试在 Sql 中进行递归查询并不容易)。
看起来我需要一个 Box 节点、一个 Location 节点和它们之间的边,用于关系“Inside”和“At”。
但我不确定如何将时间要求纳入图形模型。
我查看了this,但不确定如何使其符合我的要求。
另外请注意:这必须扩展到 1-40 亿个盒子,每个盒子包含 1 到 5000 个事件。
并且能够在第二次处理数千个事件
【问题讨论】:
标签:
neo4j
graph-databases
temporal-database
【解决方案1】:
有趣的问题
以下是根据您的示例制作的一些示例数据。这是您的问题的一种可能实现方式。
// create the boxes and the locations and add relationships
// between them. On each relationship add a time.
create (b1:Box {name: 'Box #1'})
create (b2:Box {name: 'Box #2'})
create (b3:Box {name: 'Box #3'})
create (lA:Location {name: 'A'})
create (lB:Location {name: 'B'})
create (lC:Location {name: 'C'})
create b1-[:AT {time: '2015-02-15 10:00'}]->lA
create b1-[:INSIDE {time: '2015-02-15 10:15'}]->b2
create b2-[:INSIDE {time: '2015-02-15 11:00'}]->b3
create b3-[:AT {time: '2015-02-16 03:00'}]->lB
create b2-[:REMOVED {time: '2015-02-16 04:30'}]->b3
create b3-[:AT {time: '2015-02-16 05:00'}]->lC
return *
这是一个查询以特定框开头的图形的查询。总体策略是拉回有向的盒子链。在这个例子中,我只是选择了最长的链。返回每条路径,按时间排序并选择时间最晚的路径可能会更完整。
获得路径后,我从中删除节点并对其进行迭代并匹配位置和路径。我为每个人拉回了关系类型和时间。
match p=(b:Box {name: 'Box #1'})-[:INSIDE|REMOVED*]->(:Box)
with p
order by length(p) desc
limit 1
with nodes(p) as boxes
unwind boxes as box
optional match box-[rel:AT|INSIDE|REMOVED]->(box_spot)
return rel.time as Time
, box.name as Box
, type(rel) as Directive
, box_spot.name as Spot
order by rel.time
这肯定可以通过更多用例得到改进和增强。该模型不适合按次查询模型。时代是关系的弦乐。 A 这次 neo4j 不允许对关系上的属性进行索引。我认为该模型在选择一个盒子并跟随它结束时效果很好。