You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by gi...@gmail.com, gi...@gmail.com on 2018/06/21 10:26:56 UTC

How to create Query to find Vertex and its outs

Hi,
I'm new about Java gremlin. I need an help on gremlin over OrientDB.

This is my scenario:
On my graph I have 2 Vertex classes, type A and type B.

Let A is a Vertex of type A and it is linked to 0 or more Vertices of type B.

So now I need to find both any A (filtering by a field of A) and the list of all B vertices B linked to A.

Is possible, using GremlinPipeline to have this response?

Currently I execute the query in 2 steps:
1- Find the list of A (filtering by a field)
2- For each A I search the list (if any) of B linked to A

In this case the query needs 9 seconds if I have a lot of B linked to some A.
Can somebody help me?

Gianluca

Re: How to create Query to find Vertex and its outs

Posted by Stephen Mallette <sp...@gmail.com>.
You might get some trouble with answers to this as it looks like you're
using the long long forgotten TinkerPop 2.x (with an older version of
OrientDB). As far as Gremlin goes in any version you can use it to answer:

>  find both any A (filtering by a field of A) and the list of all B
vertices B linked to A.

which in TinkerPop 3.x is basically:

g.V().hasLabel('A').
  group().
    by()
    by(out().hasLabel('B').fold())

in TinkerPop 2.x I think the syntax would be

g.V().has('label', "A").   //// don't remember how you access vertex labels
in 2.x as they weren't first class citizens
  groupBy{it}{out().has("label","B")}

Will that be faster than 9 seconds? not sure....judging from that type of
traversal, you are doing a full scan of all vertices (i.e. hasLabel('A')
isn't optimized by index for orientdb that i know of) to find all the "A"
vertices and then you have to traversal all their edges to find "B"
vertices. you don't say how big your graph is, but that could be a lot of
data to process.



On Thu, Jun 21, 2018 at 7:31 AM gianluca.val@gmail.com <
gianluca.val@gmail.com> wrote:

> Hi,
> I'm new about Java gremlin. I need an help on gremlin over OrientDB.
>
> This is my scenario:
> On my graph I have 2 Vertex classes, type A and type B.
>
> Let A is a Vertex of type A and it is linked to 0 or more Vertices of type
> B.
>
> So now I need to find both any A (filtering by a field of A) and the list
> of all B vertices B linked to A.
>
> Is possible, using GremlinPipeline to have this response?
>
> Currently I execute the query in 2 steps:
> 1- Find the list of A (filtering by a field)
> 2- For each A I search the list (if any) of B linked to A
>
> In this case the query needs 9 seconds if I have a lot of B linked to some
> A.
> Can somebody help me?
>
> Gianluca
>