【问题标题】:gremlin query using select() in coalesce() step在 coalesce() 步骤中使用 select() 进行 gremlin 查询
【发布时间】:2021-05-04 15:34:54
【问题描述】:

我正在尝试在 coalesce() 内的第二次遍历中使用 .as() 访问之前保存的遍历,如下所示:

查询更新边缘(更新边缘如果存在/创建)

Java 代码:

g.V('x').as('start')
 .V('y').as('stop')
.inE('label').where(outV().as('edge'))
.select('start','stop','edge').fold()
.coalesce(unfold(),
        addE('label').from(select('start')).to(select('stop')))
.property('key','value')
.promise(Traversal::Next);

抛出如下错误:(为简洁起见)

gremlin.driver.exception.ResponseException: 提供的遍历器没有映射到值 [stop]

当我替换最后一步时,它的工作正常(而不是再次查询顶点的别名)

替换为addE('label').from(select('start')).to(select('stop'))

addE('label').from(V('x')).to(V('y'))

在coalesce 的第二次遍历中是否有引用别名?

注意:我正在收集与在合并之前查找边相关的所有数据以便在创建边时在缺少任何顶点/顶点时使 gremlin 抛出错误

预期行为:交易成功时为真,创建边时任何顶点丢失时出错。

这在不使用 as() 别名的情况下按预期工作。但是,我正在尝试使用 as()。我做不到。

希望这很清楚。如果需要更多信息,请发表评论。谢谢。

【问题讨论】:

    标签: gremlin coalesce tinkerpop amazon-neptune graph-traversal


    【解决方案1】:

    您无法选择标签“开始”和“停止”的原因是您在定义它们之后使用了fold()fold() 是一个reducing barrier step,它会导致之前定义的所有标签丢失。

    在我解释解决方案之前,这里是添加两个测试顶点的遍历。

    g.addV().property(id, 'x').
      addV().property(id, 'y')
    

    如果缺少任何顶点“x”或“y”,则以下遍历将返回字符串“错误”。如果两个顶点都存在,则更新边(如果存在则更新边,如果不存在则添加它)。

    g.inject(1).
      optional(V('x').as('start')).
      choose(
        select('start'),
        optional(V('y').as('stop')).
        choose(
          select('stop'),
          coalesce(
            select('start').outE('label').as('e').inV().where(eq('stop')).select('e'),
            addE('label').from('start').to('stop')).
            property('key', 'value'),
          constant('error')),
        constant('error'))
    

    【讨论】:

    • 感谢@Bassem。我之前有类似的方法,如果在创建边缘时缺少任何顶点,则不会引发错误,这是我的要求。我已经更新了这个问题。很抱歉错过了那部分。这还有可能吗?如果可以,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多