Hello,
I have a question about using groovy code in dse-studio the right way.
schema setup
schema.propertyKey('vId').Uuid().single().ifNotExists().create() schema.propertyKey('cId').Text().single().ifNotExists().create() schema.propertyKey('aId').Uuid().single().ifNotExists().create() schema.propertyKey('property1').Text().multiple().properties('cId','aId').ifNotExists().create() schema.propertyKey('property2').Text().multiple().properties('cId','aId').ifNotExists().create() schema.vertexLabel('Vertex').partitionKey('vId').properties('property1','property2').ifNotExists().create() schema.vertexLabel('Vertex').index('search').search().by('property1').by('property2').ifNotExists().add()
data
g.addV('Vertex').property('vId', '10000000-0000-0000-0000-100000000001') .property('property1', 'Text1', T.id, 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', T.id, UUID.fromString('67755ac4-7d66-42cf-a824-1a6960b5772f'), 'aId', '67755ac4-7d66-42cf-a824-1a6960b5772f', 'cId', '["00000000-0000-0000-0000-100000000002"]')
problem
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 = vertices.next(); UUID vId = UUID.fromString((String)vertex.properties('vId').next().value()); UUID aId = UUID.randomUUID(); g.V().hasLabel('Vertex').has('vId', vId).property('property2', 'Text2', T.id, 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