【问题标题】:how can i write the query on gremlin console to return the pair vertices these have the parallel edge?如何在 gremlin 控制台上编写查询以返回具有平行边的对顶点?
【发布时间】:2021-08-03 16:06:28
【问题描述】:

我喜欢将此密码查询转换为 gremlin。

(n:Person)-[:friend]->(t:Person)-[:friend]->(n:Person)

谢谢

【问题讨论】:

    标签: console gremlin tinkerpop


    【解决方案1】:

    使用航线数据集,一种方法是使用cyclicPath 步骤,如下所示。

    gremlin> g.V('44').outE().inV().outE().inV().cyclicPath().path()
    ==>[v[44],e[5019][44-route->8],v[8],e[3975][8-route->44],v[44]]
    ==>[v[44],e[5020][44-route->13],v[13],e[4158][13-route->44],v[44]]
    ==>[v[44],e[5021][44-route->20],v[20],e[4387][20-route->44],v[44]]
    
    
    gremlin> g.V('44').outE().inV().outE().inV().cyclicPath().path().by('code').by()
    ==>[SAF,e[5019][44-route->8],DFW,e[3975][8-route->44],SAF]
    ==>[SAF,e[5020][44-route->13],LAX,e[4158][13-route->44],SAF]
    ==>[SAF,e[5021][44-route->20],PHX,e[4387][20-route->44],SAF]
    ==>[SAF,e[5022][44-route->31],DEN,e[4736][31-route->44],SAF]
    ==>[v[44],e[5022][44-route->31],v[31],e[4736][31-route->44],v[44]]
       
    

    或者,如果您只想要边缘 ID

    gremlin> g.V('44').outE().inV().outE().inV().cyclicPath().path().by('code').by(id)
    ==>[SAF,5019,DFW,3975,SAF]
    ==>[SAF,5020,LAX,4158,SAF]
    ==>[SAF,5021,PHX,4387,SAF]
    ==>[SAF,5022,DEN,4736,SAF]  
    

    编写此查询的另一种方法涉及where 步骤

    gremlin> g.V('44').as('a').outE().inV().outE().inV().where(eq('a')).path().by('code').by()
    ==>[SAF,e[5019][44-route->8],DFW,e[3975][8-route->44],SAF]
    ==>[SAF,e[5020][44-route->13],LAX,e[4158][13-route->44],SAF]
    ==>[SAF,e[5021][44-route->20],PHX,e[4387][20-route->44],SAF]
    ==>[SAF,e[5022][44-route->31],DEN,e[4736][31-route->44],SAF]  
    
      
    

    【讨论】:

    • 谢谢开尔文。
    • 所有互相成为朋友的人 g.V().out("FRIEND").in("FRIEND").cyclicPath().path()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 2021-12-27
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多