【问题标题】:group child vertices by property按属性分组子顶点
【发布时间】:2020-05-17 15:11:04
【问题描述】:

我正在使用带有以下简单图形架构的 Amazon Neptune:

root --has--> child

根顶点可以有许多不同的属性。

我想要一个查询来创建一个字典,其中包含所有作为键的根顶点属性和一个包含所有具有相同值的子顶点的数组。

例如以下数据:

{
  root: {
   a: 1
   b: 2
   c: 3
  },
  child1: {
   a: 4
   b: 2
   c: 3
  },
  child2: {
   a: 1
   b: 4
   c: 3
  }
}

我会得到以下结果:

{
  a: [child2],
  b: [child1],
  c: [child1, child2]
}

当我知道属性时,我可以这样做:

g.V().hasLabel('Root').as('root')
  .project('a', 'b', 'c')
  .by(out('has').where(eq('root')).by('a').fold())
  .by(out('has').where(eq('root')).by('b').fold())
  .by(out('has').where(eq('root')).by('c').fold())

有没有办法在不知道根属性的情况下创建它?

【问题讨论】:

    标签: gremlin amazon-neptune


    【解决方案1】:

    也许有比这更优雅的解决方案,但无论如何这是我的尝试:

    g.V().hasLabel('Root').as('root').
      properties().as('prop').
      group().by(label).
        by(select('root').
          out('has').where(properties().and(
              where(eq('prop')).by(key),
              where(eq('prop')).by(value)
            )).
          fold())
    

    示例:https://gremlify.com/9y

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 2019-12-11
      相关资源
      最近更新 更多