Gremling Java API, sticking together GremlinPipelines

95 views
Skip to first unread message

Gerd

unread,
Feb 3, 2012, 9:19:20 AM2/3/12
to Gremlin-users
hi there,

by doing some tutorials and simple examples I´m getting more cofident
with gremlin.

But i still have problems in sticking pipes together.

For examlpe I have three Java-GremlinPipes, they all have stored some
vertices, and the vertices themselves have outgoing relations.

GremlinPipline pipeA;
GremlinPipline pipeB;
GremlinPipline pipeC;

So what I want to do, is getting some kind of an intersect result from
all pipes together, like all outgoing vertices that are in A and also
in B and in C.

I´ve tried to get it running with the "and" operator, but maybe this
is a totally wrong way to do it ....

GremlinPipeline intersectResultOutVerticesfromA_B_C =
pipeA.and(pipeB,pipeC).out();

regards,

Gerd

Marko Rodriguez

unread,
Feb 3, 2012, 11:03:58 AM2/3/12
to gremli...@googlegroups.com
Hi,

> I´ve tried to get it running with the "and" operator, but maybe this
> is a totally wrong way to do it ....
>
> GremlinPipeline intersectResultOutVerticesfromA_B_C =
> pipeA.and(pipeB,pipeC).out();

Yea, AND is not the way to do it. AND is for saying, "let the next result of pipeA flow if that result returns objects out of both pipeB AND pipeC." To your particular problem, there are limited instances in which you can do stream-based intersection without creating an intermediate set. One example of stream-based intersection is back() filtering. To do what you want, you probably want to do this:

Set x = new HashSet();
pipeB.fill(x).iterate()
pipeC.except(x)

x is your intermediate results that you will then intersect with what comes out of pipeC using except().

I hope that helps,
Marko.

http://markorodriguez.com

Gerd

unread,
Feb 4, 2012, 7:27:09 AM2/4/12
to Gremlin-users
Thanks for your reply,
I figured out, I have to solve it using a differnent way, so I changed
my design a little bit and startet to create a gremlin query.
I uploaded some parts of my model to tinypic: http://i39.tinypic.com/hui1e0.gif
What i want to do is to identity one single kpi-Node (here it is
Activepower) by its incoming edges like year, month and day, to get
the value for one specific date. Sure, I can check the timeStamp -
property in the nodes, but this would be boring ;-)...In my model I
had to start from the mashine, so I did something like:
GremlinPipeline result = new
GremlinPipeline(mashine).out("PRODUCED").in("y:2012", "m:2", "d:
3")).back(1);
That delivers me both nodes from the 2012-02-04 and 2012-02-03, so it
seems that the .in(A B C) is chained with an "OR"?! But what i need
some kind of an "AND". I also tried it to solve with some
filterfunctions and sets but I wasn´t successful...
Can you help me out, again?
Greetings,
Gerd

Pierre De Wilde

unread,
Feb 4, 2012, 10:07:10 AM2/4/12
to gremli...@googlegroups.com
Hey,

Split into in(...).back(1) to simulate an AND:

GremlinPipeline result = new GremlinPipeline(mashine).out("PRODUCED").in("y:2012").back(1).in("m:2").back(1).in("d:3").back(1);

HTH,
Pierre

Gerd

unread,
Feb 4, 2012, 10:49:41 AM2/4/12
to Gremlin-users
Hey Pierre,

thanks a lot, I already tried this before, but I must had made some
stupid mistake.

So, this code is just working fine!

Regrads,

Gerd

On 4 Feb., 16:07, Pierre De Wilde <pierredewi...@gmail.com> wrote:
> Hey,
>
> Split into in(...).back(1) to simulate an AND:
>
> GremlinPipeline result = new
> GremlinPipeline(mashine).out("PRODUCED").in("y:2012").back(1).in("m:2").bac k(1).in("d:3").back(1);
>
> HTH,
> Pierre
Reply all
Reply to author
Forward
0 new messages