Date 1 - 3 of 3
gremlin.net: how can I connect an anonymous traveral to a regular traversal in gremlin.net?
Sorry if something like this has been answered elsewhere (hard to know what to search on).
I have a pretty simple traversal (albeit with a slightly messy projection step) that looks something like this:
g.V(root).out().order().by(id).range(1000,2000).project("v","e").....) // project step omitted for brevity
As you can see, it uses range for returning paged results. However, on the first results page only, I need to return the total vertex count of the graph too. I've got this working using something like:
This works fine for my needs. I've been able to translate this to c#/gremlin.net and successfully run and parsed the results.
The problem is there a chunk of duplicated code in doing so, namely the order and projection step that I need on both versions of the query but in different places.
Given that I have the 'core' part of the traversal, effectively:
I only know how to implement it somelthing like:
.Order().By(__.Id()).Range<GVertex>(Scope.Global, low, high).Project<object>("projectedV", "projectedE")
I know I can create the .Order()....Project()... part as an anonymous traversal:
__.Order().By(__.Id()).Range<GVertex>(Scope.Global, low, high)
Question is, can I append this to the existing 'core' traversal as if I had added it using fluent syntax? I want to be able able to reduce my code to something (VERY ROUGHLY!) like:
Is this even possible?
I appreciate that some people will try to suggest an alternative solution to my paging solution, and while help is always appreciated, I would like to improve my understanding of gremlin.net by finding out if appending/merginf traversals is possible.
Florian Hockmann <f...@...>
toggle quoted message Show quoted text
I would probably implement this as a Domain Specific Language (DSL) which is described in the TinkerPop docs for Gremlin.Net. Your combination of Order().By(), Range(), and Project() could then be a custom step of your DSL:
Since you also want to be able to use this as an anonymous traversal as an argument to the Union() step, you also need an anonymous version of this step (e.g., one that starts a traversal instead of being applied to an existing one):
Now you can use these two steps like this:
var t = Traversal().V();
var page = 1;
if (page == 1)
t.Union<Vertex>(__.Count(), OrderByWithProject(1, 1000));
Note that you need a static using of your __Custom class (or write it as __Custom.OrderByWithProject(1, 1000)).
Am Freitag, 5. Juni 2020 18:34:01 UTC+2 schrieb shapeshifter:
Thank you very much, Florian, this was pretty much what I needed.
|1 - 3 of 3|