Can not run shortest-path sample provided in Recipes

72 views
Skip to first unread message

吳崧銘

unread,
Jan 17, 2017, 5:52:43 AM1/17/17
to Gremlin-users
Hi!

Follow recipes http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/recipes/#shortest-path I try to play shortest path to be familiar with how thinkerpop work.
I try to extract the weight information from path then sum to get the total weight but got object type cast error.
Experiment environment: graph db titan-1.0.0 + single node cassandra, and also post question in titan user group.

Below is my steps:

gremlin> v1 = graph.addVertex(T.label, 'v1')
gremlin> v2 = graph.addVertex(T.label, 'v2')
gremlin> v1.addEdge("foo", v2, "weight", 0.25f)

gremlin> g.V().hasLabel('v1').repeat(outE().inV().simplePath()).times(1).path().as('p').map(unfold().coalesce(values('weight'), constant(0.0)).sum()).as('w').select('p', 'w')
org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath cannot be cast to org.apache.tinkerpop.gremlin.structure.Element 
Display stack trace? [yN]

The above step show object type is ImmutablePath which can not be cast to Element.

By adding By step, then type change from ImmutablePath to MutablePath,
gremlin> g.V().hasLabel('v1').repeat(outE().inV().simplePath()).times(1).path().as('p').by(constant(0.0)).by('weight').map(unfold().coalesce(values('weight'),constant(0.0)).sum()).as('w').select('p', 'w')
org.apache.tinkerpop.gremlin.process.traversal.step.util.MutablePath cannot be cast to org.apache.tinkerpop.gremlin.structure.Element
Display stack trace? [yN]

I think the problem might be caused by unfold step didn't decompose path object into list for Sum step.
Do I miss anything mentioned in the document or is it a bug? plz kindly help, thanks!


Daniel Kuppitz

unread,
Jan 17, 2017, 6:08:43 AM1/17/17
to gremli...@googlegroups.com
This has been discussed recently, but I can't find the discussion thread. The problem is indeed that older TP versions were not able to unfold paths. As a workaround you can use a lambda to get the path as a list of objects:

g.V().hasLabel('v1').repeat(outE().inV().simplePath()).times(1).path().as('p').
  map(map {it.get().objects()}.unfold().coalesce(values('weight'), constant(0.0)).sum()).as('w').select('p', 'w')

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/b91887bd-a105-4ccb-af9d-869110bc1f40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

吳崧銘

unread,
Jan 19, 2017, 12:33:42 AM1/19/17
to Gremlin-users
The workaround work like a charm! 
Thanks you Daniel :)

Jonas

Daniel Kuppitz於 2017年1月17日星期二 UTC+8下午7時08分43秒寫道:
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages