使用Gremlin进行边的插入和更新

huangapple go评论42阅读模式
英文:

Upserting an edge using Gremlin

问题

以下是您要翻译的内容:

There are two types of vertices in my graph: Entity and Component.

Components are “ATTACHED_TO” Entities. Components do not exist in the graph as free standing vertices. They are always attached to an Entity. So I don’t need to find Component X in the graph.

When a Component is added, if the Entity it is attached to does not exist then it should be created.

If on upsert both the Component and Entity exist, then the value property of the Component should be updated.

I'm trying to write an efficient gremlin query for AWS Neptune.

https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-efficient-upserts.html documents an optimization that Neptune makes, if properties are not set within coalesce. The following query accomplishes my design, but contains property set within the coalesce.

I've rewritten the query to remove property set within coalesce. I think I'm close, but can't quite seem to get a query that doesn't have some sort of syntax error.

There error is on the where statement. I haven't figured out how to express the where clause.

英文:

There are two types of vertices in my graph: Entity and Component.

Components are “ATTACHED_TO” Entities. Components do not exist in the graph as free standing vertices. They are always attached to an Entity. So I don’t need to find Component X in the graph.

When a Component is added, if the Entity it is attached to does not exist then it should be created.

If on upsert both the Component and Entity exist, then the value property of the Component should be updated.

I'm trying to write an efficient gremlin query for AWS Neptune.

https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-efficient-upserts.html documents an optimization that Neptune makes, if properties are not set within coalesce. The following query accomplishes my design, but contains property set within the coalesce.

g.V('urn:aaid:sc:VA6C2:004ba5d7-5e1c-47a6-824a-0d0822e6415b/#head/#root')
    .fold()
    .coalesce(unfold(),
              addV('Entity')
              .property(id, 'urn:aaid:sc:VA6C2:004ba5d7-5e1c-47a6-824a-0d0822e6415b/#head/#root'))
    .store('e1')
    .in('ATTACHED_TO')
    .has('component_id', 'DocumentProperties')
    .fold()
    .coalesce(unfold().property(single, 'value', '{"mimeType":"application/vnd.adobe.hz.express+dcx","docModelVersion":96,"draftDocumentModels":""}'),
                addV('Component')
                        .property('component_id', 'DocumentProperties')
                        .property('value', '{"mimeType":"application/vnd.adobe.hz.express+dcx","docModelVersion":95,"draftDocumentModels":""}')
                                  .addE('ATTACHED_TO').to(cap('e1').unfold()))

I've rewritten the query to remove property set within coalesce. I think I'm close, but can't quite seem to get a query that doesn't have some sort of syntax error.

g.V('urn:aaid:sc:VA6C2:004ba5d7-5e1c-47a6-824a-0d0822e6415b/#head/#root')
    .fold()
    .coalesce(unfold(),
              addV('Entity')
              .property(id, 'urn:aaid:sc:VA6C2:004ba5d7-5e1c-47a6-824a-0d0822e6415b/#head/#root'))
    .store('entity')
    .in('ATTACHED_TO')
    .has('component_id', 'DocumentProperties')
    .fold()
    .coalesce(unfold(),
                addV('Component')
                        .property('component_id', 'DocumentProperties'))
    .property('value', '{"mimeType":"application/vnd.adobe.hz.express+dcx","docModelVersion":95,"draftDocumentModels":""}')
    .outE('ATTACHED_TO')
    .where(inV(cap('entity').unfold()))
    .fold()
    .coalesce(unfold(),
              addE('ATTACHED_TO').to(cap('entity').unfold()))

There error is on the where statement. I haven't figured out how to express the where clause.

答案1

得分: 1

It's OK to set a property inside of the coalesce as that does not return a property, Gremlin will still return the vertex that the property is applied to in that case. The case where the optimization breaks is if, for example, one part of the coalesce returned a vertex, but the other returned a value such as constant(123). If the query you listed first is working for you it should be fine to use it. The Neptune /profile API will tell you how much of a query is getting fully optimized.

英文:

It's OK to set a property inside of the coalesce as that does not return a property, Gremlin will still return the vertex that the property is applied to in that case. The case where the optimization breaks is if, for example, one part of the coalesce returned a vertex, but the other returned a value such as constant(123). If the query you listed first is working for you it should be fine to use it. The Neptune /profile API will tell you how much of a query is getting fully optimized.

huangapple
  • 本文由 发表于 2023年2月14日 03:33:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75440443.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定