openCypher
openCypher copied to clipboard
Syntax differentiation for aggregations
CIR-2017-188
In Cypher today, there exists several aggregating constructs. These are all in the form of functions (and therefore also expressions). However, there is no visible difference between an aggregating function compared to a standard function, which makes aggregations, and by extension grouping, hard to spot in a given query.
Examples
This query is aggregating, and will return one row per value of the n.status expression.
MATCH (n:Device)-->()
RETURN n.status, min(n.cost)
This query is not aggregating, and will return one row per match of the pattern:
MATCH (n:Device)-->()
RETURN n.status, sin(n.cost)
Request
It would aid readability and understandability of queries by having some sort of syntax differentiation for aggregating functions, in such a way that they are not easily confused with standard functions.
Ideas
Some ideas for differentiation:
- Use different form of parenthesis,
{}or[][]are consistently used to denote list expressions, and may thus not be desirable
- Use case-sensitiveness, like all-caps:
MIN(),MAX(), etc- Could be combined with different parenthesis:
MIN{},MAX{}
- Could be combined with different parenthesis:
- Introduction of an explicit grouping clause where the aggregating function is used in a specific position
RETURN min(n.cost) GROUP BY n.status
Syntax idea: min OF expr
Worth pointing out though that choosing different syntax deviates from what people are used to that are coming from SQL.
f OF expr works for min, but collect OF expr doesn't look as nice, unfortunately.