Gremlin,包括零边的顶点

Gremlin, including vertices with zero edges

假设您有以下关系:

Author-----wrote---->Article

并且你想准备一份关于每个作者的报告以及他写了多少篇文章和他最后一篇文章的日期,当有作者没有写文章时出现问题,当你通过时他们会被丢弃'wrote' 管道,我想在 'count' 列中包含“0”,在 'date' 列中包含 'N/A',所以我的问题是如何解决这个问题?

鉴于您对 OrientDB 的使用,我假设您仍在使用 TinkerPop 2.x,所以我将以这种方式回答。您需要执行以下操作:

gremlin> g = new TinkerGraph()                        
==>tinkergraph[vertices:0 edges:0]
gremlin> bill = g.addVertex([author:'bill',type:'author'])
==>v[0]
gremlin> amy = g.addVertex([author:'amy',type:'author'])  
==>v[1]
gremlin> book1 = g.addVertex([book:1,type:'book'])        
==>v[2]
gremlin> book2 = g.addVertex([book:2,type:'book'])        
==>v[3]
gremlin> bill.addEdge('wrote',book1)                      
==>e[4][0-wrote->2]
gremlin> bill.addEdge('wrote',book2)
==>e[5][0-wrote->3]
gremlin> g.V.has('type','author').transform{[it, it.outE('wrote').count()]}
==>[v[0], 2]
==>[v[1], 0]