titanbulbs

edges.create() function causes duplication if called multiple times


I am using TitanGraphDB + Cassandra.I am starting Titan as follows

cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties

I have a Rexster shell that I can use to communicate to Titan+Cassandra above.

cd rexster-console-2.3.0
bin/rexster-console.sh

I am attempting to model a network topology using Titan Graph DB.I want to program the Titan Graph DB from my python program.I am using bulbs package for that. I create three types of vertices - switch - port - device

I use the following functions to create unique vertices if it doesn't already exist.

    self.g.vertices.index.get_unique( "dpid", dpid_str)

    self.g.vertices.index.get_unique( "port_id", port_id_str)

    self.g.vertices.index.get_unique( "dl_addr", dl_addr_str)

I create edges between related vertices as follows.

    self.g.edges.create(switch_vertex,"out",port_vertex)

However if this function is called twice it is creating a duplicate of the edges already present.Is there a function analogous to get_or_create() for edges so that I can avoid duplication.?


Solution

  • In general, graphs permit duplicate edges between vertices because the definition of a duplicate edge is ambiguous and application specific.

    For example, is the edge a duplicate based on its label, direction, or some combination of properties?

    However, Titan 0.5 introduced a Multiplicity.SIMPLE constraint that enables you to define unique edges between a pair of vertices.

    See Matthias's Titan 0.5 announcement:

    This new feature is not yet documented, but the Titan team is in the process of updating the docs for Titan 0.5 so it will be documented soon.

    Watch the Type Definition Overview page for updates:

    Also see the section on cardinality constraints: