[英]How to get the combined vertex and edge properties with gremlin and janusgraph
我在 Spring Boot 應用程序中使用 JanusGraph 作為圖形數據庫,並且我想形成一個 gremlin 查詢來檢索兩者的屬性 - 傳出 Edge 及其關聯的 Vertex。 我還希望將令牌(id、標簽等)包含在屬性中。
我想要這個 gremlin 查詢的 java 實現。
List<Map<String, Object>> propertyList = g.V("V_ID") // Get the vertex
.outE().hasLabel("OUT_EDGE").as("E") // Get the outgoing edge as E
.inV().as("V") // Get the vertex(pointed by E) as V
.select("E", "V") // Select Edge E and Vertex V
.by(__.valueMap().with(WithOptions.tokens).unfold() // Get value map including tokens
.group().by(Column.keys).by(__.select(Column.values).unfold())) // Form key value pairs
.toList(); // Return the list of properties
注意:根據您的實現替換示例字符串(“V_ID”、“OUT_EDGE”)標記
上面的查詢將返回 java map 中邊及其關聯頂點的所有屬性。 屬性映射還將包含標記(即 id、標簽)。
在這里,我不得不對valueMap()
進行分組和展開,因為valueMap()
默認情況下將 Value 字段包裝在一個數組中,我不希望這種行為,因為我擁有所有具有單個值的屬性,因此獲取列表毫無意義包含單個值。
您現在已合並所有邊和關聯的頂點屬性,並可通過propertyList
。
我認為你用project()
(如果可能的話elementMap()
)可以更好地編寫查詢:
g.V("V_ID").outE('OUT_EDGE').
project('eData','vData').
by(elementMap())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.