2

I am trying to retrieve the edge properties as values as well as the target and source node IDs.

My current database looks like that:

Edge:

_id _label _outV _inV name ID
0   edge   0     1    E    0

Nodes:

_id _label _name ID
0   node   A     0
1   node   B     1

I have tried this query:

>g.V().as('a').outE('edge').as('b').inV().values('ID').as('to').
 select('b').valueMap().as('edge').
 select('a').values('ID').as('from').
 select('to','edge','from')
==>[to:0,edge:[ID:0,name:E],from:1]

What I am trying to get is

[to:0,ID:0,name:E,from:1]

Also the Edge elements could contain an arbitrary number of properties.

Is there a way to achieve that?

Thanks!

EDIT: Final query:

gremlin> g.V().outE('edge').limit(1).
......1>   project('weight','id','from','to').
......2>     by(coalesce(values('weight'),constant(''))).
......3>     by(id).
......4>     by(outV().id()).
......5>     by(inV().id())
==>[weight:,id:0,from:0,to:1]
ThanosG
  • 119
  • 12

1 Answers1

1

Use project():

gremlin> g.V().has('name','marko').
......1>   outE().limit(1).
......2>   project('weight','id','from','to').
......3>     by('weight').
......4>     by(id).
......5>     by(outV().id()).
......6>     by(inV().id())
==>[weight:0.4,id:9,from:1,to:3]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • 1
    Thanks! This is what I was looking for. – ThanosG Sep 15 '18 at 17:19
  • There is a small problem with this query, I cant get results if the property 'weight' is null. Is there a solution to that. I was thinking of using choose() to project with and without. – ThanosG Sep 26 '18 at 07:12
  • Just use `coalesce()` in the `by()` for "weight" - instead of `by('weight')` do `by(coalesce(values('weight'),constant(0.0)))` – stephen mallette Sep 26 '18 at 10:18
  • 1
    Thanks Stephen! This is working flawlessly! I just changed the 0.0 value with '', since 0.0 is a valid value. I have updated my post with the final query. – ThanosG Sep 26 '18 at 15:55