Path Windows: from() and to() on path(), simplePath() and cyclicPath()
path(), simplePath() and cyclicPath() take from(label), to(label) and by(...), as the
Apache TinkerPop steps do. from() and to() cut the path of each traverser down to a window
between two labelled positions; by() projects the objects of that window before the step uses
them.
g.V().as("a").out().as("b").out().as("c").path().from("b").to("c").by("name")
// ["josh", "ripple"], ["josh", "lop"]
g.V().as("a").out().as("b").out().as("c").simplePath().by(T.label).from("b").to("c").path().by("name")
// ["marko", "josh", "ripple"], ["marko", "josh", "lop"]
Rules
- Window. The window starts at the position labelled by
from()(position 0 withoutfrom()) and ends at the position labelled byto()(the last position withoutto()), both included. The two bounds are found independently of each other.from("a").to("a")is the one object labelleda; two labels on the same position (as("a", "b")) work the same way. path()returns the windowed objects. The traverser's own path is unchanged, so a laterpath()is the whole path again.simplePath()/cyclicPath()test only the window (afterby()). The traverser continues with its whole path; only the test sees the window.by()is a ring over the window: the firstby()applies to the first object of the window, the next one to the second object, and so on, cycling. Aby()that yields no value for an object (a missing property) drops the traverser, forpath(),simplePath()andcyclicPath()alike.simplePath().by(...)compares the projected values, so two different vertices with the same age are a repeat.- Order of the modulators does not matter:
path().by("age").from("a").to("b")andpath().from("a").to("b").by("age")are the same. - Cost. The plain forms (no modulator) test the path in place without copying it. The modulated
forms materialize the path once per traverser.
.profile()shows the modulators, for examplesimple_path().from("b").to("c").by(T.label) [path: full].
Deviations
These are choices where the engine had to decide; none is a difference from TinkerPop's behaviour on a feature scenario.
- Repeated labels. If several positions carry the same label (the same
as("a")inside arepeat(), oras("a")twice), bothfrom()andto()use the last position carrying the label. This is TinkerPop'sPath.subPath(checked against the 3.7.2 byte code, since no Java sources are available offline), so a window may start at the lastaeven when an earlieraexists. Ato()position before thefrom()position is an error. - Unknown label. A
from()orto()label that no position carries is an error (Property '<label>' not found on element type 'path'). TinkerPop raises anIllegalArgumentExceptiontoo; only the text differs. - Repeated
from()/to(). A secondfrom()replaces the first (TinkerPop'saddFromsetter does the same). - Exactly one label.
from(["a", "b"])(a list) is anInvalidModulatorerror, detected before the traversal runs. TinkerPop'sfrom()takes one label (or a traversal, which Graphersal does not support forpath()). - No value from
by(). Aby()that produces nothing drops the traverser (aspath().by()already did); TinkerPop does the same withoutProductiveByStrategy. - Empty argument list.
from([])/to([])in a script is the no-argument form and is ignored, as it is foraddE().