openCypher
openCypher copied to clipboard
Allow DISTINCT, ORDER BY, LIMIT, and SKIP within pattern comprehensions
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.
Related to CIR-2017-190
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.
Would be solved by #217
This seems like a very useful feature. Does anyone know the status on this?
@SpaghettiFactory see my previous comment. This is (to be) solved by list subqueries, which is a generalisation of pattern comprehension.