All Products
Search
Document Center

:Steps O-T

Last Updated:Feb 20, 2024

option

  • Description: An option() modulator step specifies an option for branching queries.

  • Note: This step must be used with a branch() step.

optional

  • Description: An optional() branch step returns the result of a child traversal if the child traversal has a result. Otherwise, this step returns the input object.

// Return the friends of each person and the person itself if the person does not have friends.
g("thinkerpop").V("1;2;4;6").hasLabel("person").optional(outE("knows"))
==> {"label":"knows","pk":"1","sk":"4","weight":1.0}
==> {"label":"knows","pk":"1","sk":"2","weight":0.5}
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}
==> {"label":"person","age":35,"name":"peter","pk":"6"}

or

  • Description: An or() filter step returns the input objects for which at least one child traversal has results.

// Return the persons whose ages are 27 or the person who has at least two friends.
g("thinkerpop").V("1;2;4;6").hasLabel("person").or(outE("knows").count().is(P.gte(2)),filter("age=27"))
==> {"label":"person","age":29,"name":"marko","pk":"1"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}

order

  • Description: An order() map step sorts input objects.

  • Note:

    • This step can be modulated by a by() step that specifies the sort rule. incr indicates ascending order, decr indicates descending order, and shuffle indicates random order.

      • By default, the input objects are sorted based on the primary key (pkey). You can also specify another field or a child traversal as the sort field.

      • By default, the input objects are sorted in ascending order.

      • You can specify multiple sort rules by using multiple by() steps.

    • An implicit barrier() step is automatically inserted.

// Sort the input objects in ascending order based on the pkey. If the pkey values are the same, sort the input objects in descending order based on the secondary key (skey).
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").order().by("pk").by("sk",Order.decr)
==> {"label":"created","pk":"1","sk":"3","weight":0.4}
==> {"label":"created","pk":"4","sk":"5","weight":1.0}
==> {"label":"created","pk":"4","sk":"3","weight":0.4}
==> {"label":"created","pk":"6","sk":"3","weight":0.2}

// Sort persons in descending order based on the number of friends.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").order().by(outE("knows").count(),Order.decr)
==> {"label":"person","age":29,"name":"marko","pk":"1"}
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}
==> {"label":"person","age":35,"name":"peter","pk":"6"}

// Sort ages in random order.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").values("age").order().by(Order.shuffle)
==> 32
==> 35
==> 29
==> 27

out

  • Description: An out() element step returns the vertices that are associated with a vertex.

  • Note:

    • This step can be used only in a graph traversal.

      • You can specify the label of the edges to which the associated vertices belong in the graph.

      • If you do not specify the label of the edges, all adjacent edges are traversed by default.

    • This step is implicitly transformed into outE().limit(50).inV(), which indicates that the number of edges to access cannot exceed 50. You can also use the mode in which this step is transformed into outE().limit(300).inV() based on your business requirements.

      To protect the system, make sure that the number of edges to access does not exceed 50,000.

    • The out().out() steps are optimized and transformed into outE().limit(50).outE().limit(50).inV().

      • This optimization saves an operation that traverses vertices.

      • The skey values of the edges found in the first outE step are the pkey values of the edges found in the second outE step.

      • If a path() step exists in subsequent traversals, this optimization does not take effect.

g("thinkerpop").V("1").hasLabel("person").out("knows")
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}

g("thinkerpop").V("1").hasLabel("person").out()
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}

outE

  • Description: An outE() element step returns the edges that are associated with a vertex.

  • Note:

    • You can specify the label of the edges to which the vertex belongs in the graph.

      • If you do not specify the label of the edges, all adjacent edges are traversed by default.

// By default, edges are queried based on the pkey field of the input vertex.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").outE("knows")
==> {"label":"knows","pk":"1","sk":"4","weight":1.0}
==> {"label":"knows","pk":"1","sk":"2","weight":0.5}

g("thinkerpop").V("1").hasLabel("person").outE("knows","created")
==> {"label":"created","pk":"1","sk":"3","weight":0.4}
==> {"label":"knows","pk":"1","sk":"4","weight":1.0}
==> {"label":"knows","pk":"1","sk":"2","weight":0.5}

P

  • Description: A P function compares the input object with the traversed object.

  • Syntax

Type

Syntax

Description

Example

Basic syntax

P.eq

Checks whether the input object is equal to the provided object.

P.eq(25)

P.neq

Checks whether the input object is not equal to the provided object.

P.neq(25)

P.gt

Checks whether the input object is greater than the provided object.

P.gt(25)

P.gte

Checks whether the input object is greater than or equal to the provided object.

P.gte(25)

P.lt

Checks whether the input object is less than the provided object.

P.lt(25)

P.lte

Checks whether the input object is less than or equal to the provided object.

P.lte(25)

P.inside

Checks whether the input object is greater than the first provided object and less than the second provided object.

P.inside(25, 32)

P.outside

Checks whether the input object is less than the first provided object or greater than the second provided object.

P.outside(25, 32)

P.between

Checks whether the input object is greater than or equal to the first provided object and less than the second provided object.

P.between(25, 32)

P.within

Checks whether the input object is in the collection of provided objects.

P.within(25, 32, 33, 35)

P.without

Checks whether the input object is not in the collection of provided objects.

P.without(25, 32, 33, 35)

Composite syntax

and

Combines two P functions in AND mode.

P.gt(25) and P.lt(30)

or

Combines two P functions in OR mode.

P.eq(25) or P.eq(30)

negate

Negates the logic of the origin P function.

P.eq(25).negate()

  • Note:

    • The input object must be a number or a string.

    • P functions can be used in filter steps such as is() and has().

    • Difference between P functions and Expressions:

      • A P function is suitable for scenarios in which the comparison is made based on only one parameter. The parameter can have no name.

      • An expression is suitable for scenarios in which the comparison is made based on multiple parameters. The parameters must have names.

      • Some logic can be described by using both a P function and an expression. You can use a P function or an expression based on your business requirements.

// Return the persons whose ages are 27 or the persons who have at least two friends.
g("thinkerpop").V("1;2;4;6").hasLabel("person").or(outE("knows").count().is(P.gte(2)),values("age").is(P.eq(27)))
==> {"label":"person","age":29,"name":"marko","pk":"1"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}
// The preceding statement is equivalent to the following statement.
// The first child traversal of the or() step does not provide a field with a name, and only a P function can be used. The field in the second child traversal is age, and you can use a filter() step.
g("thinkerpop").V("1;2;4;6").hasLabel("person").or(outE("knows").count().is(P.gte(2)),filter("age=27"))

path

  • Description: A path() map step returns the path of a traversal.

  • Note:

    • A path() step returns only the result of each single step. If you want to obtain the information about edges that are traversed in an out() step, you must explicitly use outE().inV() to traverse all edges.

    • This step can be modulated by a by() step that specifies the fields to be returned for a path.

    • You can use a PathRecordStrategy() step to customize the information to be returned for a path.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").out().out().values("name").path()
==> {"value":[{"label":"person","age":29,"name":"marko","pk":"1"},{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"software","lang":"java","name":"lop","pk":"3"},"lop"],"labels":[[],[],[],[]]}
==> {"value":[{"label":"person","age":29,"name":"marko","pk":"1"},{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"software","lang":"java","name":"ripple","pk":"5"},"ripple"],"labels":[[],[],[],[]]}

// Explicitly use outE().inV() to return information about edges.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").outE().inV().outE().inV().values("name").path()
==> {"value":[{"label":"person","age":29,"name":"marko","pk":"1"},{"label":"knows","pk":"1","sk":"4","weight":1.0},{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"created","pk":"4","sk":"3","weight":0.4},{"label":"software","lang":"java","name":"lop","pk":"3"},"lop"],"labels":[[],[],[],[],[],[]]}
==> {"value":[{"label":"person","age":29,"name":"marko","pk":"1"},{"label":"knows","pk":"1","sk":"4","weight":1.0},{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"created","pk":"4","sk":"5","weight":1.0},{"label":"software","lang":"java","name":"ripple","pk":"5"},"ripple"],"labels":[[],[],[],[],[],[]]}

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").out().out().path().by("name")
==> {"value":["marko","josh","lop"],"labels":[[],[],[]]}
==> {"value":["marko","josh","ripple"],"labels":[[],[],[]]}

