【问题标题】:Why `.as()`.step used before `.fold()` is not able to use/refer after `.fold()` in apache Gremlin?为什么在 apache Gremlin 中,在 .fold() 之前使用的 .as().step 不能在 .fold() 之后使用/引用?
【发布时间】:2022-11-30 14:56:59
【问题描述】:

为什么在 .fold() 之前使用的 .as().step 在 apache Gremlin 中无法在 .fold() 之后使用/引用?

例如:

g.V().hasLabel('country').has('name', 'Japan').fold()
        .coalesce(__.unfold(), __.addV('country').property('name', 'Japan')).as('country')
    .outE('has').inV().hasLabel('state').has('name', 'A').fold()
        .coalesce(__.unfold(), __.addV('state').property('name', 'A').addE('has').from('country'))

as 的替代步骤是什么?

【问题讨论】:

  • 你的问题有点误导。折叠步骤后跟 as 不是这里的问题。您可以在没有 addE 步骤的情况下运行部分查询,以更好地关注问题和框架问题。

标签: gremlin amazon-neptune janusgraph tinkerpop3


【解决方案1】:

您在遍历时的查询会遇到过滤所有可用值的问题。因此,当调用 add Edge 时,它​​没有任何值绑定到标签 country

您可以稍微更改查询以确保标签的值是国家未被过滤。我在下面写了一个简单的重写,它为你做的。

gremlin> g.V().
......1>   hasLabel('country').
......2>   has('name', 'Japan').
......3>   fold().
......4>   coalesce(__.unfold(), __.addV('country').property('name', 'Japan')).
......5>     as('country').
......6>   coalesce(
......7>     outE('has').inV().hasLabel('state').has('name', 'A'),
......8>     __.addV('state').property('name', 'A')).
......9>   addE('has').from('country')
==>e[18][14-has->16]
gremlin> g.V().valueMap()
==>[name:[A]]
==>[name:[Japan]]
gremlin> g.E()
==>e[18][14-has->16]

【讨论】:

    猜你喜欢
    • 2010-11-29
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 2015-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    相关资源
    最近更新 更多