Using coalesce to select vertex that may or may not be connected via an edge. #828
musicalmathmind
started this conversation in
General
Replies: 1 comment 1 reply
-
I think you're looking for something like
Syntax might be a bit off but you get the idea. The null-handling story is a bit tricky and inconsistent in Tinkerpop, so I suggest making the "b"-part of the tuple a (possibly empty) array. If it has to be a single, possibly null, element, there is something called "empty projection protection" in later versions of Gremlinq, shown here. You can omit the limit and fold then. Also, I am offering workshops on Gremlin/Gremlinq. Let me know if that's something for your team. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I have the following situation.
Vertex
a
and Vertexb
could be related via an edge calledRelated
. I'm trying to build a traversal to return (a
,b
) if it is connected byRelated
, otherwise just return (a
, null). We can assumea
always exists, but it may not have a connection tob
. My strategy was to use acoalesce
to try and traverse froma
tob
. If that doesn't succeed in finding vertexb
, I'd like to just returnTuple<A,B>(a, null)
.Here is what I have so far, but it has a few problems.
Our team is fairly new to using Gremlin and graph databases in general, but this seems like it would work for what we're trying to accomplish. The problems we're encountering are as follows.
In the happy case (a
Related
edge exists betweena
andb
), I do get a tuple back, however the only property that is filled out on theB
object is it's Id. There are other properties that should be on there too, but they aren't filled out (even though they do exist as properties on the vertex). What's interesting though is if I remove the 2nd traversal in the Coalesce (the one creating thenull
constant, everything works properly for the happy case, but then the unhappy case fails by returning(null, null)
instead of returning(a, null)
Any help would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions