age icon indicating copy to clipboard operation
age copied to clipboard

Suggest new function for finding the shortest path

Open Leelst opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe.

Neo4j and AgensGraph provide various analytical features for graph analysis, and one of them is the 'shortestPath', 'allShortestPaths' functionality. If this feature is added to AGE as well, it would be useful for performing analysis tasks.

Opencypher document also provides the function 'Shotestpath' and 'allShortestPaths'. (LINK) (p.67 Shortest Path, All Shortest Paths)

  • shortestPath
# AGE (Work? N)

SELECT * FROM cypher('ldbc_graph', $$MATCH (v:person {lastname: 'Beran'}), (v2:person {lastname: 'Jones'}), p = shortestPath((v)-[knows*..15]-(v2)) RETURN p LIMIT 1 $$) AS (v agtype);

ERROR:  syntax error at or near "shortestPath"
LINE 1: ...: 'Beran'}), (v2:person {lastname: 'Jones'}), p = shortestPa...
                                                             ^
  • allShortestPath
# AGE (Work? N)

SELECT * FROM cypher('ldbc_graph', $$MATCH (v:person {lastname: 'Beran'}), (v2:person {lastname: 'Jones'}), p = allshortestPaths((v)-[knows*..15]-(v2)) RETURN p LIMIT 1 $$) AS (v agtype);

ERROR:  syntax error at or near "allshortestPaths"
LINE 1: ...: 'Beran'}), (v2:person {lastname: 'Jones'}), p = allshortes...
                                                             ^

Describe the solution you'd like

  • shortestPath
# Neo4j (Work? Y) 

MATCH (v:Person {lastName: 'Beran'}), (v2:Person {lastName: 'Jones'}), p=shortestPath((v)-[Knows*..15]-(v2)) RETURN v LIMIT 1;

+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| v                                                                                                                                                                                                                                                            |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| (:Person {birthday: "1989-09-26", lastName: "Beran", firstName: "Jan", gender: "male", speaks: "en", browserUsed: "Chrome", locationIP: "204.79.184.190", id: 10995116285325, creationDate: 2010-12-21T18:46:43.694Z, email: "[email protected]"}) |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row
# AgensGraph (Work? Y)

MATCH (v:person {lastname: 'Beran'}), (v2:person {lastname: 'Jones'}), p = shortestPath((v)-[knows*..15]-(v2)) RETURN p LIMIT 1;

                                                                                               p

--------------------------------------------------------------------------------------------------------------------------------------------------- [person[6.39]{"id": 10995116285325, "gender": "male", "birthday": "1989-09-26T00:00:00", "lastname": "Beran", "firstname": "Jan", "locationip": "204.79.184.1
90", "browserused": "Chrome", "creationdate": "2010-12-21T18:46:43.694"},hasinterest[14.116638][6.39,9.2824]{},tag[9.2824]{"id": 2823, "url": "http://dbpedia.
org/resource/Mark_Twain", "name": "Mark_Twain"},hastagcomment[18.1075296][3.813479,9.2824]{},comment[3.813479]{"id": 1924147914993, "length": 113, "content":
"About Mark Twain, tures, in particular the Paige ComposiAbout The Dark Side of the Moon,  and was premiered sever", "locationip": "27.154.53.109", "browserus
ed": "Internet Explorer", "creationdate": "2012-06-03T20:47:50.037"},likescomment[29.529274][6.28,3.813479]{"creationDate": "2012-06-03T21:47:23.679"},person[
6.28]{"id": 8796093025593, "gender": "female", "birthday": "1985-07-08T00:00:00", "lastname": "Jones", "firstname": "Michael", "locationip": "46.16.162.142",
"browserused": "Opera", "creationdate": "2010-09-05T04:22:38.487"}]
(1 row)


  • allShortestPath
# Neo4j (Work? Y) 

MATCH (v:Person {lastName: 'Beran'}), (v2:Person {lastName: 'Jones'}), p=allShortestPaths((v)-[Knows*..15]-(v2)) RETURN v LIMIT 1;

+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| v                                                                                                                                                                                                                                                            |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| (:Person {birthday: "1989-09-26", lastName: "Beran", firstName: "Jan", gender: "male", speaks: "en", browserUsed: "Chrome", locationIP: "204.79.184.190", id: 10995116285325, creationDate: 2010-12-21T18:46:43.694Z, email: "[email protected]"}) |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row

# AgensGraph (Work? Y)

MATCH (v:person {lastname: 'Beran'}), (v2:person {lastname: 'Jones'}), p = allshortestPaths((v)-[knows*..15]-(v2)) RETURN p LIMIT 1;

                                                                                               p

--------------------------------------------------------------------------------------------------------------------------------------------------- 
 [person[6.39]{"id": 10995116285325, "gender": "male", "birthday": "1989-09-26T00:00:00", "lastname": "Beran", "firstname": "Jan", "locationip": "204.79.184.1
90", "browserused": "Chrome", "creationdate": "2010-12-21T18:46:43.694"},hasinterest[14.116638][6.39,9.2824]{},tag[9.2824]{"id": 2823, "url": "http://dbpedia.
org/resource/Mark_Twain", "name": "Mark_Twain"},hastagcomment[18.1075296][3.813479,9.2824]{},comment[3.813479]{"id": 1924147914993, "length": 113, "content":
"About Mark Twain, tures, in particular the Paige ComposiAbout The Dark Side of the Moon,  and was premiered sever", "locationip": "27.154.53.109", "browserus
ed": "Internet Explorer", "creationdate": "2012-06-03T20:47:50.037"},likescomment[29.529274][6.28,3.813479]{"creationDate": "2012-06-03T21:47:23.679"},person[
6.28]{"id": 8796093025593, "gender": "female", "birthday": "1985-07-08T00:00:00", "lastname": "Jones", "firstname": "Michael", "locationip": "46.16.162.142",
"browserused": "Opera", "creationdate": "2010-09-05T04:22:38.487"}]
(1 row)

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

Leelst avatar May 25 '23 01:05 Leelst