PathRecordStrategy

  • Description: A PathRecordStrategy() policy step specifies the type of information to be returned by a path() step.

  • Syntax: The following types of information are supported.

  • This step is an extended step of iGraph.

    • PathRecord.vertex: the information about vertices.

    • PathRecord.edge: the information about edges.

    • PathRecord.map: the information about maps.

  • Note:

    • By default, all types of information are returned.

    • This step must be used with a withStrategies() step.

    • This step helps reduce the amount of data transferred.

// By default, all types of information are returned.
g("thinkerpop").V("4").hasLabel("person").outE().inV().path()
==> {"value":[{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"created","pk":"4","sk":"3","weight":0.4},{"label":"software","lang":"java","name":"lop","pk":"3"}],"labels":[[],[],[]]}
==> {"value":[{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"created","pk":"4","sk":"5","weight":1.0},{"label":"software","lang":"java","name":"ripple","pk":"5"}],"labels":[[],[],[]]}

// Return only information about vertices.
g("thinkerpop").V("4").withStrategies(PathRecordStrategy(PathRecord.vertex)).hasLabel("person").outE().inV().path()
==> {"value":[{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"software","lang":"java","name":"lop","pk":"3"}],"labels":[[],[]]},
==> {"value":[{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"software","lang":"java","name":"ripple","pk":"5"}],"labels":[[],[]]}

// Return only information about edges.
g("thinkerpop").V("4").withStrategies(PathRecordStrategy(PathRecord.edge)).hasLabel("person").outE().inV().path()
==> {"value":[{"label":"created","pk":"4","sk":"3","weight":0.4}],"labels":[[]]}
==> {"value":[{"label":"created","pk":"4","sk":"5","weight":1.0}],"labels":[[]]}

project

  • Description: A project() map step maps input objects to a map<string,object>.

  • Note: This step can be modulated by a by() step that specifies the values that are mapped.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").project("a","b").by(outE("knows").count()).by("age").order().by(select("b"))
==> {"\"a\"":0,"\"b\"":27}
==> {"\"a\"":2,"\"b\"":29}
==> {"\"a\"":0,"\"b\"":32}
==> {"\"a\"":0,"\"b\"":35}

// Map the number of items created by each person and the number of friends of each person.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").project("created","knows").by(outE("created").count()).by(outE("knows").count())
==> {"\"created\"":1,"\"knows\"":2}
==> {"\"created\"":2,"\"knows\"":0}
==> {"\"created\"":0,"\"knows\"":0}
==> {"\"created\"":1,"\"knows\"":0}

properties

  • Description: A properties() map step returns the properties of an element.

  • Note:

    • You can specify the properties to be returned. By default, all properties are returned.

    • You can use a values() step to obtain only the property values of an element.

g("thinkerpop").V("1;2").hasLabel("person").properties()
==> {"age":29}
==> {"name":"marko"}
==> {"pk":"1"}
==> {"age":27}
==> {"name":"vadas"}
==> {"pk":"2"}

g("thinkerpop").V("1;2").hasLabel("person").properties("name","age")
==> {"age":29}
==> {"name":"marko"}
==> {"age":27}
==> {"name":"vadas"}

propertyMap

  • Description: A propertyMap() map step returns a map of the properties of an element.

  • Note: You can specify the properties to be returned. By default, all properties are returned.

g("thinkerpop").V("1;2").hasLabel("person").propertyMap()
==> {"\"age\"":{"age":29},"\"name\"":{"name":"marko"},"\"pk\"":{"pk":"1"}}
==> {"\"age\"":{"age":27},"\"name\"":{"name":"vadas"},"\"pk\"":{"pk":"2"}}

g("thinkerpop").V("1;2").hasLabel("person").propertyMap("name","age")
==> {"\"age\"":{"age":29},"\"name\"":{"name":"marko"}}
==> {"\"age\"":{"age":27},"\"name\"":{"name":"vadas"}}

PushDownStrategy

  • Description: A PushDownStrategy() policy step pushes a sideEffect step to the storage layer for execution.

  • Note: In scenarios that require intensive computing, this step helps reduce the amount of data transferred.

  • This step is an extended step of iGraph.

// Return the maximum value of the product of the age of a person and the age of each other person.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").aggregate("x").by("age").V("1;2;3;4;5;6").hasLabel("person").values("age").as("y").local(select("x").unfold().math("_ * y").max())
==> 1015
==> 1120
==> 945
==> 1225

// Immediately calculate the maximum value after the y label is returned. This way, the storage duration of the y label is reduced.
g("thinkerpop").withStrategies(PushDownStrategy("x")).V("1;2;3;4;5;6").hasLabel("person").aggregate("x").by("age").V("1;2;3;4;5;6").hasLabel("person").values("age").as("y").local(select("x").unfold().math("_ * y").max())
==> 1015
==> 1120
==> 945
==> 1225

range

  • Description: A range() filter step returns the objects in a specific range.

  • Syntax: range(low,high). The low value is of the UINT32 type, and the high value is of the INT64 type. We recommend that you specify a high value that is less than 50,000.

  • Note: If the high value is set to -1, all objects that are greater than the low value are returned. Otherwise, the high value must be greater than the low value.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").order().by("pk").range(1,2)
==> {"label":"person","age":27,"name":"vadas","pk":"2"}

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").order().by("pk").range(1,-1)
==> {"label":"person","age":27,"name":"vadas","pk":"2"}
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":35,"name":"peter","pk":"6"}

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").order().by("pk").range(1,0)
==> {"ErrorCode":20040,"ErrorDescription":"gremlin 'range(global)' step invalid (low(1) > high(0) in 'range')"}

repeat

  • Description: A repeat() branch step loops over a traversal.

  • Note:

    • This step can be used with other steps such as times() and until(). This way, you can specify the conditions to exit the loop.

    • This step can also be used with an emit() step to return the intermediate results of a loop.

    • To protect the system, do not execute bad queries. For example, do not run an infinite repeat() step in a cyclic graph.

    • To protect the system, use a limit() step to truncate each traversal in the loop. The number of objects returned from each traversal cannot exceed 50,000.

# Repeat the out() step twice to obtain the traversed paths. 
g("thinkerpop").V("1").hasLabel("person").repeat(out()).times(2).path().by("name")
==> {"value":["marko","josh","lop"],"labels":[[],[],[]]}
==> {"value":["marko","josh","ripple"],"labels":[[],[],[]]}

# Do not use an until() step in a cyclic graph.
# Traverse from the specified vertex and perform a breadth-first search until a ripple vertex. 
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").until(has("name","ripple")).repeat(out()).path().by("name")
==> {"value":["marko","josh","ripple"],"labels":[[],[],[]]}
==> {"value":["josh","ripple"],"labels":[[],[]]}

# Repeat the out() step twice and return all the traversed paths. 
g("thinkerpop").V("1").hasLabel("person").repeat(out()).times(2).emit().path().by("name")
==> {"value":["marko","lop"],"labels":[[],[]]}
==> {"value":["marko","josh"],"labels":[[],[]]}
==> {"value":["marko","vadas"],"labels":[[],[]]}
==> {"value":["marko","josh","lop"],"labels":[[],[],[]]}
==> {"value":["marko","josh","ripple"],"labels":[[],[],[]]}

# Repeat the out() step twice and return all the traversed paths, including the path traversed before the repeat() step. 
g("thinkerpop").V("1").hasLabel("person").emit().repeat(out()).times(2).path().by("name")
==>[marko]
==> {"value":["marko"],"labels":[[]]}
==> {"value":["marko","lop"],"labels":[[],[]]}
==> {"value":["marko","josh"],"labels":[[],[]]}
==> {"value":["marko","josh","lop"],"labels":[[],[],[]]}
==> {"value":["marko","josh","ripple"],"labels":[[],[],[]]}
==> {"value":["marko","vadas"],"labels":[[],[]]}

sack

  • Description: A sack() map step returns the sack value of an element.

  • Note: For information about the initial value, split rules, and merge rules of the sack value, see the description of withSack().

sample

  • Description: A sample() filter step samples objects.

  • Syntax: sample([Sample.upsampling,][Sample.duplicatable,]NUM)[by(field)]. The NUM value is of the UINT32 type.

    • Sample.duplicatable indicates that the sampled objects can be duplicatable, and the bulk value of the output objects can be greater than the bulk value of the input objects. For example, the input objects are a, a, b, and c, and you want to sample three objects. If the sampled objects cannot be duplicatable, the sampling results contain two "a" objects at most. If the sampled objects can be duplicatable, the sampling results contain three "a" objects at most.

    • Sample.upsampling indicates upsampling. If the total bulk value of the input objects is less than the number of sampling results, upsampling ensures that the specified number of results is returned unless the number is set to 0. If upsampling takes effect, Sample.duplicatable does not work.

    • By default, the sampled objects cannot be duplicatable, and upsampling is not performed.

  • Note:

    • By default, this step samples objects at random.

    • This step can be modulated by a by() step that specifies a field as the sampling weight. A higher weight indicates a higher probability of being sampled.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").outE("created").sample(Sample.upsampling,Sample.duplicatable,5).by("weight")
==> {"label":"created","pk":"1","sk":"3","weight":0.4}
==> {"label":"created","pk":"4","sk":"5","weight":1.0}
==> {"label":"created","pk":"4","sk":"5","weight":1.0}
==> {"label":"created","pk":"4","sk":"5","weight":1.0}
==> {"label":"created","pk":"6","sk":"3","weight":0.2}

select

  • Description: A select() map step returns the objects with labels defined by an as() step.

  • Note:

    • If you use this step to read multiple labels, a map<label,objects> is returned.

    • This step can be modulated by a by() step that specifies the field to be obtained from the labeled objects.

    • This step can be used with Pop.first, Pop.last, or Pop.all to select the first labeled object, the last labeled object, or all labeled objects.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").as("x").select("x")
==> {"label":"person","age":29,"name":"marko","pk":"1"}
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}
==> {"label":"person","age":35,"name":"peter","pk":"6"}

// Use filtered objects as the input.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").as("x").filter("age>=32").select("x")
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":35,"name":"peter","pk":"6"}

// You can use a select() step to read multiple labels that are defined by an as() step.
// In this case, a map<label,objects> is returned.
// This step can be modulated by a by() step that specifies the field to be obtained from the labeled objects.
g("thinkerpop").V("1;2").hasLabel("person").as("x","y","z").select("x","y","z").by("pk").by("name").by("age")
==> {"\"x\"":"1","\"y\"":"marko","\"z\"":29}
==> {"\"x\"":"2","\"y\"":"vadas","\"z\"":27}

// Return the first object labeled as "a" in the traversal.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").as("a").repeat(out().as("a")).times(2).select(Pop.first,"a")
==> {"label":"person","age":29,"name":"marko","pk":"1"}
==> {"label":"person","age":29,"name":"marko","pk":"1"}

// Return the last object labeled as "a" in the traversal.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").as("a").repeat(out().as("a")).times(2).select(Pop.last,"a")
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"ripple","pk":"5"}

// Return all the objects labeled as "a" in the traversal. select(Pop.all,"a") is equivalent to select("a").
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").as("a").repeat(out().as("a")).times(2).select(Pop.all,"a")
==> [{"label":"person","age":29,"name":"marko","pk":"1"},{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"software","lang":"java","name":"lop","pk":"3"}]
==> [{"label":"person","age":29,"name":"marko","pk":"1"},{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"software","lang":"java","name":"ripple","pk":"5"}]

simplePath

  • Description: A simplePath() filter step returns a simple path.

  • Note:

    • This step can be modulated by a by() step that specifies the fields to be returned for a simple path.

    • A cyclicPath() step returns a cyclic path.

g("thinkerpop").V("1").hasLabel("person").out().out().simplePath().path()
==> {"value":[{"label":"person","age":29,"name":"marko","pk":"1"},{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"software","lang":"java","name":"lop","pk":"3"}],"labels":[[],[],[]]}
==> {"value":[{"label":"person","age":29,"name":"marko","pk":"1"},{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"software","lang":"java","name":"ripple","pk":"5"}

g("thinkerpop").V("1").hasLabel("person").out().out().simplePath().path().by("name")
==> {"value":["marko","josh","lop"],"labels":[[],[],[]]}
==>{"value":["marko","josh","ripple"],"labels":[[],[],[]]}

store

  • Description: A store() sideEffect step aggregates input objects into a list<object> during a traversal. The list<object> is stored to a sideEffect.

  • Note:

    • This step does not change the input objects. These objects are the input of the next step.

    • The list<object> is read-only. You can use a cap() step to extract the objects from the list<object> later at any point of the traversal.

      • We recommend that you do not use a select() step to extract the objects. This is because a select() step returns a list<object> for each element. Multiple identical lists are returned if multiple elements exist.

    • This step can be modulated by a by() step that specifies the field based on which objects are aggregated.

    • You can use an aggregate() step to aggregate objects with a barrier.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").store("x").by("name")
==> {"label":"person","age":29,"name":"marko","pk":"1"}
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}
==> {"label":"person","age":35,"name":"peter","pk":"6"}

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").store("x").by("name").cap("x")
==> ["josh","marko","peter","vadas"]

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").store("x").by("name").filter("age>=32").cap("x")
==> ["josh","marko","peter","vadas"]

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").store("x").by("name").outE("knows").store("y").cap("x","y").dedup()
==> {"\"x\"":["josh","marko","peter","vadas"],"\"y\"":[{"label":"knows","pk":"1","sk":"2","weight":0.5},{"label":"knows","pk":"1","sk":"4","weight":1.0}]}

sum

  • Description: A sum() map step sums input objects.

  • Note:

    • The input objects must be of a numeric type. The bool type is not supported.

    • The input of a sum(Scope.local) step can be an iterator. The objects in the scope must be of a numeric type. The bool type is not supported.

    • An implicit barrier() step is automatically inserted.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").values("age").sum()
==> 123

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").values("age").fold().sum(Scope.local)
==> 123

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").aggregate("x").by("age").cap("x").sum(Scope.local)
==> 123

T

  • Description: A T function returns the information about an element.

  • Syntax

    • T.id: returns the pkey value of an element.

    • T.label: returns the label of an element.

    • T.key: returns the field names of an element.

    • T.value: returns the field values of an element.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").has(T.id,P.eq("1"))
==> {"label":"person","age":29,"name":"marko","pk":"1"}

// After the system runs the out() step twice, no objects with the person label can be traversed. Only objects with the software label can be traversed.
g("thinkerpop").V("1").hasLabel("person").out().out().has(T.label,P.eq("person"))
==> No result is returned.

// Sort fields based on the field name.
g("thinkerpop").V("1").hasLabel("person").properties().order().by(T.key)
==> {"age":29}
==> {"name":"marko"}
==> {"pk":"1"}

// Sort fields based on the field value.
g("thinkerpop").V("1").hasLabel("person").properties().order().by(T.value)
==> {"age":29}
==> {"pk":"1"}
==> {"name":"marko"}

tail

  • Description: A tail() filter step returns a specific number of the last elements.

  • Syntax: tail(NUM). The NUM value is of the UINT32 type. We recommend that you specify a NUM value that is less than 50,000.

  • Note:

    • A limit() step returns a specific number of the first elements.

    • An implicit barrier() step is automatically inserted.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").tail(2)
==> {"label":"person","age":27,"name":"vadas","pk":"2"}
==> {"label":"person","age":35,"name":"peter","pk":"6"}

times

  • Description: A times() modulator step specifies the number of times that a loop is gone through.

  • Note: This step must be used with a repeat() step.