简体   繁体   English

如何从顶点 scala gremlin 获取所有传出边的所有顶点

[英]How to get all vertices of all outgoing edges from a vertex scala gremlin

I need to get all list of vertices label of all outgoing egdes from a vertex using scala gremlin.我需要使用 scala gremlin 从一个顶点获取所有传出 egdes 的所有顶点标签列表。

My code looks like below,我的代码如下所示,

val names :ListBuffer[String] = ListBuffer()
val toList: List[Vertex] = graph.V().hasLabel(100).outE().outV().toList()
for(vertex <- toList){
      names  += vertex.label()
    }

Its returning the same label name for all vertex Eg : Vertex A is having outE to B,C,D .它为所有顶点返回相同的标签名称,例如:顶点 A 有 outE 到 B,C,D 。 It returns the label of A. Output:它返回 A 的标签。输出:

ListBuffer(100, 100, 100)

Anything am i missing?我错过了什么吗?

I believe you asking for the wrong vertex in the end.我相信你最终会要求错误的顶点。 Honestly, I often make the same mistake.老实说,我经常犯同样的错误。 Maybe this is the traversal you looking for:也许这就是你要找的遍历:

graph.V().hasLabel(100).outE().inV().label().toList()

If you like me and often get confused by inV() and outV() you can use otherV which gets the opposite vertex.如果你喜欢我并且经常被inV()outV()弄糊涂,你可以使用获得相反顶点的otherV Like so:像这样:

graph.V().hasLabel(100).outE().otherV().label().toList()

Finally you can even shorten your traversal by not explicitly stating the edge part:最后,您甚至可以通过不明确说明边缘部分来缩短遍历:

graph.V().hasLabel(100).out().label().toList()

By using out() instead of outE() you don't need to specify you want the vertex, out() gets you the vertex directly.通过使用out()而不是outE()你不需要指定你想要的顶点, out()直接让你得到顶点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GREMLIN for Scala:如何在单个查询中放置两个顶点之间的边并连接两个顶点之间的边 - GREMLIN for Scala : How to drop edge between two vertex and connect edges between two vertex in single query 获取Scala gremlin中两个顶点之间的传出边缘属性值 - Fetch outgoing edge property value between two vertices in scala gremlin 在GraphX中删除没有出线边缘的顶点 - Remove Vertices with no outgoing edges in GraphX Gremlin:选择具有共享属性的边的顶点 - Gremlin: Select Vertices that have edges that share a property GraphX-如何从vertexId获取所有连接的顶点(而不仅是第一个相邻的顶点)? - GraphX - How to get all connected vertices from vertexId (not just the firsts adjacents)? 在 Scala gremlin 泰坦图数据库中创建顶点 - Vertex creation in Scala gremlin titan graph DB Scala - 如何从 Avro 模式中获取所有字段名称? - Scala - How to get all the fields name from an Avro schema? 如何从Scala中的Map List获取所有值? - How to get all values from List of Map in Scala? 如何从.scala文件中获取所有配置参数? - How to get all config parameters from a .scala file ? Scala:如何从 Option[Map[String, Int]] 中获取所有键? - Scala: How to get all keys from Option[Map[String, Int]]?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM