0
votes

I'm using JanusGraph as a graph database in my spring boot application, and I want to form a gremlin query to retrieve the properties of both - outgoing Edge and its associated Vertex. I also want the tokens(id, label etc) to be included in the properties.

I want the java implementation of this gremlin query.

2

2 Answers

0
votes
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

NOTE: Replace the sample strings ("V_ID", "OUT_EDGE") tokens as per your implementation

The above query will return all the properties of edges and its associated vertex in java map. The property map will also contain the tokens (i.e. id, label).

Here I had to group and unfold the valueMap() since the valueMap() by default wraps the Value field inside an array and I do not want this behavior since I have all the properties with single value so there is no point in getting a list that contains a single value.

You now have all the edge and associated vertex properties merged and available with the propertyList.

0
votes

I think you write your query better with project() (and if possible elementMap()):

g.V("V_ID").outE('OUT_EDGE').
  project('eData','vData').
    by(elementMap())