【问题标题】:Gremlin: inject() and has() not working together as expectedGremlin:inject() 和 has() 没有按预期一起工作
【发布时间】:2020-09-28 05:14:10
【问题描述】:

我需要根据传递给inject()的列表创建不重复的顶点,该列表非常大,所以我需要使用inject()。我试过了,但没有用:

g.inject(["Macka", "Pedro", "Albert"]).unfold().map(
    coalesce(
        V().has("name", identity()),
        addV("user").property("name", identity())
    )
)

您可以在这里尝试: https://gremlify.com/765qiupxinw

为什么这不起作用? 看来 V().has() 是返回所有顶点,为什么呢?

【问题讨论】:

    标签: gremlin tinkerpop tinkerpop3 gremlin-server azure-cosmosdb-gremlinapi


    【解决方案1】:

    我认为在这种情况下你应该使用where step 而不是has

    g.inject(["Macka", "Pedro", "Albert"]).unfold().as('n').map(
        coalesce(
            V().where(eq('n')).by('name').by(),
            addV("user").property("name", identity())
        )
    )
    

    示例:https://gremlify.com/06q0zxgd2uam

    【讨论】:

    • has(String,Traversal) 并不像大多数人认为的那样。此版本的has() 旨在评估匿名Traversal 作为过滤器,使用当前属性值作为遍历器。它不会将Traversal 解析为将其用作has() 的对象的值。这里有一些讨论:issues.apache.org/jira/browse/TINKERPOP-1463
    • 这是一个不错的选择吗? V().has("name", where(eq("n")))我觉得它更具可读性并且似乎可以正常工作
    猜你喜欢
    • 2018-03-17
    • 2015-10-09
    • 2015-09-18
    • 1970-01-01
    • 2016-08-13
    • 2013-07-07
    • 2012-12-05
    • 2017-05-22
    • 2019-07-28
    相关资源
    最近更新 更多