简体   繁体   English

CYPHER / NEO4J:计算和删除模式理解列表结果中的重复项

[英]CYPHER/NEO4J: Counting and removing duplicates from pattern comprehension list results

I am trying to combine count and distinct with comprehension list and keep getting errors. 我试图将计数和清晰度与理解列表结合起来并不断出错。

I think this explains what I'd like to do, though I'm aware it does not work: 我想这解释了我想做什么,虽然我知道它不起作用:

Match (n) WHERE n.id={id}
RETURN n {.id, ems: [(n)<-[:LOTS_OF_PATHS*]-()<-[:EVEN_MORE_PATHS*]-(m) | id:     distinct m.id, count: count(distinct m)]}

Have also tried with some collects in there 还尝试过那里的一些收藏

Match (n) WHERE n.id={id}
RETURN n {.id, ems: [(n)<-[:LOTS_OF_PATHS*]-()<-[:EVEN_MORE_PATHS*]-(m) | collect(distinct m {id:m.id}), count: count(distinct m)]}

I'm actually collecting the comprehension lists, and ideally would like no repeats within each array, and ideally no repeats amongst the sum of collects. 我实际上正在收集理解列表,理想情况下不希望每个数组中都有重复,理想情况下不会在收集总和中重复。

Match (n) WHERE n.id={id}
RETURN n {.id, collect([(n)<-[:LOTS_OF_PATHS*]-()<-[:EVEN_MORE_PATHS*]-(m) | distinct m.id])+ collect([(n)<-[:OTHER_PATHS*]-()<-[:MORE_PATHS*]-(o) | distinct o.id]) as distinct_ems_and_os} 

The count is less important as I can count the array, but would love to understand it a bit better. 由于我可以计算数组,因此计数不太重要,但是我希望能更好地理解它。

This query (which does not use the fairly limited pattern comprehension) might work for you: 此查询(不使用相当有限的模式理解)可能适合您:

MATCH (n)<-[:LOTS_OF_PATHS*]-()<-[:EVEN_MORE_PATHS*]-(m)
WHERE n.id = $id
WITH COLLECT(DISTINCT m.id) AS ems
RETURN {id: $id, ems: ems, count: SIZE(ems)}

NOTE: variable-length relationships have exponential complexity. 注意: 可变长度关系具有指数复杂性。 You may need to set a reasonable upper bound on the number of hops to avoid running out of memory or long execution times. 您可能需要在跳数上设置合理的上限,以避免内存不足或执行时间过长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM