【问题标题】:With Gremlin, when using a groupCount() with more than one property, how can I order the results?使用 Gremlin,当使用具有多个属性的 groupCount() 时,如何对结果进行排序?
【发布时间】:2020-08-05 23:40:24
【问题描述】:
g.V().as('a').
 outE().as('r').
 inV().as('b').
 select('a', 'r', 'b').
 project('source','label','target').
 by(select('a').label()).
 by(select('r').label()).
 by(select('b').label()).
 groupCount().
 order(local).by(values, desc).
 unfold()

此查询应该适用于任何 gremlin 数据集。

样本输出:

==>{source=Node, label=POINTS_AT, target=Node}=63
==>{source=Node, label=IS_RELATED_TO, target=Other}=14
==>{source=Other, label=POINTS_AT, target=Other}=3

我刚刚开始学习 Gremlin。此查询对 out vertex label、edge label 和 in vertex label 执行 groupCount 并按值对结果进行排序,这些值只是计数。

键是具有多个值 'source'、'label' 和 'target' 的 Map 条目。我想按边缘标签排序结果,然后按源标签,最后按目标标签。我怎样才能做到这一点?

另外,有没有比我提出的查询更好的方法来解决这个问题?

【问题讨论】:

    标签: gremlin tinkerpop


    【解决方案1】:

    如果没有您的数据集,我不确定这是否正是您想要的,但这是否满足您的需求?

    g.V().as('a').
     outE().as('r').
     inV().as('b').
     project('source','label','target').
     by(select('a').label()).
     by(select('r').label()).
     by(select('b').label()).
     groupCount().
     order(local).
       by(select(keys).select('source')).
       by(select(keys).select('target')).
       by(select(keys).select('label')).
     unfold()
    

    如果您需要,您可以将desc 添加到任何by 调制器。

    【讨论】:

    • 谢谢,这正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 2023-02-20
    • 2012-05-09
    • 2019-12-21
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    相关资源
    最近更新 更多