【问题标题】:Problem running Gremlin query in CosmosDb在 CosmosDb 中运行 Gremlin 查询时出现问题
【发布时间】:2021-01-22 03:37:08
【问题描述】:

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

g.V().
  has('node', 'id', 'new').
  fold().coalesce(
    unfold(),
    addV('node').
    property('id', 'new').
    property('partitionKey', 'edd1f6ca3b1c446987d7da29e370cc7e')
  ).V().
  has('node', 'id', 'new').
    as('new').
  V().
  has('node', 'id', 'root').
  coalesce(
    outE('contains').where(inV().as('new')),
    addE('contains').to('new')
  ).V().
  has('node', 'id', 'new').
    as('new').
  V().has('userGroup', 'id', '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', 'id', 'new').
  fold().coalesce(
    unfold(),
    addV('node').
    property('id', 'new').
    property('partitionKey', 'edd1f6ca3b1c446987d7da29e370cc7e')
  )
g.V().
  has('node', 'id', 'new').
    as('new').
  V().
  has('node', 'id', 'root').
  coalesce(
    outE('contains').where(inV().as('new')),
    addE('contains').to('new')
  )
g.V().
  has('node', 'id', 'new').
    as('new').
  V().has('userGroup', 'id', 'userGroup1').
  coalesce(
    outE('hasAccess').where(inV().as('new')),
    addE('hasAccess').to('new')
  )

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

【问题讨论】:

    标签: gremlin tinkerpop azure-cosmosdb-gremlinapi


    【解决方案1】:

    根据我在遍历中间使用 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', '_id', 'root').coalesce(
        outE('contains').where(inV().as('new')),
        addE('contains').to('new')
      ).
      select('vertices').unfold().has('userGroup', '_id', 'userGroup1')
      coalesce(
        outE('hasAccess').where(inV().as('new')),
        addE('hasAccess').to('new')
      )
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多