incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

appendVertexProperty 对SET和LIST类型没有追加,而是覆盖

Open shenxinyu opened this issue 7 years ago • 4 comments

用 hugegraph client的driver,调用appendVertexProperty时, 对SET和LIST类型属性没有追加,而是覆盖

而直接用curl调用服务器resetapi是可以追加的

shenxinyu avatar Aug 20 '19 14:08 shenxinyu

追加属性使用vertex.property(k, v)方法即可。

你测试不通过可能是以前版本的问题。我使用 1.7.5 的 client,在 0.9.2 和 0.10 的 server上都是能追加的,请参考示例:

public static void main(String[] args) throws IOException {
        // If connect failed will throw a exception.
        HugeClient hugeClient = new HugeClient("http://localhost:8080",
                                               "hugegraph");

        SchemaManager schema = hugeClient.schema();

        schema.propertyKey("name").asText().ifNotExist().create();
        schema.propertyKey("age").asInt().ifNotExist().create();
        schema.propertyKey("city").asText().valueSet().ifNotExist().create();
        schema.propertyKey("weight").asDouble().ifNotExist().create();
        schema.propertyKey("lang").asText().ifNotExist().create();
        schema.propertyKey("date").asDate().ifNotExist().create();
        schema.propertyKey("price").asInt().ifNotExist().create();

        schema.vertexLabel("person")
              .properties("name", "age", "city")
              .primaryKeys("name")
              .ifNotExist()
              .create();

        schema.vertexLabel("software")
              .properties("name", "lang", "price")
              .primaryKeys("name")
              .ifNotExist()
              .create();

        GraphManager graph = hugeClient.graph();
        Vertex marko = graph.addVertex(T.label, "person", "name", "marko",
                                       "age", 29, "city", "Beijing");
        Vertex vadas = graph.addVertex(T.label, "person", "name", "vadas",
                                       "age", 27, "city", "Hongkong");
        Vertex lop = graph.addVertex(T.label, "software", "name", "lop",
                                     "lang", "java", "price", 328);
        Vertex josh = graph.addVertex(T.label, "person", "name", "josh",
                                      "age", 32, "city", "Beijing");
        Vertex ripple = graph.addVertex(T.label, "software", "name", "ripple",
                                        "lang", "java", "price", 199);
        Vertex peter = graph.addVertex(T.label, "person", "name", "peter",
                                       "age", 35, "city", "Shanghai");

        Vertex vertex = new Vertex(marko.label());
        vertex.id(marko.id());
        vertex.property("city", "Hongkong1");
        graph.appendVertexProperty(vertex);
        // 建议使用这种方式
        marko.property("city", "Hongkong2");

        graph.listVertices(-1).forEach(v -> System.out.println(v));

        hugeClient.close();
    }

结果:

{id=2:lop, label=software, properties={name=lop, lang=java, price=328}}
{id=1:josh, label=person, properties={name=josh, age=32, city=[Beijing]}}
{id=1:marko, label=person, properties={name=marko, age=29, city=[Beijing, Hongkong1, Hongkong2]}}
{id=1:peter, label=person, properties={name=peter, age=35, city=[Shanghai]}}
{id=1:vadas, label=person, properties={name=vadas, age=27, city=[Hongkong]}}
{id=2:ripple, label=software, properties={name=ripple, lang=java, price=199}}

Linary avatar Aug 21 '19 06:08 Linary

我的是scala代码 ,下面两段代码,当两段代码在一个进程里执行时,结果是追加的。 vectex2={id=2:1, label=enterprise, properties={id=1, label=[aaa, bbb]}} vectex3={id=2:1, label=enterprise, properties={id=1, label=[aaa, test2, bbb, test1]}} 但两段代码在两个进程中先后执行时结果就是覆盖的。 vectex2={id=2:1, label=enterprise, properties={id=1, label=[aaa, bbb]}} vectex3={id=2:1, label=enterprise, properties={id=1, label=[test2, test1]}}

这时什么原因呢?

代码段1: val v1 = new Vertex("enterprise") v1.property("id", "1") v1.property("label", "aaa") val v = client.graph.addVertex(v1) v.property("label", "bbb") log.error("vectex1=" + v)

代码段2: var cmd = s"g.V().hasLabel('enterprise').has('id', '1')" var resultset = client.gremlin().gremlin(cmd).execute() val i = resultset.get(0).getVertex() log.error("vectex2=" + i) i.property("label", "test1") i.property("label", "test2") log.error("vectex3=" + i)

shenxinyu avatar Aug 27 '19 14:08 shenxinyu

@shenxinyu 追加Set属性需要调用batch-update API(需要 v0.10 版本才支持)

javeme avatar Oct 15 '19 05:10 javeme

Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label

github-actions[bot] avatar Jan 01 '22 21:01 github-actions[bot]