public interface Scoping
Stepimplementations that access labeled path steps, side-effects or
Mapvalues by key, such as
select('a')step. Note that a step like
project()is non-scoping because while it creates a
Mapit does not introspect them. There are four types of scopes:
traverser.get()object. Another way to think about the current scope is to think in terms of the path of the traverser where the current scope is the head of the path. With the math()-step, the variable
_refers to the current scope.
The path scope refers to data previously seen by the traverser. That is, data in the traverser’s path history. Paths can be accessed by
gremlin> g.V().values("age").math("sin _") ==>-0.6636338842129675 ==>0.956375928404503 ==>0.5514266812416906 ==>-0.428182669496151
path(), however, individual parts of the path can be labeled using
as()and accessed later via the path label name. Thus, in the traversal below, “a” and “b” refer to objects previously traversed by the traverser.
The side-effect scope refers objects in the global side-effects of the traversal. Side-effects are not local to the traverser, but instead, global to the traversal. In the traversal below you can see how “x” is being referenced in the math()-step and thus, the side-effect data is being used.
gremlin> g.V().as("a").out("knows").as("b”). math("a / b").by("age") ==>1.0740740740740742 ==>0.90625
Map scope refers to objects within the current map object. Thus, its like current scope, but a bit “deeper.” In the traversal below the
gremlin> g.withSideEffect("x",100).V().values("age").math("_ / x") ==>0.29 ==>0.27 ==>0.32 ==>0.35
project()-step generates a map with keys “a” and “b”. The subsequent
math()-step is then able to access the “a” and “b” values in the respective map and use them for the division operation.
Scoping is all about variable data access and forms the fundamental interface for access to the memory structures of Gremlin.
gremlin> g.V().hasLabel("person”). project("a","b”). by("age”). by(bothE().count()). math("a / b") ==>9.666666666666666 ==>27.0 ==>10.666666666666666 ==>35.0
|Modifier and Type||Interface and Description|
|Modifier and Type||Method and Description|
Get the labels that this scoping step will access during the traversal
default <S> S getScopeValue(Pop pop, String key, Traverser.Admin<?> traverser) throws IllegalArgumentException
default <S> S getNullableScopeValue(Pop pop, String key, Traverser.Admin<?> traverser)
Copyright © 2013–2018 Apache Software Foundation. All rights reserved.