openCypher icon indicating copy to clipboard operation
openCypher copied to clipboard

Syntax differentiation for aggregations

Open Mats-SX opened this issue 8 years ago • 3 comments

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{}
  • Introduction of an explicit grouping clause where the aggregating function is used in a specific position
    • RETURN min(n.cost) GROUP BY n.status

Mats-SX avatar Feb 09 '17 09:02 Mats-SX

Syntax idea: min OF expr

boggle avatar Feb 23 '17 08:02 boggle

Worth pointing out though that choosing different syntax deviates from what people are used to that are coming from SQL.

boggle avatar Feb 23 '17 09:02 boggle

f OF expr works for min, but collect OF expr doesn't look as nice, unfortunately.

Mats-SX avatar Feb 23 '17 12:02 Mats-SX