微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在CosmosDb中运行Gremlin查询时出现问题

如何解决在CosmosDb中运行Gremlin查询时出现问题

我在Azure CosmosDB中运行此Gremlin查询时遇到问题。

g.V().
  has('node','id','new').
  fold().coalesce(
    unfold(),addV('node').
    property('id','new').
    property('partitionKey','edd1f6ca3b1c446987d7da29e370cc7e')
  ).V().
  has('node','new').
    as('new').
  V().
  has('node','root').
  coalesce(
    outE('contains').where(inV().as('new')),addE('contains').to('new')
  ).V().
  has('node','new').
    as('new').
  V().has('userGroup','userGroup1').
  coalesce(
    outE('hasAccess').where(inV().as('new')),addE('hasAccess').to('new')
  )

我遇到两个问题:

  1. 如果数据库中有许多其他节点(350000),查询将超时。我无法在TinkerPop中对此进行测试。
  2. 未创建hasAccess边缘。在TinkerPop中可以使用。

查询的基础是(来自gremlify.com的图像):

g.addV('node').
  property('id','root').
  property('partitionKey','33cb2571f8e348eaa875e6a2639af385')
g.addV('userGroup').
  property('id','userGroup1').
  property('partitionKey','1')

最后我想像这样

可以多次运行而无需更改任何内容(幂等)的查询。如果我在单独的查询中执行此操作,则效果很好:

g.V().
  has('node','edd1f6ca3b1c446987d7da29e370cc7e')
  )
g.V().
  has('node',addE('contains').to('new')
  )
g.V().
  has('node',addE('hasAccess').to('new')
  )

但是我想保存两个对数据库调用并一次性完成。

解决方法

根据我在遍历过程中使用V()步骤的经验,即使在使用诸如has('id',<name>)之类的强大过滤器后,某些供应商也无法很好地对其进行优化,我认为您应该尽量避免如果要执行单个查询,请使用它。 您可以尝试:

g.V().hasLabel('node','userGroup').has('_id',within('new','root','userGroup1')).
  fold().as('vertices').coalesce(
    unfold().has('node','_id','new'),addV('node').property('_id','new').
    property('partitionKey','edd1f6ca3b1c446987d7da29e370cc7e')
  ).as('new').
  select('vertices').unfold().has('node','root').coalesce(
    outE('contains').where(inV().as('new')),addE('contains').to('new')
  ).
  select('vertices').unfold().has('userGroup','userGroup1')
  coalesce(
    outE('hasAccess').where(inV().as('new')),addE('hasAccess').to('new')
  )

示例:https://gremlify.com/pdtla2bsrc/1

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。