【问题标题】:Gremlin : Combine 2 or more vertices without an edge between them in Cosmos DB Gremlin APIGremlin :在 Cosmos DB Gremlin API 中组合 2 个或更多顶点,它们之间没有边
【发布时间】:2023-03-26 05:45:01
【问题描述】:

假设我有一个顶点 Employee 和一个顶点 Department。 Employee有一个属性departmentId,但是这两个顶点之间没有边,我可以将departmentName与employeeName一起投影吗??

g.addV('employee').
  property('id', 1).
  property('name', 'A').
  property('departmentId', 1)

g.addV('department').
  property('id', 1).
  property('name', 'HR')

【问题讨论】:

  • 您可以通过每次搜索所有顶点或提前将它们组合在一起来做到这一点.. 但是为什么呢?图中的所有要点都是为了避免这种情况。如果您有一个需要“加入”它们两者的数据的查询,那么不将它们与边缘连接似乎是一个糟糕的设计
  • @noam621 我理解您对设计的担忧,但这只是创建场景的示例。

标签: azure-cosmosdb gremlin gremlin-server azure-cosmosdb-gremlinapi


【解决方案1】:

我还是觉得这是个糟糕的设计,这里的性能会很差。

g.V().hasLabel('employee').as('e').
  project('name', 'department name').
    by('name').
    by(V().hasLabel('department').
      has('_id', select('e').
        values('departmentId')).values('name'))

示例:https://gremlify.com/kudcz61i5j

也许这样会有更好的表现:

g.V().hasLabel('department', 'employee').
  group().by(coalesce(
      hasLabel('department').values('_id'),
      hasLabel('employee').values('departmentId')
    )).
    by(fold().as('group').unfold().
      hasLabel('employee').
      project('name', 'department name').
        by('name').
        by(select('group').unfold().
          hasLabel('department').values('name')).
      fold())

示例:https://gremlify.com/nndmumlshmo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 2021-11-07
    • 2020-12-13
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多