josef.schauer_169242 avatar image
josef.schauer_169242 asked josef.schauer_169242 commented

How can I get my Groovy code to work in Studio?


I have a question about using groovy code in dse-studio the right way.

schema setup




g.addV('Vertex').property('vId', '10000000-0000-0000-0000-100000000001')
.property('property1', 'Text1',, UUID.fromString('83755ac4-7d66-42cf-a824-1a6960b5772f'), 'aId', '83755ac4-7d66-42cf-a824-1a6960b5772f', 'cId', '["00000000-0000-0000-0000-100000000001"]')

g.addV('Vertex').property('vId', '10000000-0000-0000-0000-100000000002')
.property('property1', 'Text1',, UUID.fromString('67755ac4-7d66-42cf-a824-1a6960b5772f'), 'aId', '67755ac4-7d66-42cf-a824-1a6960b5772f', 'cId', '["00000000-0000-0000-0000-100000000002"]')


I want to loop over the vertices and add a property. But the property I want to add needs information from the current vertex in the loop. This is for migrating existing data, high performance is no requirement.

I prepared the following code. I tried to use groovy as much as possible, because for me as a java developer it seems to be the easiest way.

vertices = g.V().hasLabel('Vertex').has('property1', regex('.*')).iterator()

while(vertices.hasNext()) {
    vertex =;
    UUID vId = UUID.fromString((String)'vId').next().value());
    UUID aId = UUID.randomUUID();
    g.V().hasLabel('Vertex').has('vId', vId).property('property2', 'Text2',, aId, 'aId', aId, 'cId', '["'+vId+'"]');

As you can see, I filter for vertices and create the iterator. Then I iterate over the list and prepare some data which I need in the "property"-step.

I need a new UUID which is used twice in the property step. Also, the vertex id is used in the step. Then I filter again based on the current id and want to add the property.

The code runs without any error but doesn't do anything.

How can I get this runnable? I would prefer to use groovy, but if not possible a gremlin command would help, too.

Thanks in advance.

Josef Schauer

1 comment
10 |1000

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

Erick Ramirez avatar image Erick Ramirez ♦♦ commented ·

@josef.schauer_169242 Just acknowledging your ticket. It might have something to do with not having full Groovy support. I'm going to reach out to the DSE Graph team to get you an answer. Cheers!

0 Likes 0 ·

1 Answer

polandll avatar image
polandll answered josef.schauer_169242 commented

A couple of things to say about this issue. First, add:


to the end of the first line in the add vertices codeblock, so that both vertices will be added.

That's the missing piece in the while loop, too. Add that iterate() to the add property statement in the while loop and it works just fine.

1 comment Share
10 |1000

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

josef.schauer_169242 avatar image josef.schauer_169242 commented ·

works, thanks.

1 Like 1 ·