List subscript with an inline aggregate index may return null (original) (raw)
ArcadeDB version
Observed on Docker images:
arcadedata/arcadedb:latestarcadedata/arcadedb:26.3.2arcadedata/arcadedb:26.4.1-SNAPSHOTarcadedata/arcadedb:26.4.2
Environment
- Host OS: Windows 10
- Architecture: x86_64
- Deployment: Docker
- ArcadeDB endpoint: HTTP
/api/v1/command/arcade - Request mode matches ArcadeDB Studio:
language: opencypherserializer: studio
- Differential comparison target: Neo4j Docker
neo4j:latest
Describe the bug
ArcadeDB may return null when a list subscript uses an inline aggregate expression as the index, even though:
- the same aggregate expression evaluates correctly on its own
- the same list subscript works when the index is first materialized in
WITH
In the minimized repro below, Neo4j returns the first score (85).
ArcadeDB returns null.
To Reproduce
Setup:
CREATE (:Person {name:'Alice', scores:[85,92,78]});
Query:
MATCH (p:Person {name:'Alice'}) OPTIONAL MATCH (p)-[:HAS_FRIEND]->(f:Person) WITH p, collect(f) AS friends RETURN p AS person, p.scores[toInteger(avg(size(friends)))] AS selectedScore;
Expected behavior
With no matching HAS_FRIEND relationships:
collect(f)becomes[]size(friends)is0avg(size(friends))is0toInteger(...)is0
So the query should return the first score:
Observed Neo4j result:
(:Person {name: "Alice", scores: [85, 92, 78]}), 85
Actual behavior
ArcadeDB returns the person correctly, but selectedScore becomes null:
(:Person {name: "Alice", scores: [85, 92, 78]}), null
Control query 1
If the same index is computed first and then reused, ArcadeDB behaves correctly:
MATCH (p:Person {name:'Alice'}) OPTIONAL MATCH (p)-[:HAS_FRIEND]->(f:Person) WITH p, collect(f) AS friends WITH p, toInteger(avg(size(friends))) AS idx RETURN p AS person, p.scores[idx] AS selectedScore, idx;
Observed result on both Neo4j and ArcadeDB:
(:Person {name: "Alice", scores: [85, 92, 78]}), 85, 0
So the aggregate expression itself is not the problem.
Control query 2
If the subscript uses a non-aggregate index, ArcadeDB also behaves correctly:
MATCH (p:Person {name:'Alice'}) OPTIONAL MATCH (p)-[:HAS_FRIEND]->(f:Person) WITH p, collect(f) AS friends RETURN p AS person, p.scores[size(friends)] AS selectedScore;
Observed result on both Neo4j and ArcadeDB:
(:Person {name: "Alice", scores: [85, 92, 78]}), 85
This makes the boundary clearer: the failure is tied to using the aggregate expression inline inside the list subscript.