opencypher / openCypher

Specification of the Cypher property graph query language
http://www.opencypher.org
Apache License 2.0
851 stars 149 forks source link

Support calling aggregation functions on lists in expressions #183

Open boggle opened 7 years ago

boggle commented 7 years ago

CIR-2017-183

Cypher has a great set of aggregation functions that can be used to compute aggregate values over multiple result records.

However it currently is not possible to call these aggregation functions on lists in an expression evaluation context. Currently users that need to achieve this usually try to help themselves by using collect, UNWIND, and list comprehensions.

This CIR looks for a better way to achieve this user goal.

Requirements

Proposals should provide a syntax extensions for allowing to call aggregation functions over lists in an expression evaluation context.

thobe commented 7 years ago

If we use another syntax for aggregation [CIR2017-188], then using the aggregator name with regular function-call syntax could be used to aggregate over a list argument.

thobe commented 7 years ago

Another way to solve this is by scalar subqueries (pending syntax finalization):

RETURN  <(((< UNWIND my_list AS item RETURN sum(item) >)))>
trzeci commented 7 years ago

There is function reduce() having functionality suitable for min/max/sum/avg. E.g.: reduce( i=0, x IN list | i+x ) is equivalent to sum(list).