All Products
Search
Document Center

:Steps A-G

Last Updated:Feb 21, 2024

aggregate

agg

  • Description: An aggregate() 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.

    • An implicit barrier() step is automatically inserted. You can use a store() step to aggregate objects in lazy mode without a barrier.

    • Differences among aggregate(), as(), and fold():

      • An aggregate() step aggregates input objects into a list and copies the list to a sideEffect. These objects are the input of the next step. The list is read-only in subsequent steps.

      • An as() step adds labels to input objects. These labeled objects are the input of the next step. You can modify the labeled objects in subsequent steps.

      • A fold() step aggregates input objects into a list. The list is the input of the next step.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").aggregate("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").aggregate("x").by("name").cap("x")
==> ["josh","marko","peter","vadas"]

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

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").aggregate("x").by("name").outE("knows").aggregate("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}]}

alias

  • Description: An alias() sideEffect step defines virtual fields for input elements, including vertices and edges.

  • Syntax: alias("expr1:new1;expr2;new2;field1:new3")

  • Note:

    • You can define an expression as a virtual field.

    • You can define a virtual field for an original field. This way, you define an alias for the original field.

      • After an alias is defined for a field, you must use the alias to access the field in subsequent steps.

    • Field names must be unique.

    • This step is an extended step of iGraph.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").alias("name:nick;age*2:double_age")
==> {"label":"person","age":29,"double_age":58,"nick":"marko","pk":"1"}
==> {"label":"person","age":32,"double_age":64,"nick":"josh","pk":"4"}
==> {"label":"person","age":27,"double_age":54,"nick":"vadas","pk":"2"}
==> {"label":"person","age":35,"double_age":70,"nick":"peter","pk":"6"}

// No result is returned if you use the original name to access a field.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").alias("name:nick").values("name")
==> []
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").alias("name:nick").values("nick")
==> ["marko","josh","vadas","peter"]

and

  • Description: An and() filter step returns the input objects for which all child traversals have results.

  • Note: This step can take an arbitrary number of traversals as the input.

// Find people whose age is equal to or greater than 32 but less than 35.
g("thinkerpop").V("1;2;4;6").hasLabel("person").and(has("age",P.lt(35)),has("age",P.gte(32)))
==> {"label":"person","age":32,"name":"josh","pk":"4"}

// Find people who are older than 28 and have at least two friends.
g("thinkerpop").V("1;2;4;6").hasLabel("person").and(has("age",P.gt(28)),outE("knows")).count().is(P.gte(2)))
==> {"label":"person","age":29,"name":"marko","pk":"1"}

as

  • Description: An as() modulator step adds labels to input objects. These objects can be accessed by subsequent steps and data structures that make use of such labels.

  • Note:

    • An as() step can add multiple labels to objects at a time.

    • The labeled objects are the input of the next step. You can use a select() step to extract the labels later at any point of the traversal.

      • If you use a select() step to extract multiple labels, a map<label,objects> is returned.

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

    • Differences among aggregate(), as(), and fold():

      • An aggregate() step aggregates input objects into a list and copies the list to a sideEffect. These objects are the input of the next step. The list is read-only in subsequent steps.

      • An as() step adds labels to input objects. These labeled objects are the input of the next step. You can modify the labeled objects in subsequent steps.

      • A fold() step aggregates input objects into a list. The list is the input of the next step.

    • The "label":"person" field in the following result set indicates the label of an element in the graph.

      This label is different from the label added by the as() step.

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"}

// A filter() step takes the labeled objects as the input and filters out some objects.
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"}

// An as() step can add multiple labels to objects.
// A map<label,objects> is returned if you use a select() step to select multiple objects with the same label.
// A select() 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}

barrier

  • Description: A barrier() map step serves as a barrier. This means that every step prior to the barrier() step needs to be complete before the system moves to the steps after the barrier() step.

  • Note:

    • By default, a barrier() step merges repeated objects.

      • Method: The bulk values of the objects are added together. The sack values of the objects are merged based on the specific merge operator.

      • Purpose: For example, the input objects contain ten Vertices A with a bulk value of 1.

        • If you run the barrier().outE() steps, the barrier() step returns a single Vertex A with a bulk value of 10, and the outE() step returns a result with a bulk value of 10 by performing one computation.

        • If you directly run an outE() step, the step returns ten results with a bulk value of 1 by performing ten computations.

      • Generally, the merge operation is imperceptible to users. This is because an object whose bulk value is greater than 1 is unfolded by multiple times based on the bulk value when the object is returned in the final result. This process does not change the bulk value.

      • You can use a bulk() step to obtain the bulk value of an element.

      • You can use a local(count()) step to count the number of each unique object.

    • A barrier(Barrier.nodedup) step serves as a barrier but does not merge repeated objects.

    • An implicit barrier() step is automatically inserted for steps such as aggregate(), cap(), count(), dedup(), distinct(), fold(), group(), groupCount(), limit(), max(), mean(), min(), order(), range(), sample(), sum(), and tail().

// A barrier() step merges repeated objects into one object. The bulk value of the result object is the number of objects that are merged.
// Generally, the merge operation is imperceptible to users. This is because an object whose bulk value is greater than 1 is unfolded by multiple times based on the bulk value when the object is returned in the final result.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().barrier()
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"ripple","pk":"5"}

// You can use a bulk() step to obtain the bulk value of an element.
// The objects are returned and unfolded. An object with a bulk value of 3 is returned as three objects, each of which has a bulk value of 3.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().barrier().bulk()

// You can use a local(count()) step to count the number of each unique object.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().barrier().local(count())
==> [3,1]

// A barrier(Barrier.nodedup) step serves as a barrier but does not merge repeated objects. 
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().barrier(Barrier.nodedup)
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"ripple","pk":"5"}

// If repeated objects are not merged, the bulk value of each object is 1.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().barrier(Barrier.nodedup).bulk()
==> [1,1,1,1]

branch

  • Description: A branch() branch step performs branching queries.

  • Note:

    • This step must be used with option() steps.

    • If the condition of the first option is met, the process goes to the first branch. Otherwise, the second option is checked.

    • This step can take an arbitrary number of traversals as the input.

    • The use of this step is similar to that of a choose() step.

// if (name=marko) {return age}
// else {return name}
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").branch(values("name")).option("marko",values("age")).option(none,values("name"))
==> [29,"josh","vadas","peter"]

bulk

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

  • Note:

    • The initial bulk value of an element is 1. The bulk values of objects are added when the objects are merged by a barrier() step.

    • Generally, the merge operation is imperceptible to users. This is because an object whose bulk value is greater than 1 is unfolded by multiple times based on the bulk value when the object is returned in the final result. This process does not change the bulk value.

    • A dedup() step resets the bulk value of an element to 1.

g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV()
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"ripple","pk":"5"}

// A barrier () step merges the three objects of software 3 with a bulk value of 1 into one object with a bulk value of 3.
// The objects are returned and unfolded. An object with a bulk value of 3 is returned as three objects, each of which has a bulk value of 3.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().barrier().bulk()
==> 3
==> 3
==> 3
==> 1

// A barrier () step merges the three objects of software 3 with a bulk value of 1 into one object with a bulk value of 3.
// A dedup() step resets the bulk value of the object of software 3 from 3 to 1.
// The objects are returned and unfolded. After the dedup() step is run, only two objects are returned.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().barrier().dedup().bulk()
==> 1
==> 1

by

  • Description: A by() modulator step provides parameters such as traversals, functions, and comparators for other steps. The general pattern is step().by()…​by().

  • Note: A by() step can modulate the following steps. For more information, see the description of each step.

    • aggregate(): You can use a by() step to specify the field based on which objects are aggregated.

    • cyclicPath(): You can use a by() step to specify the fields to be returned for a cyclic path.

    • dedup(): You can use a by() step to specify the field based on which repeated objects are deduplicated.

    • distinct(): You can use a by() step to specify the distinction rule.

    • group(): You can use two by() steps to specify the grouping rule and the fields to be stored in each group.

    • groupCount(): You can use a by() step to specify the grouping rule.

    • order(): You can use a by() step to specify the sort rule, such as the ascending order, descending order, or random order.

    • path(): You can use a by() step to specify the fields to be returned for a path.

    • project(): You can use a by() step to specify the values that are mapped.

    • sample(): You can use a by() step to specify the weight field for sampling. A larger weight indicates a higher probability that an object is sampled.

    • select(): You can use a by() step to specify the field to be obtained from the labeled objects.

    • simplePath(): You can use a by() step to specify the fields to be returned for a simple path. A path that is not cyclic is considered a simple path.

cap

  • Description: A cap() map step returns the value of a sideEffect.

  • Note:

    • This step can read multiple sideEffects and return a map<key,sideEffect>.

    • An implicit barrier() step is automatically inserted.

g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().groupCount("x").by("name").cap("x")
==> {"lop":3,"ripple":1}

// This step can read multiple sideEffects and return a map<key,sideEffect>.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").groupCount("x").by("pk").groupCount("y").by("weight").cap("x","y")
==> {"\"x\"":{"\"1\"":1,"\"4\"":2,"\"6\"":1},"\"y\"":{"0.2":1,"0.4":2,"1.0":1}}

choose

  • Description: A choose() branch step performs branching queries.

  • Note:

    • If the condition of the first option is met, the process goes to the first branch. Otherwise, the second option is checked.

    • This step can take an arbitrary number of traversals as the input.

    • The use of this step is similar to that of a branch() step.

// if (name=marko) {return age}
// else {return name}
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").choose(has("name","marko"),values("age"), values("name"))
==> 29
==> "josh"
==> "vadas"
==> "peter"

// if (age<=30) {return knows edges}
// else {return created edges)
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").choose(values("age").is(P.lte(30)),__.outE("knows"),__.outE("created"))
==> {"label":"knows","pk":"1","sk":"4","weight":1.0}
==> {"label":"knows","pk":"1","sk":"2","weight":0.5}
==> {"label":"created","pk":"4","sk":"3","weight":0.4}
==> {"label":"created","pk":"4","sk":"5","weight":1.0}
==> {"label":"created","pk":"6","sk":"3","weight":0.2}

// if (age=29) {return knows edges}
// else if (age=27) {return created edges}
// else {return input}
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").choose(values("age")).option(29,__.outE("knows")).option(32,__.outE("created")).option(none,identity())
==> {"label":"knows","pk":"1","sk":"4","weight":1.0}
==> {"label":"knows","pk":"1","sk":"2","weight":0.5}
==> {"label":"created","pk":"4","sk":"3","weight":0.4}
==> {"label":"created","pk":"4","sk":"5","weight":1.0}
==> {"label":"person","age":35,"nick":"peter","pk":"6"}

coalesce

  • Description: A coalesce() branch step evaluates the input traversals in sequence and returns the first traversal that finds at least one element.

  • Note: This step can take an arbitrary number of traversals as the input.

// The knows edges are found before the created edges. Therefore, the knows edges are returned.
g("thinkerpop").V("1").hasLabel("person").coalesce(outE("knows")outE("created"))
==> {"label":"knows","pk":"1","sk":"4","weight":1.0}
==> {"label":"knows","pk":"1","sk":"2","weight":0.5}

// The created edges are found before the knows edges. Therefore, the created edges are returned.
g("thinkerpop").V("1").hasLabel("person").coalesce(outE("created"),outE("knows"))
==> {"label":"created","pk":"1","sk":"3","weight":0.4}

constant

  • Description: A constant() map step returns a custom constant value.

  • Note:

    • The constant value must be a number or a string.

    • This step is often used in branching queries.

// if (age<=30) {return "young man"}
// else {return age)
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").choose(filter("age<30"),constant("young man"),values("age"))
==> "young man"
==> "32"
==> "young man"
==> "35"

// if (has age) {return age}
// else {return 5}
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").union(outE("knows").inV(),outE("created").inV()).coalesce(properties("age"), constant(5))
==> {"age":32}
==> {"age":27}
==> 5
==> 5
==> 5
==> 5

count

  • Description: A count() map step counts the number of input objects.

  • Note:

    • A count(Scope.local) step can count the number of objects in a iterator-based data collection such as a list or a set.

    • An implicit barrier() step is automatically inserted.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").count()
==> 4

// Count the number of objects in the list<object> generated by a fold() step.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").fold().count(Scope.local)
==> 4

cyclicPath

  • Description: A cyclicPath() filter step returns a cyclic path.

  • Note:

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

    • A simplePath() step returns a simple path.

g("thinkerpop").V("1").hasLabel("person").out().out().cyclicPath().path()
==> No result is returned if the thinkerpop graph does not contain a cyclic path.

dedup

  • Description: A dedup() filter step deduplicates input objects.

  • Note:

    • If the bulk value of an object is greater than 1, this step resets the bulk value to 1.

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

      • A random object is retained for objects with the same field value.

    • This step can deduplicate objects based on labels added by as() steps.

    • An implicit barrier() step is automatically inserted.

g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV()
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"ripple","pk":"5"}

g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().dedup()
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"ripple","pk":"5"}

// A random object of the objects with the same lang value is retained.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").inV().dedup().by("lang")
==> {"label":"software","lang":"java","name":"lop","pk":"3"}

// Deduplicate objects based on the values of the x and y labels. 
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").as("x").inV().as("y").dedup("x","y")
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"lop","pk":"3"}
==> {"label":"software","lang":"java","name":"ripple","pk":"5"}

distinct

  • Description: A distinct() filter step hashes input objects based on a specific method and extracts a specific number of objects from each hash bucket.

  • Note:

    • You can use the

      Distinct.round parameter to specify the number of extraction rounds. Default value: 1.

    • You can use the

      Distinct.amount parameter to specify the number of objects to be extracted from each bucket each round.

      Default value: 1.

    • You can use the

      Distinct.isReserved parameter to specify whether to append unextracted objects to the end of the result set. By default, unextracted objects are discarded.

    • This step can be modulated by a by() step that specifies the distinction rule.

    • An implicit barrier() step is automatically inserted.

    • This step is an extended step of iGraph.

// Distribute objects into hash buckets based on the primary key (pkey). Extract one object from each hash bucket in one round, and discard unextracted objects.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").distinct().by("pk")
==> {"label":"created","pk":"6","sk":"3","weight":0.2}
==> {"label":"created","pk":"1","sk":"3","weight":0.4}
==> {"label":"created","pk":"4","sk":"3","weight":0.4}

// Distribute objects into hash buckets based on the pkey. Extract one object from each hash bucket in two rounds, and discards unextracted objects.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").distinct(Distinct.round,2,Distinct.amount,1).by("pk")
==> {"label":"created","pk":"6","sk":"3","weight":0.2}
==> {"label":"created","pk":"1","sk":"3","weight":0.4}
==> {"label":"created","pk":"4","sk":"3","weight":0.4}
==> {"label":"created","pk":"4","sk":"5","weight":1.0}

// Distribute objects into hash buckets based on the number of the number of friends. Extract one object from each hash bucket in one round, and append unextracted objects to the end of the result set.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").distinct(Distinct.isReserved).by(__.outE("created").count())
==> {"label":"person","age":27,"name":"vadas","pk":"2"}
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":29,"name":"marko","pk":"1"}
==> {"label":"person","age":35,"name":"peter","pk":"6"}

E

  • Description: An E() element step reads edges from a graph.

  • Syntax: Separate multiple pkey strings with semicolons (;). Specify multiple secondary keys (skeys) for a pkey in the pk:sk1|sk2|... format.

  • Note:

    • You can use a hasLabel() step to specify the label of the graph from which you want to read edges.

g("thinkerpop").E("1:3;4:3|5;6").hasLabel("created")
==> {"label":"created","pk":"1","sk":"3","weight":0.4}
==> {"label":"created","pk":"4","sk":"3","weight":0.4}
==> {"label":"created","pk":"4","sk":"5","weight":1.0}
==> {"label":"created","pk":"6","sk":"3","weight":0.2}

emit

  • Description: An emit() modulator step returns the intermediate results of a loop.

  • Note: This step must be used with other steps such as loop() and repeat().

fields

  • Description: A field() sideEffect step retains the specified fields and removes other fields from elements, including vertices and edges.

  • Syntax: Separate multiple fields with semicolons (;).

  • Note:

    • You cannot remove a pkey field or an skey field.

    • This step helps reduce the data volume.

    • This step is an extended step of iGraph.

g("thinkerpop").E("1:3;4:3|5;6").hasLabel("created").fields("pk;sk")
==> {"label":"created","pk":"1","sk":"3"}
==> {"label":"created","pk":"4","sk":"3"}
==> {"label":"created","pk":"4","sk":"5"}
==> {"label":"created","pk":"6","sk":"3"}

filter

  • Description: A filter() filter step filters elements. Elements that meet the filter condition are retained, whereas other elements are discarded.

  • Note: You can specify an expression or a child traversal as the filter condition.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").filter("age<30")
==> {"label":"person","age":29,"name":"marko","pk":"1"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").filter(__.outE("knows"))
==> {"label":"person","age":29,"name":"marko","pk":"1"}

fold

  • Description: A fold() map step aggregates input objects into a list<object>.

  • Note:

    • Differences among aggregate(), as(), and fold():

      • An aggregate() step aggregates input objects into a list and copies the list to a sideEffect. These objects are the input of the next step. The list is read-only in subsequent steps.

      • An as() step adds labels to input objects. These labeled objects are the input of the next step. You can modify the labeled objects in subsequent steps.

      • A fold() step aggregates input objects into a list. The list is the input of the next step.

    • An unfold() step has the inverse functionality to unfold a list into objects.

    • An implicit barrier() step is automatically inserted.

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

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").values("name").fold().unfold()
==> "marko"
==> "josh"
==> "vadas"
==> "peter"

group

  • Description: A group() map step groups input objects based on a specific rule.

  • Note:

    • This step can be modulated by two by() steps.

      • You can use the first by() step to specify the grouping rule and the second by() step to specify the fields to be stored in each group.

      • You must specify the grouping rule. You can specify an expression or a child traversal as the grouping rule.

      • The fields to be stored in each group are optional. You can use an expression or a child traversal to specify the fields. By default, all fields of an object are stored.

    • An implicit barrier() step is automatically inserted.

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").group().by(outE("knows".count())
==> {"0":[{"label":"person","age":32,"name":"josh","pk":"4"},{"label":"person","age":27,"name":"vadas","pk":"2"},{"label":"person","age":35,"name":"peter","pk":"6"}],"2":[{"label":"person","age":29,"name":"marko","pk":"1"}]}

// Group objects by the specified label and store the name values of the objects in each group.
g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").union(outE("knows").inV(),outE("created").inV()).group().by(T.label).by("name")
==> {"\"person\"":["josh","vadas"],"\"software\"":["lop","lop","ripple","lop"]}
  • Common usage

// Group objects by f1. Sort the objects in each group in descending order based on the weights. Retain the first two objects in each group.
......group().by("f1").select(Column.values).unfold().flatMap(__.unfold().order().by("weight", decr).limit(2))

groupCount

  • Description: A groupCount() sideEffect step groups input objects based on a specific rule and returns the number of objects in each group.

  • Note:

    • This step can be modulated by a by() step that specifies the grouping rule.

      • The grouping rule is optional. You can specify an expression or a child traversal as the grouping rule.

    • This step stores the grouping result to a sideEffect. Then, you can extract the objects by using a cap() step.

    • An implicit barrier() step is automatically inserted.

g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").groupCount().by("pk")
==> {"\"1\"":1,"\"4\"":2,"\"6\"":1}

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").union(outE("knows").inV().outE("created").inV()).groupCount().by(T.label)
==> {"\"person\"":2,"\"software\"":4}

// Extract the grouping result by using a cap() step.
g("thinkerpop").E("1;2;3;4;5;6").hasLabel("created").groupCount("x").by("pk").groupCount("y").by("weight").cap("x","y")
==> {"\"x\"":{"\"1\"":1,"\"4\"":2,"\"6\"":1},"\"y\"":{"0.2":1,"0.4":2,"1.0":1}}