0

The problem is described as following:

I want to find some interested paths and get corresponding properties of vertices or edges, the groovy I used is as following:

g.V().has("p_v_name", "d8e5d39d63c580acdb3eb188a1f4a942").
repeat(__.bothE().otherV().simplePath()).
times(3).emit().
has('p_v_tag').
path().
by(
    __.project("label", "id", "p_v_black_tag").
    by(__.label()).
    by(__.id()).
    by(__.choose(__.has('p_v_tag'),
                __.properties('p_v_tag').project('value').by(__.value()).fold(),
                __.constant([])
                )
    )
).unfold()

The above code gives me following result:

==>[label:v_user_key,id:749577404608,p_v_tag:[[value:PR016],[value:PR033],[value:PR068]]]
==>[label:e_application_id,id:4jjrk79js-9kcn170g-8ph-nvxhl4s0,p_v_tag:[]]
==>[label:v_application_id,id:1871880949872,p_v_tag:[]]

The result is unfolded for easing reading. It's just a path consisted of two nodes and one edge. The source node has a property p_v_tag, it's of multi-properties. The problem is the target node also has the property p_v_tag, but the code does not output the values.

I checked the target node has the property p_v_tag and it's not empty as following:


gremlin> g.V(1871880949872).properties('p_v_tag')
==>vp[p_v_tag->outdated]

I read the document(http://tinkerpop.apache.org/docs/current/reference) over and over but I can't figure out how to make it right, can any body help me or give me some advice?

dulq
  • 245
  • 3
  • 11

1 Answers1

1

I'm not sure why that wouldn't work. What happens if you try this workaround to replace:

by(__.choose(__.has('p_v_tag'),
            __.properties('p_v_tag').project('value').by(__.value()).fold(),
            __.constant([])
            )

with:

by(coalesce(properties('p_v_tag').
   project('value').
     by(__.value()).
   fold(), 
   constant([]))
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Thank you @stephen-mallette, your answer works. I'm working with janus-graph of version 0.2.0, recently I upgraded it to version 0.3.1, the method I used past works now. So this seems a problem related with version. With version 0.3.1, both `choose` and `coalesce` steps work. – dulq Jan 17 '19 at 10:17