Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

josef.schauer_169242 avatar image
josef.schauer_169242 asked ·

How to create a result list in gremlin query?

v1= g.V().hasLabel('Vertex1').has('id', '08f0b5d7-5fed-4d00-875d-49cad4d0e9bd').next()
v2= g.V().hasLabel('Vertex2').has('id', '08f0b5d7-5fed-4d00-875d-49cad4d0e9b1').next()

e1 = v1.addEdge('Edge1', v2, T.id, UUID.fromString('18f0b5d7-5fed-4d00-875d-49cad4d0e9b1'), 'date', '2019-06-06')

How can I return the two vertices and the edge in the result list?

graphgremlin
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

bryn.cooke_101029 avatar image
bryn.cooke_101029 answered ·

It's worth bearing in mind that the new Core graph engine does not support calling 'Vertex#addEdge' and you will get a message: Edge additions not supported.

You should use something like this to add edges:

g.addV('person').property('name', 'bob').as('person').
  addV('software').property('name', 'Studio').as('software').
  addE('created').from('person').to('software').as('created')

The advantage of the above is that it doesn't require a read before write and will be much faster. This will also work in `Classic` graphs.

For your purposes you can the use 'select' to get back the original elements:

g.addV('person').property('name', 'bob').as('person').
  addV('software').property('name', 'Studio').as('software').
  addE('created').from('person').to('software').as('created').
  select('person','software', 'created')

==>{person=v[person:bob#64], software=v[software:Studio#05], created=e[person:bob#64->created#96->software:Studio#05][person:bob#64-created->software:Studio#05]}


4 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

found the very simple Solution: [v1, v2, e1]

0 Likes 0 ·

But the read is important in this example, because I want to create an edge between two already existing vertices.

How this would be solved for the new Core Graph Engine?

0 Likes 0 ·

Thanks for choosing DataStax! Just a friendly note since we're all new here but this is really a "comment" rather than an "answer". Just a friendly advice for those who come across "answers" in the future. Cheers! :)

0 Likes 0 ·

But the read is important in this example, because I want to create an edge between two already existing vertices.

How this would be solved for the new Core Graph Engine?

0 Likes 0 ·