【问题标题】:Upserting multiple vertices in Gremlin from Go从 Go 更新 Gremlin 中的多个顶点
【发布时间】:2023-01-28 01:50:23
【问题描述】:

我已经编写了以下 Go 代码来在 Go 中插入顶点数组。首先,代码没有效果。它不会出错,它只是不执行更新插入。

其次,这是使用 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
}

这是使用 tinkerpop Go 驱动程序 gremlingo。

【问题讨论】:

    标签: go gremlin


    【解决方案1】:

    你的Coalesce looks wrong。你能试试吗

                Coalesce(AnonT.Unfold(),
                         AnonT.AddV("Entity").Property("asset_id", assetID).Property("version", version).Property("entity_id", r.EntityID)).Iterate()
    

    这假设 AnonT 被定义为

    var AnonT = gremlingo.T__
    

    在您的原始查询中,Coalesceg.V().Unfold() 开头,它将始终产生结果(除非图表为​​空),因此永远不会执行 Coalesce 的替代部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-03
      • 1970-01-01
      • 2015-07-06
      • 2019-02-14
      • 2012-03-12
      • 2016-12-30
      • 1970-01-01
      相关资源
      最近更新 更多