【问题标题】:I am using JanusGraph 0.2 with Cassandra 3.9. How can I replace a vertex?我将 JanusGraph 0.2 与 Cassandra 3.9 一起使用。如何替换顶点?
【发布时间】:2018-01-15 10:00:50
【问题描述】:

我们可以更新一个顶点,例如: g.V(vertex_id).property("name","Marko")
有没有办法替换一个顶点?

【问题讨论】:

  • 替换顶点到底是什么意思?是否要更改所有属性?你想改变边缘吗?
  • @FlorianHockmann 我的意思是我想更改顶点的所有属性,但所有边都将保持不变

标签: cassandra gremlin janusgraph


【解决方案1】:

所以你想用另一个顶点的属性替换一个顶点的所有属性(至少我是这样理解你的问题和你的评论的)。

要删除所有属性,您只需删除它们:

g.V(vertex_id).properties().drop().iterate()

我们可以看到如何将所有属性从一个顶点复制到另一个顶点in this response by Daniel Kuppitz to a question on how to merge two vertices:

g.V(vertex_with_new_properties).
    sideEffect(properties().group("p").by(key).by(value())).
    cap("p").unfold().as("kv").
  V(vertex_id).
    property(select("kv").select(keys), select("kv").select(values)).
    iterate()

当我们结合这两个遍历时,我们会得到一个遍历,它会丢弃旧属性并从另一个顶点复制新属性:

g.V(vertex_id).
    sideEffect(properties().drop()).
  V(vertex_with_new_properties).
    sideEffect(properties().group("p").by(key).by(value())).
    cap("p").unfold().as("kv").
  V(vertex_id).
    property(select("kv").select(keys), select("kv").select(values)).
    iterate()

现代图表的实际应用:

// properties before for both vertices:
gremlin> g.V(1).valueMap(true)
==>{id=1, label=person, name=[marko], age=[29]}
gremlin> g.V(2).valueMap(true)
==>{id=2, label=person, name=[vadas], age=[27]}

// Replace all properties of v[1]:
gremlin> g.V(1).
            sideEffect(properties().drop()).
           V(2).
            sideEffect(properties().group("p").by(key).by(value())).
            cap("p").unfold().as("kv").
           V(1).
            property(select("kv").select(keys), select("kv").select(values)).
            iterate()

// v[1] properties after:
gremlin> g.V(1).valueMap(true)
==>{id=1, label=person, name=[vadas], age=[27]}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-18
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    相关资源
    最近更新 更多