如何将csv文件加载到janusgraph(addVertex和addEdge)?

时间:2017-08-15 13:31:22

标签: gremlin janusgraph

我在下面有以下gremlin命令。它可以正常工作。

新文件(" data / 1a78de40-8f0a-1028-9c9e-db07163b51b2.csv")。eachLine {l-> p = l.split(",") ; V1 = GV()具有('的uuid',p [0])?: graph.addVertex('的uuid',p [0]); V2 = GV()。已经('的uuid',p [1])?: graph.addVertex('的uuid',p [1]);}

但以下情况不会很好。

新文件(&#34; data / 1a78de40-8f0a-1028-9c9e-db07163b51b2.csv&#34;)。eachLine {l-&gt; p = l.split(&#34;,&#34;) ; V1 = GV()具有(&#39;的uuid&#39;,p [0])?: graph.addVertex(&#39;的uuid&#39;,p [0]); V2 = GV()。已经(&#39;的uuid&#39;,p [1])?: graph.addVertex(&#39;的uuid&#39;,p [1]); v1.addEdge(对[4],V2)} < / p>

错误在于:

的gremlin&GT;新文件(&#34; data / 1a78de40-8f0a-1028-9c9e-db07163b51b2.csv&#34;)。eachLine {l-&gt; p = l.split(&#34;,&#34;); v1 = GV()具有(&#39;的uuid&#39;,p [0])。?: graph.addVertex(&#39;的uuid&#39;,p [0]); V2 = GV()具有(& #39;的uuid&#39;,p [1])?: graph.addVertex(&#39;的uuid&#39;,p [1]); v1.addEdge(对[4],V2)}

21:30:12 WARN org.janusgraph.graphdb.transaction.StandardJanusGraphTx - 查询需要迭代所有顶点[(uuid = 1a78de40-8f0a-1028-9c9e-db07163b51b2)]。为了获得更好的性能,请使用索 21:30:12 WARN org.janusgraph.graphdb.transaction.StandardJanusGraphTx - 查询需要迭代所有顶点[(uuid = d803d140-8f0a-1028-98de-db07163b51b2)]。为了获得更好的性能,请使用索 21:30:12 WARN org.janusgraph.graphdb.transaction.StandardJanusGraphTx - 查询需要迭代所有顶点[(uuid = 1a78de40-8f0a-1028-9c9e-db07163b51b2)]。为了获得更好的性能,请使用索 21:30:12 WARN org.janusgraph.graphdb.transaction.StandardJanusGraphTx - 查询需要迭代所有顶点[(uuid = 92df9f40-8f0a-1028-8723-db07163b51b2)]。为了获得更好的性能,请使用索 没有方法签名:org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.addEdge()适用于参数类型:(java.lang.String,org.janusgraph.graphdb.vertices.StandardVertex)值:[CommunitiesMember,v [122908672]] 输入&#39;:help&#39;或者&#39;:h&#39;求助。 显示堆栈跟踪? [YN]

csv文件如下: 1a78de40-8f0a-1028-9c9e-db07163b51b2,d803d140-8f0a-1028-98de-db07163b51b2,2012-09-18T08:56:01Z,1,CommunitiesMember 1a78de40-8f0a-1028-9c9e-db07163b51b2,92df9f40-8f0a-1028-8723-db07163b51b2,2012-09-18T08:56:01Z,1,CommunitiesMember 1a78de40-8f0a-1028-9c9e-db07163b51b2,281edc40-3c20-102c-9a69-980191c9f99a,2012-09-18T08:56:01Z,1,CommunitiesMember 1a78de40-8f0a-1028-9c9e-db07163b51b2,878c73c0-8f0a-1028-91a1-db07163b51b2,2012-09-18T08:56:01Z,1,CommunitiesMember 1a78de40-8f0a-1028-9c9e-db07163b51b2,5427d240-9f1e-102C-9233-9c1aa9e13df3,2012-09-18T08:56:01Z,1,CommunitiesMember

1 个答案:

答案 0 :(得分:1)

这里的问题是您正在分配遍历而不是为变量分配顶点。

new File("data/1a78de40-8f0a-1028-9c9e-db07163b51b2.csv").eachLine{
  l->p=l.split(",");
  t_v1= g.V().has('uuid',p[0]);
  v1 = t_v1.hasNext() ? t_v1.next() : graph.addVertex('uuid',p[0]);
  t_v2 = g.V().has('uuid',p[1]);
  v2 = t_v2.hasNext() ? t_v2.next() : graph.addVertex('uuid',p[1]);
  v1.addEdge(p[4],v2);
}

应该有用。