UNION of results from different paths

490 views
Skip to first unread message

blueprints-learner

unread,
Dec 26, 2012, 9:58:41 AM12/26/12
to gremli...@googlegroups.com
Hi,

Suppose, g = TinkerGraphFactory.createTinkerGraph();

gremlin> g.V.outE('knows').inV.path
==>[v[1], e[7][1-knows->2], v[2]]
==>[v[1], e[8][1-knows->4], v[4]]

gremlin> g.V.inE('knows').outV.path
==>[v[2], e[7][1-knows->2], v[1]]
==>[v[4], e[8][1-knows->4], v[1]]

I'm wondering if it is possible to return a UNION of both the above pipelines in a single sequence of steps?

Thanks in advance.

Marko A. Rodriguez

unread,
Dec 26, 2012, 10:27:17 AM12/26/12
to gremli...@googlegroups.com
Hello,

You can do your query as such:

g.V.copySplit(_().outE('knows').inV, _().inE('knows').outV).fairMerge.path

via the terminal:

gremlin> g.V.copySplit(_().outE('knows').inV, _().inE('knows').outV).fairMerge.path
==>[v[1], e[7][1-knows->2], v[2]]
==>[v[2], e[7][1-knows->2], v[1]]
==>[v[1], e[8][1-knows->4], v[4]]
==>[v[4], e[8][1-knows->4], v[1]]
--
 
 

Stephen Mallette

unread,
Dec 26, 2012, 10:29:38 AM12/26/12
to gremli...@googlegroups.com
You could use copySplit to accomplish something like this:

gremlin> g.V.copySplit(_().outE("knows").inV,_().inE("knows").outV).fairMerge.path
==>[v[1], e[7][1-knows->2], v[2]]
==>[v[2], e[7][1-knows->2], v[1]]
==>[v[1], e[8][1-knows->4], v[4]]
==>[v[4], e[8][1-knows->4], v[1]]

http://gremlindocs.com/#branch/copysplit

Stephen
> --
>
>

blueprints-learner

unread,
Dec 29, 2012, 11:04:23 AM12/29/12
to gremli...@googlegroups.com
Thanks, Marko. That works in gremlin. However, I'm trying to accomplish the same in Java using Pipes API. I'm doing somthing like the code below to create a valid sequence of pipes. The results are incorrect and I'm not sure if this is even close to the right approach to doing this :/ In particular, how can CopySplitPipe() and FairMergePipe() be used in this (or other) example?

public void printPaths() {
    Graph g = TinkerGraphFactory.createTinkerGraph();

    Pipe p1 = new Pipeline(new IdentityPipe(), new OutEdgesPipe("knows"), new InVertexPipe());
    Pipe p2 = new Pipeline(new IdentityPipe(), new InEdgesPipe("knows"), new OutVertexPipe());    
    Pipe p3 = new CopySplitPipe(p1, p2);

    List<Pipe> tmp = new ArrayList();
    tmp.add(p3);

    Pipe pipeline = new Pipeline(new FairMergePipe(), new PathPipe());
    pipeline.enablePath(true);
    pipeline.setStarts(g.getVertices());

    for (Objec o : pipeline) {
        System.out.println(o);
    }
}


Thanks in advance.

blueprints-learner

unread,
Dec 29, 2012, 11:10:29 AM12/29/12
to gremli...@googlegroups.com
Thanks, Stephen. It works in gremlin. I'm trying to do the same in Java using Pipes API. Can't figure out how CopySplitPipe() and FairMergePipe() can be used in this context. I've given the bit of relevant code in reply to Marko's answer above.

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages