简体   繁体   English

Gremlin - 1 次遍历中的顶点和边缘 Upsert

[英]Gremlin - Vertex and Edge Upsert in 1 traversal

I have a Vertex upsert working and an Edge upsert working in 2 separate traversals.我有一个 Vertex upsert 工作和一个 Edge upsert 在 2 个单独的遍历中工作。 Is it possible to combine the 2 into 1 traversal?是否可以将 2 合并为 1 遍历? I have attempted but am receiving errors.我尝试过但收到错误。

a = self.gV().has('account', 'id', 'account-111111111').fold().coalesce( .unfold(), .addV('account').property(T.id, 'account-111111111')).has('customer', 'id', 'cust-111111111').as_('v').V().has('account', 'id', 'account-111111111').coalesce( .inE('owns').where( .outV().as_('v')), .addE('owns').from_( .V('customer', 'id', 'cust-111111111'))) a = self.gV().has('account', 'id', 'account-111111111').fold().coalesce( .unfold(), .addV('account').property(T.id, 'account-111111111')).has('customer', 'id', 'cust-111111111').as_('v').V().has('account', 'id', 'account-111111111 ').coalesce( .inE('owns').where( .outV().as_('v')), .addE('owns').from _(.V('customer', 'id', '客户 111111111')))

a.next() a.next()

Works:作品:

Vertex Upsert:顶点插入:

a = gV().has('account', 'id', 'account-111111111').fold().coalesce( .unfold(), .addV('account').property(T.id, 'account-111111111')) a.next() a = gV().has('account', 'id', 'account-111111111').fold().coalesce( .unfold(), .addV('account').property(T.id, 'account -111111111')) a.next()

Edge Upsert:边缘插入:

a = gV().has('customer', 'id', 'cust-111111111').as_('v').V().has('account', 'id', 'account-111111111). a = gV().has('customer', 'id', 'cust-111111111').as_('v').V().has('account', 'id', 'account-111111111)。 \ coalesce( .inE('owns').where( .outV().as_('v')), .addE('owns').from_( .V('customer', 'id', 'cust-111111111]))) \ coalesce( .inE('owns').where( .outV().as_('v')), .addE('owns').from _(.V('customer', 'id', 'cust- 111111111])))

a.next() a.next()

After studying it for a while, there are quite a few things in your example that will not work.研究了一段时间后,您的示例中有很多东西不起作用。

First of all if you know the ID of a vertex or an edge there is really no need to check the label or any other property.首先,如果您知道顶点或边的 ID,则实际上无需检查 label 或任何其他属性。

Secondly T.id is an ID.其次,T.id 是一个 ID。 The value 'id' would be a property called 'id'.值“id”将是一个名为“id”的属性。

From your question it was a bit hard to piece together what you are wanting to do but here is a first go at what I think you intended.根据您的问题,很难拼凑出您想要做的事情,但这是我认为您想要做的第一个 go。 If this is not in fact what you wanted please edit the question to make it more clear.如果这实际上不是您想要的,请编辑问题以使其更清楚。 Anyway, I hope this helps无论如何,我希望这会有所帮助

g.V('account-111111111').
  fold().
  coalesce(__.unfold(),
           __.addV('account').property(T.id, 'account-111111111')).
  coalesce(__.in('owns').hasId('cust-111111111')),
           __.addE('owns').from_(__.V('cust-111111111')) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM