Ranjith Eswaran
Ranjith Eswaran

Reputation: 333

Partition key of the vertices connected through the edge is not available when querying the Cosmos gremlin Graph

Gremlin API in Azure Cosmos DB allows us to create vertices in different partitions(p1, p2) with same id(v1). When I created a self edge(e1) for a vertex(v1) in one partition(p1), two edges are getting created for vertices in both the partitions(v1 of p1 and v2 of p2). But actually only one edge must be created for the vertex(v1) of p1. I am using the gremlin version 3.4.10 for edge creation. The same behavior of creating duplicate edges was observed, when added the source and target for a vertex in Azure Portal. Find the JSON for the vertices created below.

[
  {
    "id": "v1",
    "label": "v1",
    "type": "vertex",
    "properties": {
      "_partitionKey": [
        {
          "id": "v1|_partitionKey",
          "value": "v1"
        }
      ]
    }
  },
  {
    "id": "v1",
    "label": "v1",
    "type": "vertex",
    "properties": {
      "_partitionKey": [
        {
          "id": "v1|_partitionKey",
          "value": "p2"
        }
      ]
    }
  }
]

Find the JSON for the edges created below

[
  {
    "id": "1bea8dea-6f10-49f5-bf7a-400894a92aae",
    "label": "edge1",
    "type": "edge",
    "inVLabel": "v1",
    "outVLabel": "v1",
    "inV": "v1",
    "outV": "v1"
  },
  {
    "id": "92c72e30-0bea-4ef9-b3c4-9c3879fb5a42",
    "label": "edge1",
    "type": "edge",
    "inVLabel": "v1",
    "outVLabel": "v1",
    "inV": "v1",
    "outV": "v1"
  }
]

I have two problems here

  1. Only one edge must be created. Whereas two edges are getting created when there are vertices with same id in different partitions.
  2. When I create an edge(e1) between two vertices(v1 of p1 and v2 of p1), the JSON for the edge doesn't have the partition key of the in and out vertices. It only has the id and label of the in and out vertices.In this case, I am not able to guess whether this edge(e1) belongs to which vertex(v1 of p1 or v1 of p2). This is because I have both the vertices with same id(v1) and same label(v1) in different partitions(p1 and p2). It will be helpful if I can get the inVertexPartition and outVertexPartition along with inV and outV for the edge JSON.

Upvotes: 0

Views: 472

Answers (1)

mannu2050
mannu2050

Reputation: 403

Out Edge will get stored along with the vertex. If I have created

v1(p1) --e1--> v2(p2), 

then e1 will get stored in the same partition of v1 which is p1. Refer for more information on how partition works in Gremlin API, https://learn.microsoft.com/en-us/azure/cosmos-db/graph-partitioning

Upvotes: 0

Related Questions