[英]Upserting multiple vertices in Gremlin from Go
I've written the following Go code to upsert and array of vertices in Go. First off, the code has not effect.我已经编写了以下 Go 代码来更新 Go 中的顶点数组。首先,代码没有效果。 It doesn't error out, it just doesn't do the upserts.
它不会出错,它只是不执行更新。
Second, is this the most efficient way to upsert a batch of vertices using Gremlin?其次,这是使用 Gremlin 更新一批顶点的最有效方法吗?
func (n NeptuneGremlinGraph) Put(assetID string, version string, records []les.DeltaEditRecord) error {
g := gremlin.Traversal_().WithRemote(n.connection)
for _, r := range records {
promise := g.V().HasLabel("Entity").Property("asset_id", assetID).Property("version", version).Property("entity_id", r.EntityID).Fold().
Coalesce(g.V().Unfold(),
g.AddV("Entity").Property("asset_id", assetID).Property("version", version).Property("entity_id", r.EntityID)).Iterate()
err := <-promise
if err != nil {
return err
}
}
return nil
}
This is using the tinkerpop Go driver gremlingo.这是使用 tinkerpop Go 驱动程序 gremlingo。
Your Coalesce
looks wrong.您的
Coalesce
看起来不对。 Can you please try你能试试吗
Coalesce(AnonT.Unfold(),
AnonT.AddV("Entity").Property("asset_id", assetID).Property("version", version).Property("entity_id", r.EntityID)).Iterate()
This assumes AnonT
was defined as这假设
AnonT
被定义为
var AnonT = gremlingo.T__
In your original query, the Coalesce
started with gV().Unfold()
which is going to always yield results (unless the graph is empty) so the alternate part of the Coalesce
will never get executed.在您的原始查询中,
Coalesce
以gV().Unfold()
开头,它将始终产生结果(除非图形为空),因此Coalesce
的替代部分将永远不会执行。
Using the Fold
... Coalesce
pattern is a perfectly reasonable way to do a "create if not exist" type of operation.使用
Fold
... Coalesce
模式是执行“如果不存在则创建”类型操作的一种非常合理的方法。 Note that in Apache TinkerPop 3.6.xa new step called MergeV
(along with a corresponding MergeE
) was added.请注意,在 Apache TinkerPop 3.6.x 中,添加了一个名为
MergeV
的新步骤(以及相应的MergeE
)。 This will help simplify these types of tasks.这将有助于简化这些类型的任务。
It looks from your code sample that you may be using Amazon Neptune.从您的代码示例来看,您可能正在使用 Amazon Neptune。 If so, support for
MergeV
is not quite there yet in Neptune, so keep using the Coalesce
idiom until Neptune adds that support.如果是这样,那么 Neptune 中还没有完全支持
MergeV
,因此请继续使用Coalesce
习惯用法,直到 Neptune 添加该支持。
UPDATED based on comment discussion根据评论讨论更新
Also, as discussed in the comments, this line另外,正如评论中所讨论的,这一行
g.V().HasLabel("Entity").Property("asset_id", assetID).Property("version", version).Property("entity_id", r.EntityID).Fold().
should use Has
instead of Property
应该使用
Has
而不是Property
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.