Re: similar edges and how to prevent them


yair...@...
 





One Option I thought of that should have worked but doesn't is:

Assuming I have a method to create between 'from' vertex and 'to' vertex:



       
Iterator<Edge> edgesIter = from.edges(Direction.OUT, "link");


       
while (edgesIter.hasNext()) {
           
Edge edge = edgesIter.next();
           
Vertex outVertex = edge.outVertex();
           
if(outVertex.property("nodeId").value().equals(to.property("nodeId").value())){
               
return edge;
           
}


       
}
        org
.apache.tinkerpop.gremlin.structure.Edge linkedEdge = from.addEdge("link", to);
       
return linkedEdge;


I still get duplicate edges when I re-run my app. and yes I do commit the tx after i'm done.

Any ideas?


On Monday, September 11, 2017 at 9:53:49 AM UTC+3, ya...@... wrote:

I have an app where I am migration a d non graph DB graph to Janus. So I create the graph when I first start the app. Using cassandra backend.

I have an issue where 2 vertices have "identical" edges (besides the auto-generated id of course) are created in my code causing me to get too many IN and OUT edges.

I read my vertex like this:


javaGraph.traversal().V().hasLabel(instanceId).has("nodeId", lineageNodeId).toList();




I read Both edges:

vertex.edges(org.apache.tinkerpop.gremlin.structure.Direction.IN, "link");


vertex
.edges(org.apache.tinkerpop.gremlin.structure.Direction.OUT, "link");


each time I run my app it doesn't "see" the existing edges and adds to it. so I get edges multiplies while I only want "link" edge between any 2 given vertices

in order to make sure I don't create duplicate vertices:


        GraphTraversal<Vertex, Vertex> vertexNode = javaGraph.traversal().V().hasLabel(instanceId).has("nodeId", myNodeId);
        if (vertexNode.hasNext()) {
            return vertexNode.next();
        } else {            

            JanusGraphVertex node = javaGraph.addVertex(instanceId);
            node.property("nodeId", myNodeId);
            return node;
        }



But I don't know once I have vertex A and B at hand - how to verify they are not already connected.






Join {janusgraph-users@lists.lfaidata.foundation to automatically receive all group messages.