Skip to content

OpenCypher: Aggregation with CASE statement returns multiple rows (implicit GROUP BY) #3858

Description

@victorkashirin

Hey ArcadeDB team,

I ran into an issue with the OpenCypher interpreter within ArcadeDB. When I put a CASE statement inside an aggregation function like sum() or count(), ArcadeDB accidentally uses the variable inside the CASE as a grouping key.

Instead of returning a single row for the total, it splits the results into multiple rows.

Example to reproduce:

UNWIND [{state: 'NY'}, {state: 'PA'}, {state: 'PA'}] AS loc
RETURN count(loc) AS total, sum(CASE WHEN loc.state = 'PA' THEN 1 ELSE 0 END) AS pa

What ArcadeDB returns:
It splits the result into multiple rows based on the state variable:

total pa
1 0
2 1

What I expect it return:
I tested this query on neo4j and memgraph playgrounds, and there it returns exactly one row. Because both items in the RETURN clause are aggregations and there are no stray variables, Cypher collapses it into one result:

total pa
3 2

It seems like the execution planner is peeking inside the sum() and grouping by loc.state under the hood.

ArcadeDB Version: 26.3.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions