Skip to content

Split Merge Pattern

okram edited this page Feb 16, 2012 · 5 revisions

Most Gremlin pipelines are serial in that one step feeds to the next, so on and so forth. There are situations where it is desirable to split a pipeline and thus, have n-parallel steps that are later merged back into a serial flow. To support this type of traversal, there are split and merge steps.

  • Split
    • copySplit: copy the incoming object to each pipeline
  • Merge
    • fairMerge: merge the parallel traversals in a round-robin fashion
    • exhaustMerge: merge the parallel traversals by exhaustively getting the objects of the first, then the second, etc.
gremlin> g.v(1).out('knows').copySplit(_().out('created').name, _().age).fairMerge
==>ripple
==>27
==>lop
==>32
gremlin> g.v(1).out('knows').copySplit(_().out('created').name, _().age).exhaustMerge
==>ripple
==>lop
==>27
==>32

A useful representation of the the split/merge pattern is as follows.

g.v(1).out('knows').copySplit(
   _().out('created').name, 
   _().age
).fairMerge