From 9c5b629be891e7beb4ce216fd81f6fcc53f12fce Mon Sep 17 00:00:00 2001 From: Michael Pollmeier Date: Wed, 29 Mar 2017 10:39:41 +1300 Subject: [PATCH] provide examples where merge operator actually has an impact see https://groups.google.com/d/msgid/gremlin-users/CD3873E8-F202-4717-92E4-700D6CA80603%40gmail.com --- docs/src/reference/the-traversal.asciidoc | 33 +++++++++++++---------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc index f7aee7c44ec..b36fe7c9751 100644 --- a/docs/src/reference/the-traversal.asciidoc +++ b/docs/src/reference/the-traversal.asciidoc @@ -1876,20 +1876,25 @@ merge, their respective sacks are added together. [gremlin-groovy,modern] ---- -g.withSack(1.0f,sum).V(1).local(outE('knows').barrier(normSack).inV()) <1> -g.withSack(1.0f,sum).V(1).local(outE('knows').barrier(normSack).inV()).sack() <2> -g.withSack(1.0f,sum).V(1).local(outE('knows').barrier(normSack).inV()).in('knows') <3> -g.withSack(1.0f,sum).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').sack() <4> -g.withSack(1.0f,sum).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack() <5> -g.withBulk(false).withSack(1.0f,sum).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack() <6> ----- - -<1> The knows-adjacent vertices of vertex 1 are vertices 2 and 4. -<2> The `local(...barrier(normSack)...)` ensures that all traversers leaving vertex 1 have an evenly distributed amount of the initial 1.0 "energy" (50-50). -<3> Going from vertices 2 and 4 yield two traversers at vertex 1. -<4> Those two traversers each have a sack of 0.5. -<5> The `barrier()` merges the two traversers at vertex 1 into a single traverser whose sack is 1.0. -<6> There is now a single traverser with bulk of 2 and sack of 1.0 and thus, setting `withBulk(false)` yields the expected 1.0. +g.withSack(1.0d).V(1).out('knows').in('knows') <1> +g.withSack(1.0d).V(1).out('knows').in('knows').sack() <2> +g.withSack(1.0d, sum).V(1).out('knows').in('knows').sack() <3> +g.withSack(1.0d).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier() <4> +g.withSack(1.0d).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack() <5> +g.withSack(1.0d,sum).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack() <6> +g.withBulk(false).withSack(1.0f,sum).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack() <7> +g.withBulk(false).withSack(1.0f).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack()<8> + +---- + +<1> We find vertex 1 twice because he knows two other people +<2> Without a merge operation the sack values are 1.0. +<3> When specifying `sum` as the merge operation, the sack values are 2.0 because of bulking +<4> Like 1, but using barrier internally +<5> The `local(...barrier(normSack)...)` ensures that all traversers leaving vertex 1 have an evenly distributed amount of the initial 1.0 "energy" (50-50), i.e. the sack is 0.5 on each result +<6> Like 3, but using `sum` as merge operator leads to the expected 1.0 +<7> There is now a single traverser with bulk of 2 and sack of 1.0 and thus, setting withBulk(false) yields the expected 1.0 +<8> Like 7, but without the sum operator [[sample-step]]