英文:
Adding edge between 2 vertices in different partitions in Azure Cosmos DB Gremlin
问题
我尝试将2个顶点添加到不同的逻辑分区,然后想通过一条边连接它们,但在网上找不到任何信息!如何做到这一点?!
Azure Cosmos DB Gremlin API通过分区键(pk)工作,根据pk的值分配数据分布,这通过组隔离顶点和边...我遇到的问题是...无法连接来自不同组的顶点!他们展示得很简单,没有示例,我无法做到![查看下面的图像]
英文:
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]
Links:
-
Getting the best out of Azure Cosmos DB’s scale-out Graph API aka partitioned Graph containers => https://jayanta-mondal.medium.com/getting-the-best-out-of-cosmos-dbs-scale-out-graph-api-aka-partitioned-graph-containers-bf47c240e698
-
Using a partitioned graph in Azure Cosmos DB => https://learn.microsoft.com/en-us/azure/cosmos-db/gremlin/partitioning
-
Partitioning and horizontal scaling in Azure Cosmos DB => https://learn.microsoft.com/en-us/azure/cosmos-db/partitioning-overview
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', 'omar@gmail.com')
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', 'omar@gmail.com'))
the edge adding part seems to not have any effect.
How can I proceed from that?
答案1
得分: 0
当您创建Gremlin API图时,您会定义一个分区键路径。每个顶点的分区键值定义了其逻辑分区。要在不同分区创建顶点,只需为每个顶点定义不同的分区键值。然后,您可以在两个顶点之间创建一条边。
例如,假设您有一个分区键路径为/pk的图,以下两个遍历将分别在不同的逻辑分区中创建一个顶点:
g.addV(‘vertex_label_1’).property(‘id’,’V1’).property(‘pk’,’pkX’)
g.addV(‘vertex_label_2’).property(‘id’,’V2’).property(‘pk’,’pkY’)
然后,此遍历将选择这两个现有顶点并在它们之间创建一条边:
g.V(‘V1’).has(‘pk’,’pkX’).addE(‘edge_label_12’).property(‘id’,’E12’).to(g.V(‘V2’).has(‘pk’,’pkY’))
Gremlin没有事务,因此可能会导致addV步骤中的任何一个失败,或者按顺序执行的遍历可能会超过新图元素的传播延迟。如果这可能会在您的应用程序中引发问题,您可以阅读这篇文章,了解如何使用幂等查询来确保图元素的存在:https://jayanta-mondal.medium.com/cosmos-db-graph-gremlin-api-how-to-executing-multiple-writes-as-a-unit-via-a-single-gremlin-2ce82d8bf365
英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论