Search code examples
graphdatastax-enterprisegremlindatastax-enterprise-graph

DSE graph same vertex part of two vertex labels?


In my case there are two vertex labels : User, Seller.

Register user create new vertex using custom vertex id :

  g.addV(label,'User', 'id', '123456789', 'name', 'User1').next();

When user login and if he register a new business then he become Seller. Now i want same vertex id to be part of Seller label which is not acheivable.

If i create new vertex with seller label then whole graph(hasmobile, hasaddress) stored against user vertex will not be accessible with seller vertex.

Is there way to acheive this in DSE graph ?


Solution

  • The semantics of TinkerPop and DSE Graph (as well as most graph implementations - with Neo4j the only exception I can think of) do not allow a vertex to have multiple labels. You might think of the reason as being why you wouldn't have a row exist in multiple tables in a SQL database.

    There are multiple ways you could resolve this. Make a "Person" vertex (instead of "User" or "Seller") then:

    1. Infer whether they are a "User" or "Seller" from some aspect of the data related to them. Perhaps that is done with an "isSeller" or "isUser" property. Then you would query for sellers with

      g.V().hasLabel('Person').has('isSeller',true)

    2. Create a sub-type system where you connect your "Person" vertex to a "User" vertex or "Seller" vertex. Then you can then do stuff like "find a user only if they are a seller" with

      g.V().hasLabel('User').has('someid','12345'). filter(__.in('isAPerson').out('isASeller'))