【问题标题】:Adding Multiple Unique Vertices添加多个唯一顶点
【发布时间】:2019-01-11 12:15:58
【问题描述】:

我想编写一个 gremlin 查询来创建多个顶点,但只有在它们都是唯一的情况下才会这样做。我知道我可以通过使用 cmets 中提到的合并步骤来使用 get 或 addV 方法。

g.V().has('com.demo.test', '__type', 'Namespace').fold().coalesce(unfold(), addV('com.demo.test').property('__type', 'Namespace'))

只有当它不存在时才会有一个顶点。如果我想在单个查询中对多个边和顶点执行相同的过程怎么办?我的目标是,如果其中一个顶点/边不是唯一的,则它们都不会被创建。但是我知道这可能是不可能的,所以欢迎所有答案。

谢谢

【问题讨论】:

  • @jason neptune 不允许使用 lambda 函数
  • 查看答案中的最后一个代码块,在单次遍历中处理“获取或创建”的一般方法是执行以下操作: g.V().has('person','name','bill').fold().coalesce(unfold(), addV('person').property('name','bill'))
  • 使用你的参数,g.V().has('com.demo.test', '__type', 'Namespace').fold().coalesce(unfold(), addV('com.demo.test').property('__type', 'Namespace'))
  • 无论如何我可以用这个逻辑进行多顶点/边创建单查询吗?

标签: gremlin tinkerpop3 amazon-neptune


【解决方案1】:

我找到了一个可能的解决方案。这可行,但可能有更好的方法。

g.V().coalesce(
  V().has(label,'Namespace61'),
  addV('Namespace61')).
coalesce(
  V().has(label,'Namespace76'),
  addV('Namespace76')).
coalesce(
  V().has(label,'Namespace74'),
  addV('Namespace74')
).dedup()

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-23
  • 2019-01-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多