openCypher icon indicating copy to clipboard operation
openCypher copied to clipboard

Allow DISTINCT, ORDER BY, LIMIT, and SKIP within pattern comprehensions

Open InverseFalcon opened this issue 7 years ago • 5 comments

CIR-2017-202

While it is possible to take a slice of the resulting list from pattern comprehension, this operation is not lazy (like LIMIT), so all results of the comprehension must be computed to form the full list, then the resulting slice is taken.

This is request for using LIMIT (or perhaps a separate keyword, if the overloaded usage is too confusing) within a pattern comprehension, which only limits the number of results within the resulting collection. It will not limit the number of rows of the query.

Here's an example of a query using this proposed feature request that gets 5 actors, and for each of those 5 actors gets 2 movies they've acted in:

MATCH (actor:Person) WITH actor LIMIT 5 RETURN actor, [(actor)-[:ACTED_IN]->(m:Movie) | m LIMIT 2] as movies

This also requests ORDER BY and SKIP, in similar placement, before LIMIT and after the expression defining the elements for the collection.

InverseFalcon avatar Mar 06 '17 15:03 InverseFalcon

Related to CIR-2017-190

thobe avatar Mar 06 '17 16:03 thobe

Supporting usage of DISTINCT would also be great, otherwise we have to rely on apoc.coll.toSet() to get the list of distinct values, which is problematic because this would happen after LIMIT, SKIP, and ORDER BY.

InverseFalcon avatar Apr 26 '17 04:04 InverseFalcon

Would be solved by #217

thobe avatar Dec 20 '18 12:12 thobe

This seems like a very useful feature. Does anyone know the status on this?

SpaghettiFactory avatar May 26 '20 22:05 SpaghettiFactory

@SpaghettiFactory see my previous comment. This is (to be) solved by list subqueries, which is a generalisation of pattern comprehension.

thobe avatar May 27 '20 07:05 thobe