Is there a Gremlin NULL keyword or something similar that isn't a traversal step?

杀马特。学长 韩版系。学妹 提交于 2020-01-06 04:52:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!