List subscript with an inline aggregate index may return null (original) (raw)

ArcadeDB version
Observed on Docker images:

Environment

Describe the bug
ArcadeDB may return null when a list subscript uses an inline aggregate expression as the index, even though:

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:

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.