【问题标题】:Accessing and compare properties of the stored edge in traversal在遍历中访问和比较存储边的属性
【发布时间】:2021-05-23 10:25:51
【问题描述】:

我有以下图形模型:

我想选择已通过控制器执行操作的用户。 performed-by 边缘包含 used_user_key 属性,我想使用该属性来选择连接到所需用户的 called-by 边缘以下条件:called-by.user_key == perform-b​​y.used_user_key 属性。

我将 performed-by 存储在 action_edge 中,并尝试在 has 步骤中使用存储的值。

问题:has('user_key', select('action_edge').values('used_user_key')) 产生随机边。

问题:我应该如何在 has 步骤中从存储的边缘获取/引用属性?

GraphDB:JanusGraph 0.5.2 gremlinpython:3.5.0

用于重现问题的 Python sn-p:

user_a = g.addV('user').property('name', 'a').next()
user_b = g.addV('user').property('name', 'b').next()
user_c = g.addV('user').property('name', 'c').next()
controller = g.addV('controller').property('name', 'controller').next()
action = g.addV('action').property('name', 'action').next()

g.V(user_a).as_('to').V(controller).as_('from') \
    .addE('called-by') \
    .property('user_key', 'user_a') \
    .to('to') \
    .next()

g.V(user_b).as_('to').V(controller).as_('from') \
    .addE('called-by') \
    .property('user_key', 'user_b') \
    .to('to') \
    .next()

g.V(user_c).as_('to').V(controller).as_('from') \
    .addE('called-by') \
    .property('user_key', 'user_c') \
    .to('to') \
    .next()

g.V(controller).as_('to').V(action).as_('from') \
        .addE('performed-by') \
        .property('used_user_key', 'user_a') \
        .to('to') \
        .next()

# Works as expected!
user_perming_the_action = g.V(action).outE('performed-by').as_('action_edge').inV() \
    .outE('called-by').has('user_key', 'user_a').inV() \
    .next()
assert user_a.id == user_perming_the_action.id

# Selects random user - ignores all action_edge.used_user_key value
user_perming_the_action = g.V(action).outE('performed-by').as_('action_edge').inV() \
    .outE('called-by').has('user_key', select('action_edge').values('used_user_key')).inV();

# Why it yield 3 instead of 1 edge?
assert user_perming_the_action.clone().count().next() == 3
# Returns random user
assert user_a.id == user_perming_the_action.clone().next().id

提前感谢您的帮助!

【问题讨论】:

    标签: gremlin janusgraph gremlinpython


    【解决方案1】:

    经过一番研究,我发现了以下问题的解决方案:

        user_perming_the_action = g.V(action).outE('performed-by').as_('action_edge').inV() \
            .outE('called-by').where(eq('action_edge')).by('user_key').by('used_user_key').inV() \
            .next()
        assert user_a.id == user_perming_the_action.id
    

    我正在使用两个 by 调制器比较具有不同名称的属性与 where 的边缘。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      相关资源
      最近更新 更多