【问题标题】:Can I rewrite this Cypher query to be compatible with Redis Graph?我可以重写这个 Cypher 查询以与 Redis Graph 兼容吗?
【发布时间】:2020-05-29 18:47:01
【问题描述】:

我的用例是我在组织结构中有一些代理。我想为 some agent 选择(可以由我)查看该代理下属的所有合同的总和(金额)(及其下属的下属等...)与按合同类别分组的客户一起创建。

问题在于 Redis Graph do not currently support all 谓词。但是我需要过滤代理之间的关系,因为我们有多个具有不同组织结构的“模块”,并且我当时只需要来自一个模块的报告。

我当前的 Cypher 查询是:

MATCH path = (:agent {id: 482})<-[:supervised *]-(b:agent)
    WHERE all(rel IN relationships(path) WHERE
        rel.module_id = 1
        AND rel.valid_from < '2020-05-29'
        AND '2020-05-29' < rel.valid_to)
WITH b as mediators
MATCH (mediators)-[:mediated]->(c:contract)
    RETURN
        c.category as category,
        count(c) as contract_count,
        sum(c.sum) as sum
    ORDER BY sum DESC, category

此查询在 Neo4j 中有效。

我不知道这个查询是否针对我想要的结果类型正确编写。

出于性能原因,我的老板真的很想使用 Redis Graph 而不是 Neo4j,但我找不到任何方法来重写此查询以在 Redis 图中发挥作用。有没有可能?

编辑 1: 有人告诉我,我们将仅针对当前有效数据和一个模块使用图表,因此我不再需要功能性 all 谓词,但我仍然对答案感兴趣。

【问题讨论】:

    标签: cypher redisgraph


    【解决方案1】:

    目前不支持ALL 功能,我们确实打算在不久的将来添加它,实现与ALL 功能相同效果的尴尬方法是将UNWINDcount

    MATCH path = (:agent {id: 482})<-[:supervised *]-(b:agent)
    WITH b AS b, relationships(path) AS edges, size(relationships(path)) AS edge_count
    UNWIND edges AS r
    WITH b AS b, edge_count AS edge_count, r AS r
    WHERE r.module_id = 1 AND r.valid_from < '2020-05-29' AND '2020-05-29' < r.valid_to
    WITH b AS b, edge_count AS edge_count, count(r) AS filter_edge_count
    WHERE edge_count = filter_edge_count
    ....
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-23
      • 2021-11-10
      • 2011-04-25
      • 1970-01-01
      相关资源
      最近更新 更多