Search code examples
azureazure-cosmosdbgremlin

Adding edge between 2 vertices in different partitions in Azure Cosmos DB Gremlin


I am trying to add 2 vertices to different logical partitions, then i want to connect them through an edge, but couldn't find anything online! How to do it?!

Azure Cosmos DB Gremlin API works via Partition Key (pk) by distributing data alocation based on the value of pk ... this isolates VErtices and edges by group ... the problem i'm having is ... not being able to connect to vertices from distinct groups! They show case it simple, with no example and i couldn't do it! [check image below]

2 vertices between 2 partitions


Links:


On Azure Cosmos DB Gremlin, you have to specify the Partition Key to where the Vertex is going to be stored ... tried this:

being pk = Person_Natural_Customer_ID

g.addV('Person_Natural').property('Person_Natural_Full_Name', 'Omar Ghoche').property('Person_Natural_Customer_ID', '6753902')

then with pk = Object_Email_Address:

g.addV('Object_Email_Address').property('Object_Email_Address_Email', '[email protected]')

one of the obstacles is connecting these 2 vertices that live in different logical partitions!

g.addE('Uses_Email').from(g.V().has('Person_Natural_Customer_ID', '6753902')).to(g.V().has('Object_Email_Address_Email', '[email protected]'))

the edge adding part seems to not have any effect.

How can I proceed from that?


Solution

  • When you create your Gremlin API graph you define a partition key path. The value of the partition key for each vertex defines its logical partition. To create vertices in different partitions, you simply define each vertex with a different partition key value. You can then create an edge between the two vertices.

    For example, assuming you have a graph with partition key path /pk, the following two traversals will each create a vertex in a different logical partition:

    g.addV(‘vertex_label_1’).property(‘id’,’V1’).property(‘pk’,’pkX’)

    g.addV(‘vertex_label_2’).property(‘id’,’V2’).property(‘pk’,’pkY’)

    This traversal will then select the two existing vertices and create an edge between them:

    g.V(‘V1’).has(‘pk’,’pkX’).addE(‘edge_label_12’).property(‘id’,’E12’).to(g.V(‘V2’).has(‘pk’,’pkY’))

    Gremlin does not have transactions so it is possible that either of the addV steps may fail or that the sequentially executed traversals may beat the propagation delay for the new graph elements. If it’s possible that this can cause issues in your application, you can read this article on using idempotent queries to ensure the existence the graph elements:

    https://jayanta-mondal.medium.com/cosmos-db-graph-gremlin-api-how-to-executing-multiple-writes-as-a-unit-via-a-single-gremlin-2ce82d8bf365