age icon indicating copy to clipboard operation
age copied to clipboard

If an alias is not specified, the count result is incorrect.

Open beamrock opened this issue 1 year ago • 7 comments

Describe the bug If an alias is not specified, the count result is incorrect.

How are you accessing AGE (Command line, driver, etc.)?

  • anywhere. I did in Command line.

What data setup do we need to do?

SELECT * from cypher('movie_graph', $$
CREATE (a:Part {part_num: '123'}), 
       (b:Part {part_num: '345'}), 
       (c:Part {part_num: '456'}), 
       (d:Part {part_num: '789'})
$$) as (a agtype);
moviedb=# SELECT * from cypher('movie_graph', $$ match (a:Part) return a $$) as (result agtype);
                                        result                                        
--------------------------------------------------------------------------------------
 {"id": 1125899906842625, "label": "Part", "properties": {"part_num": "123"}}::vertex
 {"id": 1125899906842626, "label": "Part", "properties": {"part_num": "345"}}::vertex
 {"id": 1125899906842627, "label": "Part", "properties": {"part_num": "456"}}::vertex
 {"id": 1125899906842628, "label": "Part", "properties": {"part_num": "789"}}::vertex
(4 rows)

What is the command that caused the error?

When an alias is not specified

moviedb=# SELECT * from cypher('movie_graph', $$ match (:Part) return count(*) $$) as (result agtype);   
 result 
--------
 1  <-------- incorrect count result
(1 row)

When an alias and a label is specified

moviedb=# SELECT * from cypher('movie_graph', $$ match (a:Part) return count(*) $$) as (result agtype); 
 result 
--------
 4
(1 row)

When only an alias is specified

moviedb=# SELECT * from cypher('movie_graph', $$ match (a) return count(*) $$) as (result agtype);     
 result 
--------
 4
(1 row)

Expected behavior

Same as agensgraph or neo4j

On Neo4j

neo4j@ldbcgraph> match (:Part) return count(*) ;
+----------+
| count(*) |
+----------+
| 4        |
+----------+

On AgensGraph

sampledb=# match (:Part) return count(*) ;
 count 
-------
 4

Additional context

Just so you know, agensgraph and neo4j give accurate results.

beamrock avatar May 24 '23 06:05 beamrock

I encountered a similar problem and decided to seek assistance on Stack Overflow. I suggest exploring the various solutions provided there to address the issue. https://stackoverflow.com/questions/76327413/ambiguous-count-results-in-apache-agedb-cypher-query-when-alias-is-not-defined

AbdulSamad4068 avatar May 26 '23 10:05 AbdulSamad4068

This is something that needs to be fixed.

jrgemignani avatar Jun 06 '23 17:06 jrgemignani

Verified this is still an issue -

psql-15.4-5432-pgsql=# SELECT create_graph('movie_graph');
NOTICE:  graph "movie_graph" has been created
 create_graph
--------------

(1 row)

psql-15.4-5432-pgsql=# SELECT * from cypher('movie_graph', $$
psql-15.4-5432-pgsql$# CREATE (a:Part {part_num: '123'}),
psql-15.4-5432-pgsql$#        (b:Part {part_num: '345'}),
psql-15.4-5432-pgsql$#        (c:Part {part_num: '456'}),
psql-15.4-5432-pgsql$#        (d:Part {part_num: '789'})
psql-15.4-5432-pgsql$# $$) as (a agtype);
 a
---
(0 rows)

psql-15.4-5432-pgsql=# SELECT * from cypher('movie_graph', $$ match (a:Part) return a $$) as (result agtype);
                                       result
-------------------------------------------------------------------------------------
 {"id": 844424930131969, "label": "Part", "properties": {"part_num": "123"}}::vertex
 {"id": 844424930131970, "label": "Part", "properties": {"part_num": "345"}}::vertex
 {"id": 844424930131971, "label": "Part", "properties": {"part_num": "456"}}::vertex
 {"id": 844424930131972, "label": "Part", "properties": {"part_num": "789"}}::vertex
(4 rows)

psql-15.4-5432-pgsql=# SELECT * from cypher('movie_graph', $$ match (:Part) return count(*) $$) as (result agtype);
 result
--------
 1
(1 row)

psql-15.4-5432-pgsql=# SELECT * from cypher('movie_graph', $$ match (a:Part) return count(*) $$) as (result agtype);
 result
--------
 4
(1 row)

psql-15.4-5432-pgsql=#

jrgemignani avatar Oct 21 '23 00:10 jrgemignani

I will look at this.

jrgemignani avatar Oct 23 '23 18:10 jrgemignani

I will have a PR for this tomorrow.

jrgemignani avatar Oct 24 '23 00:10 jrgemignani

PR #1288 has been created to address this.

jrgemignani avatar Oct 24 '23 17:10 jrgemignani

@beamrock This has been corrected in the master branch.

jrgemignani avatar Oct 27 '23 19:10 jrgemignani

This issue is stale because it has been open 45 days with no activity. Remove "Abondoned" label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 11 '24 00:05 github-actions[bot]

Closing this as it was resolved by PR #1288

MuhammadTahaNaveed avatar May 11 '24 11:05 MuhammadTahaNaveed