0

请告诉我一个简单的解决方案,因为我有数百万个节点,所以需要更少的时间:

  for(int i=1100000; i<=1200000;i++){
        GraphStatement q1 = new SimpleGraphStatement("g.addV(label, 'Asset','name','Asset"+i+"','type','"+1+"').as('a')").setGraphName("lookingglass");

    System.out.println("Added node----"+i);
    }

 for(int i=1100000;i<=1200000;i++){
        //int j=i+1;
    Vertex v1 = dseSession.executeGraph("g.V().has('name','Org"+1000+"')").one().asVertex();
    Vertex v2 = dseSession.executeGraph("g.V().has('name','Asset"+i+"')").one().asVertex();

    SimpleGraphStatement s = new SimpleGraphStatement(
            "def v1 = g.V(id1).next()\n" +
                    "def v2 = g.V(id2).next()\n" +
                    "v1.addEdge('HAS', v2)")
            .set("id1", v1)
            .set("id2", v2);

    dseSession.executeGraph(s);
    System.out.println("Added Edge "+i);
    }
    System.out.println("Done");

当我进行整个图形搜索时,这需要更长的时间。我们能否有一个简单的单个查询,可以添加一个 vartex 并将一条边添加到现有顶点,从而减少延迟?

注意我也尝试过使用以下方法,但以下方法似乎被贬低了,因此给出了错误(顶点不支持用户提供的标识符:

 g.addV().property(id, "A").as("a").
      addV().property(id, "B").property("value", 100).as("b").
      addV().property(id, "C").property("value", 200).as("c").
      addV().property(id, "D").property("value", 500).as("d").
      addV().property(id, "E").property("value", 1000).as("e").
      addV().property(id, "Z").property("value", 900).as("z").
      addE("link").from("a").to("b").property("weight", 80).
      addE("link").from("a").to("c").property("weight", 20).
      addE("link").from("b").to("d").property("weight", 50).
      addE("link").from("b").to("e").property("weight", 40).
      addE("link").from("z").to("d").property("weight", 10).iterate()
4

2 回答 2

4

您指定为“已弃用”的方法确实有效。DSE 图形和大多数图形数据库不允许您以这种方式分配标识符。请注意,如果您只是更改 to 的使用,id那么"myid"Gremlin 语法是可以接受的:

gremlin>  g.addV().property("myid", "A").as("a").
......1>    addV().property("myid", "B").property("value", 100).as("b").
......2>    addV().property("myid", "C").property("value", 200).as("c").
......3>    addV().property("myid", "D").property("value", 500).as("d").
......4>    addV().property("myid", "E").property("value", 1000).as("e").
......5>    addV().property("myid", "Z").property("value", 900).as("z").
......6>    addE("link").from("a").to("b").property("weight", 80).
......7>    addE("link").from("a").to("c").property("weight", 20).
......8>    addE("link").from("b").to("d").property("weight", 50).
......9>    addE("link").from("b").to("e").property("weight", 40).
.....10>    addE("link").from("z").to("d").property("weight", 10).iterate()
gremlin> g.V()
==>v[{~label=vertex, community_id=1368843392, member_id=512}]
==>v[{~label=vertex, community_id=1368843392, member_id=513}]
==>v[{~label=vertex, community_id=1368843392, member_id=514}]
==>v[{~label=vertex, community_id=1368843392, member_id=515}]
==>v[{~label=vertex, community_id=1368843392, member_id=516}]
==>v[{~label=vertex, community_id=1368843392, member_id=517}]
于 2017-01-27T11:49:44.790 回答
0

您可以简单地使用executeGraphAsync方法来加快插入速度,因为它本质上是异步的。

请看一下:-

https://docs.datastax.com/en/developer/java-driver-dse/1.1/manual/graph/

于 2017-01-31T10:40:18.883 回答