【问题标题】:How to drop a subgraph in Tinkerpop (OrientDB) gremlin query?如何在 Tinkerpop (OrientDB) gremlin 查询中删除子图?
【发布时间】:2020-07-31 09:25:22
【问题描述】:

如果我有runId 和appId,则要求删除此子图。应用程序可以有多个这样的 appId,因此只有在没有 appId 附加到它时才应该删除它。

我已尝试使用以下查询删除子图,但只有 IO 和 appRun 被删除。 iRecord & oRecord 不要被丢弃。这是因为我失去了 gremlin 指针吗?所以问题是如何删除iRecord 和oRecord。

我打算在第二次遍历调用中删除appId。那么我可以检查appId 是否不再连接runId 并在同一遍历中删除appId。

db.getTraversal()
                .V().has("aRun", "runId", runId).as("aRun")
                .outE("hasIO")
                .inV().hasLabel("io").as("io")
                .sideEffect(outE("output").inV().has("oRecord").drop())
                .sideEffect(inE("input").outV().has("iRecord").drop())
                .sideEffect(select("aRun").drop())
                .sideEffect(select("io").drop())
                .iterate();

我还尝试了此处提供的答案版本:Link

db.getTraversal().
  V().has("aRun", "runId", runId)
  emit().
  repeat(out()).
  fold().
  unfold().
  drop()

但这将删除oRecord、aRun 和io,但不会删除iRecord。以及如何删除appId 的问题仍然存在。

谢谢

pom.xml:

<dependency>
 <groupId>com.orientechnologies</groupId>
 <artifactId>orientdb-gremlin</artifactId>
 <version>3.0.25</version>
</dependency>

【问题讨论】:

  • “oRecord”和“iRecord”是标签还是属性?如果标签我认为您的第一个查询不会删除它们,因为您使用的是has 而不是hasLabel
  • 非常感谢!是的!就这么简单。

标签: java graph orientdb gremlin tinkerpop


【解决方案1】:

我使用了这个查询:

db.getTraversal()
 .V().has("app", "appId", appId).as("app")
 .outE("hasRun")
 .inV().has("aRun", "runId", runId).as("aRun")
 .outE("hasIO")
 .inV().hasLabel("io").as("io")
 .sideEffect(outE("output").inV().hasLabel("oRecord").drop())
 .sideEffect(inE("input").outV().hasLabel("iRecord").drop())
 .sideEffect(select("app").filter(outE("hasRun").count().is(1)).drop())
 .sideEffect(select("aRun").drop())
 .sideEffect(select("io").drop())
 .iterate();

谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 2015-12-30
    相关资源
    最近更新 更多