Node.js AGE driver unable to handle nested array in result set
- Dominant language
- C
- Stars
- 4.8k
- Forks
- 523
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 9
Description
Hi all,
I have a query that collects and consolidates various bits of data into a derived object, but it seems to cause a problem for the AGE driver (NodeJS). Below is a contrived example you can use to replicate the issue.
## Setup
```
SELECT * FROM ag_catalog.create_graph('nesteddemo');
SELECT create_vlabel('nesteddemo','Building');
SELECT create_vlabel('nesteddemo','User');
SELECT create_vlabel('nesteddemo','Comestible');
SELECT create_elabel('nesteddemo','likes');
SELECT create_elabel('nesteddemo','lives_in');
SELECT * FROM ag_catalog.cypher('nesteddemo', $$
CREATE (b1:Building {id: "b001", name: 'Building One'})
CREATE (b2:Building {id: "b002", name: 'Building Two'})
CREATE (u1:User {id: "u001", name: 'User One'})
CREATE (u2:User {id: "u002", name: 'User Two'})
CREATE (u3:User {id: "u003", name: 'User Three'})
CREATE (p1:Comestible {name: 'Pizza', flavour: 'Pepperoni'})
CREATE (m1:Comestible {name: 'Milkshake', flavour: 'Strawberry'})
CREATE (p2:Comestible {name: 'Hamburger'})
CREATE (m2:Comestible {name: 'Cola'})
CREATE (u1)-[:lives_in]->(b1)
CREATE (u1)-[:likes]->(p1)
CREATE (u1)-[:likes]->(m1)
CREATE (u2)-[:lives_in]->(b2)
CREATE (u2)-[:likes]->(p2)
CREATE (u2)-[:likes]->(m2)
CREATE (u3)-[:lives_in]->(b2)
CREATE (u3)-[:likes]->(p1)
CREATE (u3)-[:likes]->(m2)
RETURN true
$$) as (id ag_catalog.agtype);
SET search_path = ag_catalog, "$user", public;
```
## Query
Below is an illustrative query.
```
SELECT * FROM ag_catalog.cypher('nesteddemo', $$
MATCH (b:Building)<-[:lives_in]-(u:User)-[:likes]->(c:Comestible)
WITH {name: u.name, favouriteFoods: COLLECT(c)} AS person, u, b
RETURN b.name, COLLECT([person]) AS people
$$) as (building ag_catalog.agtype, userdata ag_catalog.agtype);
```
A couple of things to note:
- The derived object (`person`) needs to be wrapped in an array in order to be `COLLECT`ed
- The value of `favourites` in the result `userdata` is an array of arrays
Besides the slight inconvenience of having nested arrays, no real issue so far. All the data is returned.
However, when the above query is run via `pg` using the NodeJS AGE driver, `userdata`'s top level array _only contains one array_ where it should contain two. The result row for `Building Two` **should** contain `User Two` and `User Three`, but it only contains `User Three`.
This _seems_ to me like a bug, but I'm not sure if I'm doing something wrong. If so, I'm hoping one of you can point me in the right direction. This is a significant hindrance at the moment. The actual query that's producing the described result worked well in RedisGraph and (I think) Neo4J.
Please let me know your thoughts.
Contributor guide
Assessment
This issue has not been assessed yet.