【发布时间】:2014-08-22 14:42:04
【问题描述】:
假设我有一个包含节点信息的 csv 文件,每一行都有一个唯一的 id(第一列),还有另一个包含边缘的 csv 文件,描述节点之间的边缘(通过它们的唯一 ID)。以下密码成功加载节点,然后创建边。但是,我可以提高效率吗?我的真实数据集有数百万个节点和数千万条边。显然,我应该使用定期提交并创建一个索引,但是我可以以某种方式避免 matching 对每条边进行处理,并使用我知道要构建的每条边的唯一节点 ID 的事实吗?还是我对这一切都错了?我想完全用 cypher(没有 java)来做这件事。
load csv from 'file:///home/user/nodes.txt' as line
create (:foo { id: toInt(line[0]), name: line[1], someprop: line[2]});
load csv from 'file:///home/user/edges.txt' as line
match (n1:foo { id: toInt(line[0])} )
with n1, line
match (n2:foo { id: toInt(line[1])} )
// if I had an index I'd use it here with: using index n2:foo(name)
merge (n1) -[:bar]-> (n2) ;
match p = (n)-->(m) return p;
nodes.txt:
0,node0,Some Property 0
1,node1,Some Property 1
2,node2,Some Property 2
3,node3,Some Property 3
4,node4,Some Property 4
5,node5,Some Property 5
6,node6,Some Property 6
7,node7,Some Property 7
8,node8,Some Property 8
9,node9,Some Property 9
10,node10,Some Property 10
...
edges.txt:
0,2
0,4
0,8
0,13
1,4
1,8
1,15
2,4
2,6
3,4
3,7
3,8
3,11
4,10
...
【问题讨论】:
-
如果您有这么多数据,则加载 csv 不是要走的路。你可以看看 Michael Hunger 制作的工具:github.com/jexp/batch-import