Coalesce() step behaves differently than Or() step, with exception in sum() step

90 views
Skip to first unread message

cmilowka

unread,
Feb 9, 2021, 8:32:10 PM2/9/21
to Gremlin-users
I am trying to replace coalesce() by or() which is generally faster, but there is a problem with or() step failing in the following mum() step:

gremlin> graph3 = TinkerGraph.open()                                              ==>tinkergraph[vertices:0 edges:0]
gremlin> graph3.io(graphml()).readGraph('data/grateful-dead.xml')  ==>null
gremlin> g3 = graph3.traversal()                                                        ==>graphtraversalsource[tinkergraph[vertices:808 edges:8049], standard]
gremlin> g3.V('89').values("performances")                                       ==>219
gremlin> g3.V('89').values("performances").sum()                             ==>219
gremlin> g3.V('89').or(values("performances")).sum()                       ==> org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex cannot be cast to java.lang.Number
gremlin> g3.V('89').or(values("performances"),__.constant("10000")).sum()  ==> org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex cannot be cast to java.lang.Number
gremlin> g3.V('89').coalesce(values("performances"),__.constant("10000")).sum()  ==>219

Is an error, or wrong doing?
CM

Daniel C. Weber

unread,
Feb 11, 2021, 6:49:18 AM2/11/21
to Gremlin-users
It's proof that Coalesce cannot be replaced by Or because they do different things.

"or" is a filter. What goes into or only passes when one of the sub-traversals passed to or yields a value.  V('89').or(values("performances")) will yield the vertex '89' (a vertex!) when values("performances") yields a value. Now that we established that  V('89').or(values("performances")) will only ever yield vertices, you see that you can't sum over vertexes and the error makes sense.

If Coalesce gives the desired results for you, keep it. 

Reply all
Reply to author
Forward
0 new messages