Typescript 如何在小精灵中移动边缘
我是小精灵的新手,在Azure Cosmos DB中使用typescript,这意味着我不允许使用所有酷炫的新功能,比如副作用 我有一个类似树的场景,其中顶点是其他顶点的父节点,但只能有一个自己的父节点和一个在一个顶点工作的人 以下是我的图表的一些示例数据:Typescript 如何在小精灵中移动边缘,typescript,gremlin,azure-cosmosdb-gremlinapi,Typescript,Gremlin,Azure Cosmosdb Gremlinapi,我是小精灵的新手,在Azure Cosmos DB中使用typescript,这意味着我不允许使用所有酷炫的新功能,比如副作用 我有一个类似树的场景,其中顶点是其他顶点的父节点,但只能有一个自己的父节点和一个在一个顶点工作的人 以下是我的图表的一些示例数据: g.addV('person').property('partitionKey', 'person').property('accountID','1') g.addV('unit').property('partitionKey', 'u
g.addV('person').property('partitionKey', 'person').property('accountID','1')
g.addV('unit').property('partitionKey', 'unit').property('unitID', '1')
g.addV('unit').property('partitionKey', 'unit').property('unitID', '2')
g.addV('unit').property('partitionKey', 'unit').property('unitID', '3')
g.V().has('accountID','1').as('p').V().has('unitID','1').addE('employedAt').from('p')
g.V().has('unitID','1').as('u').V().has('unitID','2').addE('parentOf').from('u')
g.V().has('unitID','2').as('u').V().has('unitID','3').addE('parentOf').from('u')
该树现在看起来像:
person
|
employedAt
|
unit1
/ \
parentOf parentOf
| |
unit2 unit4
|
parentOf
|
unit3
个人---受雇于---->unit1---->unit2---->unit3的父母
我们现在想让第二单元成为第三单元的孩子
之后的预期结果:
个人---受雇于---->unit1---->unit3---->unit2的父母
现在,我们希望移动一个顶点(创建一个新的传入边父节点并删除旧的顶点)
第一个块是检查此人是否可以访问这两个顶点。感觉不是很好,但我不知道如何做得更好
coalesce中的第一个语句是将顶点向下移动(使其成为其Subversice之一的子对象)。因此,我们检查它是否是targetVertex的父级,当它是父级时,它也会执行此合并语句的其余部分
第二个语句是将顶点移动到树中的另一个分支。当这不是“困难”部分时,这一点就会实现
我现在有几个问题:
我试图从您的查询和示例中理解逻辑,我希望这是您所需要的
g.V().has('person', 'accountID', accountID).
out('employedAt').as('employedAtVertex').
// Check if the employedAtVertex is parentOf the movingVertex and targetVertex
emit(has('unitID', within(movingVertexID, targetVertexID))).
repeat(out('parentOf')).
fold().where(count(local).is(2)).as('vertices').
unfold().has('unitID', targetVertexID).as('targetVertex').
// Check if the movingVertex is parentOf the targetVertex
choose(until(has('unitID', movingVertexID)).repeat(__.in('parentOf')),
// ### First Part: Make a vertex the children of his own children
select('vertices').unfold().has('unitID', movingVertexID).as('movingVertex')
union(
__.in('parentOf').addE('parentOf').to(select('movingVertex').out('parentOf')),
bothE('parentOf').drop(),
addE('parentOf').from('targetVertex')
),
// ### Second Part: Make a vertex the children of a vertex higher in the tree or in an other branch
union(
inE('parentOf').drop(),
addE('parentOf').from('targetVertex'),
)
)
示例:我试图从您的查询和示例中理解逻辑,我希望这是您所需要的
g.V().has('person', 'accountID', accountID).
out('employedAt').as('employedAtVertex').
// Check if the employedAtVertex is parentOf the movingVertex and targetVertex
emit(has('unitID', within(movingVertexID, targetVertexID))).
repeat(out('parentOf')).
fold().where(count(local).is(2)).as('vertices').
unfold().has('unitID', targetVertexID).as('targetVertex').
// Check if the movingVertex is parentOf the targetVertex
choose(until(has('unitID', movingVertexID)).repeat(__.in('parentOf')),
// ### First Part: Make a vertex the children of his own children
select('vertices').unfold().has('unitID', movingVertexID).as('movingVertex')
union(
__.in('parentOf').addE('parentOf').to(select('movingVertex').out('parentOf')),
bothE('parentOf').drop(),
addE('parentOf').from('targetVertex')
),
// ### Second Part: Make a vertex the children of a vertex higher in the tree or in an other branch
union(
inE('parentOf').drop(),
addE('parentOf').from('targetVertex'),
)
)
示例:第一部分工作完美。结果与预期相符 我现在对第二部分有一个问题。 当我创建一棵树时,它看起来像:
person
|
employedAt
|
unit1
/ \
parentOf parentOf
| |
unit2 unit4
|
parentOf
|
unit3
我现在想把第二单元变成第四单元的孩子,但这行不通。
我有两个以上的unitID 2用于movingVertex,unitID 4用于targetVertex
预期结果如下所示:
person
|
employedAt
|
unit1
|
parentOf
|
unit4
|
parentOf
|
unit2
|
parentOf
|
unit3
但是它什么也做不了。第一部分工作得很完美。结果与预期相符 我现在对第二部分有一个问题。 当我创建一棵树时,它看起来像:
person
|
employedAt
|
unit1
/ \
parentOf parentOf
| |
unit2 unit4
|
parentOf
|
unit3
我现在想把第二单元变成第四单元的孩子,但这行不通。
我有两个以上的unitID 2用于movingVertex,unitID 4用于targetVertex
预期结果如下所示:
person
|
employedAt
|
unit1
|
parentOf
|
unit4
|
parentOf
|
unit2
|
parentOf
|
unit3
但它没有任何作用。由于这是一个复杂的用例,我认为如果您添加一个脚本来生成示例数据或保存的gremlify示例,效果会更好。然后给出该数据的预期行为。您好,感谢您解释如何获得帮助。我已经更新了我的问题,并在中添加了一个示例以及预期的结果。这是一个复杂的用例,我认为如果您添加一个脚本来生成示例数据或保存gremlify示例会更好。然后给出该数据的预期行为。您好,感谢您解释如何获得帮助。我已经更新了我的问题,并在中添加了一个示例,以及预期的结果