You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by an...@relatech.com, an...@relatech.com on 2018/07/11 10:36:56 UTC

Question for Detached Vertex in Tinkerpop

Hi guys,


my name is Antonio and i'm java developer. First of all i want to congratulate with you for the great work you have done with Tinkerpop framework.

I' m working with Dse Graph using Tinkerpop for developing a feature of my app and i'm facing a problem that i want to share with you.

I've got a Rest service that must return all the vertices of a graph that has a certain Label and for each of them i should return also the adjacent vertices.

I've built my Traversal properly and then i've performed the terminal step "toList()" for having the vertices found on Dse Graph. For each of these vertices i've called the "vertices" method for finding the adjacent vertices (with Direction.OUT as first arg and "valid_for" as second arg) .

After that i've run a junit test with TinkerGraph object to simulate a db in memory and everything works fine but when i perform a test with Dse Graph remote connection i've seen that the list of vertices returned by "toList()" step are DetachedVertex and the method "vertices" is returning an empty Collection. My question is the following: is there a way for returning the original elements and not a DetachedVertex when i perform the "toList()" step, so i can call the method "vertices" and get all the adjacent vertices from my db?


Thanks.

Re: Question for Detached Vertex in Tinkerpop

Posted by Daniel Kuppitz <me...@gremlin.guru>.
To get all vertices of a specific label and their adjacent vertices
(potentially none), run:

g.V().hasLabel(<specificLabel>).
  project("v","a").
    by().                     // by(valueMap()) if you need the vertex
properties
    by(both().dedup().fold()) // by(both().dedup().valueMap().fold()) if
you need the adjacent vertex properties


This will return a bunch of maps, each containing the two keys v and a,
where v is the vertex with the "specific label" and a is a list that
contains its adjacent vertices.

Cheers,
Daniel


On Wed, Jul 11, 2018 at 3:36 AM, antonio.loregio@relatech.com <
antonio.loregio@relatech.com> wrote:

> Hi guys,
>
>
> my name is Antonio and i'm java developer. First of all i want to
> congratulate with you for the great work you have done with Tinkerpop
> framework.
>
> I' m working with Dse Graph using Tinkerpop for developing a feature of my
> app and i'm facing a problem that i want to share with you.
>
> I've got a Rest service that must return all the vertices of a graph that
> has a certain Label and for each of them i should return also the adjacent
> vertices.
>
> I've built my Traversal properly and then i've performed the terminal step
> "toList()" for having the vertices found on Dse Graph. For each of these
> vertices i've called the "vertices" method for finding the adjacent
> vertices (with Direction.OUT as first arg and "valid_for" as second arg) .
>
> After that i've run a junit test with TinkerGraph object to simulate a db
> in memory and everything works fine but when i perform a test with Dse
> Graph remote connection i've seen that the list of vertices returned by
> "toList()" step are DetachedVertex and the method "vertices" is returning
> an empty Collection. My question is the following: is there a way for
> returning the original elements and not a DetachedVertex when i perform the
> "toList()" step, so i can call the method "vertices" and get all the
> adjacent vertices from my db?
>
>
> Thanks.
>

Re: Question for Detached Vertex in Tinkerpop

Posted by Robert Dale <ro...@gmail.com>.
First, you should be using the Traversal API -
http://tinkerpop.apache.org/docs/current/reference/#traversal - instead of
the Graph API. Then you would return a map that represents the vertex:
g.V().out("valid_for").path().by(valueMap(true))

gremlin> g.V().out().path().by(valueMap(true))
==>[[id:1,label:person,name:[marko],age:[29]],[id:3,label:software,name:[lop],lang:[java]]]
==>[[id:1,label:person,name:[marko],age:[29]],[id:2,label:person,name:[vadas],age:[27]]]
==>[[id:1,label:person,name:[marko],age:[29]],[id:4,label:person,name:[josh],age:[32]]]
==>[[id:4,label:person,name:[josh],age:[32]],[id:5,label:software,name:[ripple],lang:[java]]]
==>[[id:4,label:person,name:[josh],age:[32]],[id:3,label:software,name:[lop],lang:[java]]]
==>[[id:6,label:person,name:[peter],age:[35]],[id:3,label:software,name:[lop],lang:[java]]]


Robert Dale


On Wed, Jul 11, 2018 at 6:51 AM antonio.loregio@relatech.com <
antonio.loregio@relatech.com> wrote:

> Hi guys,
>
>
> my name is Antonio and i'm java developer. First of all i want to
> congratulate with you for the great work you have done with Tinkerpop
> framework.
>
> I' m working with Dse Graph using Tinkerpop for developing a feature of my
> app and i'm facing a problem that i want to share with you.
>
> I've got a Rest service that must return all the vertices of a graph that
> has a certain Label and for each of them i should return also the adjacent
> vertices.
>
> I've built my Traversal properly and then i've performed the terminal step
> "toList()" for having the vertices found on Dse Graph. For each of these
> vertices i've called the "vertices" method for finding the adjacent
> vertices (with Direction.OUT as first arg and "valid_for" as second arg) .
>
> After that i've run a junit test with TinkerGraph object to simulate a db
> in memory and everything works fine but when i perform a test with Dse
> Graph remote connection i've seen that the list of vertices returned by
> "toList()" step are DetachedVertex and the method "vertices" is returning
> an empty Collection. My question is the following: is there a way for
> returning the original elements and not a DetachedVertex when i perform the
> "toList()" step, so i can call the method "vertices" and get all the
> adjacent vertices from my db?
>
>
> Thanks.
>