问题
Problem
I've been optimizing the performance of our app that's built on graph (Gremlin API on Cosmos DB) and I've been generally having a bad time of it. After quite a lot of digging, I realize that a bunch of the pain is being caused by unneeded traversal processing. If I want to get all foo vertices along with any bar edges that those edges may have (think left join from SQL), I would write the following in Gremlin:
g.V().hasLabel("foo").as("foos").
coalesce(out("bar"),constant()).as("bars").
select("foos","bars")
The results would comprise a set of tuples with item 1 named foos and item 2 named bars. Foos would always have a vertex and bars would have either an edge or a [].
Instead of processing a new anonymous traversal with one constant()
step for each vertex, a null would make the whole thing a lot more efficient.
I've looked everywhere but I can't find null in Gremlin. Anyone have any ideas?
回答1:
There isn't the concept of returning null
in Gremlin for a value. It is one of the more annoying parts but you have to return a value.
Additionally, I think you can simplify your traversal down by using a project() statement instead of traversing the graph and then selecting the values. It would be something like this:
g.V().hasLabel("foo").
project('foo', 'bars').
by(__.id()).
by(__.outE('bars').fold().coalesce(unfold(), constant('')))
来源:https://stackoverflow.com/questions/58564443/is-there-a-gremlin-null-keyword-or-something-similar-that-isnt-a-traversal-step