简体   繁体   中英

Gremlin : Combine 2 or more vertices without an edge between them in Cosmos DB Gremlin API

Suppose I have a vertex Employee and a vertex Department. Employee has a property departmentId but there is no edge between these 2 vertices, can I project departmentName along with employeeName??

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

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

I still think this is a bad design, and the performance here will be bad.

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

example: https://gremlify.com/kudcz61i5j

Maybe this will have better performance:

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())

example: https://gremlify.com/nndmumlshmo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM