@@ -1418,8 +1418,8 @@ g.V().elementMap('name')
14181418g.V().dedup().by(label).values('name')
14191419----
14201420
1421- Finally, if `dedup()` is provided an array of strings, then it will ensure that the de-duplication is not with respect
1422- to the current traverser object, but to the path history of the traverser.
1421+ If `dedup()` is provided an array of strings, then it will ensure that the de-duplication is not with respect to the
1422+ current traverser object, but to the path history of the traverser.
14231423
14241424[gremlin-groovy,modern]
14251425----
@@ -1433,6 +1433,37 @@ g.V().as('a').both().as('b').both().as('c').
14331433<1> If the current `a` and `b` combination has been seen previously, then filter the traverser.
14341434<2> The "age" property is not <<by-step,productive>> for all vertices and therefore those values are filtered.
14351435
1436+ The `dedup()` step can work on many different types of objects. One object in particular can need a bit of explanation.
1437+ If you use `dedup()` on a `Path` object there is a chance that you may get some unexpected results. Consider the
1438+ following example which forcibly generates duplicate path results in the first traversal and in the second applies
1439+ `dedup()` to remove them:
1440+
1441+ [gremlin-groovy,modern]
1442+ ----
1443+ g.V().union(out().path(), out().path())
1444+ g.V().union(out().path(), out().path()).dedup()
1445+ ----
1446+
1447+ The `dedup()` step checks the equality of the paths by examining the equality of the objects on the `Path` (in this case
1448+ vertices), but also on any path labels. In the prior example, there weren't any path labels so `dedup()` behaved as
1449+ expected. In the next example, note the difference in the results if a label is added for one `Path` but not the other:
1450+
1451+ [gremlin-groovy,modern]
1452+ ----
1453+ g.V().union(out().as('x').path(), out().path())
1454+ g.V().union(out().as('x').path(), out().path()).dedup()
1455+ ----
1456+
1457+ The prior example shows how `dedup()` does not have the same effect when a path label is in place. In this contrived
1458+ example the answer is simple: remove the `as('x')`. If in the real world, it is not possible to remove the label, the
1459+ workaround is to deconstruct the `Path` into a `List` to drop the label. In this way, `dedup()` is just comparing `List`
1460+ objects and the objects in the `Path`.
1461+
1462+ [gremlin-groovy,modern]
1463+ ----
1464+ g.V().union(out().as('x').path(), out().path()).map(unfold().fold()).dedup()
1465+ ----
1466+
14361467*Additional References*
14371468
14381469link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#dedup(org.apache.tinkerpop.gremlin.process.traversal.Scope,java.lang.String...)++[`dedup(Scope,String...)`],
@@ -5325,7 +5356,7 @@ First, it is important to recognize that there is a bit of a difference in behav
53255356becomes its composite `Map.Entry` objects as is typical in Java. The following example demonstrates the basic name/value
53265357pairs that returned:
53275358
5328- [groovy,modern]
5359+ [gremlin- groovy,modern]
53295360----
53305361g.V().valueMap('name','age').unfold()
53315362----
@@ -5380,7 +5411,7 @@ Display stack trace? [yN]
53805411While this problem might be solved in future versions, the workaround for both cases is to use
53815412<<constant-step,constant()>> as shown in the following example:
53825413
5383- [groovy,modern]
5414+ [gremlin- groovy,modern]
53845415----
53855416g.V().hasLabel('person').both().group().by(constant(id))
53865417g.V().hasLabel('person').both().group().by('age').select(constant(32))
0 commit comments