Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node Label is recognized as Edge Label #111

Open
MatheusFarias03 opened this issue Jan 18, 2023 · 13 comments
Open

Node Label is recognized as Edge Label #111

MatheusFarias03 opened this issue Jan 18, 2023 · 13 comments
Labels
bug Something isn't working

Comments

@MatheusFarias03
Copy link

MatheusFarias03 commented Jan 18, 2023

Bug Description

I've created a graph to replicate the Goodreads website, where you can keep track of your current readings and give ratings to books. The graph's name is "goodreads_db" and the vertices can be of the following labels: "Book", "Author", and "User". When I open AGE Viewer, only "*" and "User" are available on the "Node Label" panel, both "Book" and "Author" appear on the "Edge Label" panel (which are wrongly put since both of them belong to "Node Label").

image

Furthermore, when I click on the "Book(11)" or "Author(5)" button, it creates a query but it places the "Book" label as an edge label:

image

Here is an example of how I'm adding these "Book" vertices:

SELECT * FROM cypher ('goodreads_db', $$
CREATE (a :Book {title: "The Hobbit", author: "J.R.R. Tolkien", pages: 336, rating: 4.28, ratings: 3577180, reviews: 61452, series: "The Lord of the Rings"}) 
RETURN a 
$$) as (a agtype);   

Expected behavior

The "Book" and "Author" label should be placed under "Node Label", so that when I click it, it would create a query like this:

SELECT * from cypher('goodreads_db', $$
        MATCH (V:Book)
        RETURN V
$$) as (V agtype);

When I type this query manually, the right behavior is shown:

image

@MatheusFarias03 MatheusFarias03 added the bug Something isn't working label Jan 18, 2023
@MJinH
Copy link
Contributor

MJinH commented Jan 18, 2023

When I run the query that you provided, it is placed correctly under node label. Could you make sure if you've cloned from main branch or share the order of query execution?

@MatheusFarias03
Copy link
Author

MatheusFarias03 commented Jan 18, 2023

Sure! When I type git status on the terminal, it shows that I'm on the main branch:

git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

Now, how I am executing the query.

First, I created the graph:

SELECT * FROM ag_catalog.create_graph('goodreads_db');

Then I created a "User" vertex:

SELECT * FROM cypher ('goodreads_db', $$                                                     
CREATE (a :User {first_name: 'Matheus', last_name: 'Matsumoto', country: 'Brazil', read: 9, reading:2 }) RETURN a                                                                                      
$$) as (a agtype);

I also created a "Book" vertex:

SELECT * FROM cypher ('goodreads_db', $$                                                     
CREATE (a :Book {title: 'To Kill a Mockingbird', author: 'Harper Lee', rating: 4.27, pages: 336, language: 'English', ratings: 5574002, reviews: 107847}) 
RETURN a                                      
$$) as (a agtype);

And after this, I created an edge between "User" and "Book" with a "READ" label:

SELECT * FROM cypher ('goodreads_db', $$                                                     
MATCH (a :User), (b :Book)                                                                          
WHERE a.first_name = 'Matheus' AND b.title = 'To Kill a Mockingbird'                                
CREATE (a)-[e:READ {rating: 4}]->(b)                                                                
RETURN e                                                                                            
$$) as (e agtype);

So I kept doing it like this, also adding the vertices with "Author" label and adding the edge with "AUTHOR_OF" label between them. Now I have about 17 nodes and 22 edges. I went to where I installed AGE Viewer and executed the npm run setup and npm run start commands to use AGE Viewer.

@MJinH
Copy link
Contributor

MJinH commented Jan 18, 2023

Thank you for providing it. I keep running the queries in the provided order above and it seems that I get the correct result.
Screenshot (125)

I'd just like to make sure if you run these queries using query editor in viewer app. If not, could you tell me how you run these queries (ex: using pgadmin, cmd) so that I can see if I get the same bug?

@MatheusFarias03
Copy link
Author

MatheusFarias03 commented Jan 18, 2023

I did the addition of vertices and edges with the terminal app. Then, just to visualize the graph, I went to AGE Viewer. I believe that some nodes may have been added whilst AGE Viewer was running, but I added them via terminal. I do not know if this affects this behavior or not.

So, I open the Terminal App, go to the postgres directory, and then I type:

% bin/pg_ctl -D demo -l logfile start

waiting for server to start.... done
server started

% bin/psql demo

psql (11.17)
Type "help" for help.

demo=#

And then I start using AGE to create the graph, nodes, and edges.

@MatheusFarias03
Copy link
Author

Oh and I forgot to add that I'm using:

  • MacOS Ventura 13.1
  • Safari browser

@marodins
Copy link
Contributor

marodins commented Jan 18, 2023

@MatheusFarias03 This might be specific to postgres version 11 as there's two separate queries for metadata. The query that is executed depends on the connected pg version. Do you experience the same issue when using postgres version 12?

@MatheusFarias03
Copy link
Author

I did not try it with postgres version 12.

@MJinH
Copy link
Contributor

MJinH commented Jan 18, 2023

I'm also using postgres version 11 and I get the correct result. This is the data output from query for the version 11 metadata.
Screenshot (126)

I've looked at the backend code and I believe it determines vertices and edges based on kind column. I think each rows from the data output represents whether label is vertex or edge properly. So I'm curious how this issue occurred if it is caused by the version of postgres.

@MatheusFarias03
Copy link
Author

I was looking at other issues and this bug actually happened here : #77 , but someone there said that also had the same bug at #71 and that #75 should fix the bug, but it occurred again here.

@MJinH
Copy link
Contributor

MJinH commented Jan 18, 2023

If possible, could you run this query in your terminal and share the output result?

SELECT * FROM (
        SELECT c.relname AS label, n.oid as namespace_id, c.reltuples AS cnt
        FROM pg_catalog.pg_class c
        JOIN pg_catalog.pg_namespace n
        ON n.oid = c.relnamespace
        WHERE c.relkind = 'r'
        AND n.nspname = 'goodreads_db'
) as q1
JOIN ag_graph as g ON q1.namespace_id = g.namespace
INNER JOIN ag_label as label
ON label.name = q1.label
AND label.graph = g.oid;

Thank you

@MatheusFarias03
Copy link
Author

Running the query it outputs this:

       label       | namespace_id | cnt |     name     |  namespace   |       name        | graph | id | kind |             relation             
-------------------+--------------+-----+--------------+--------------+-------------------+-------+----+------+----------------------------------
 AUTHOR_OF         |        17439 |  13 | goodreads_db | goodreads_db | AUTHOR_OF         | 17442 |  7 | e    | goodreads_db."AUTHOR_OF"
 Author            |        17439 |   5 | goodreads_db | goodreads_db | Author            | 17442 |  6 | v    | goodreads_db."Author"
 Book              |        17439 |  13 | goodreads_db | goodreads_db | Book              | 17442 |  4 | v    | goodreads_db."Book"
 CURRENTLY_READING |        17439 |   2 | goodreads_db | goodreads_db | CURRENTLY_READING | 17442 |  8 | e    | goodreads_db."CURRENTLY_READING"
 READ              |        17439 |   9 | goodreads_db | goodreads_db | READ              | 17442 |  5 | e    | goodreads_db."READ"
 User              |        17439 |   1 | goodreads_db | goodreads_db | User              | 17442 |  3 | v    | goodreads_db."User"
 _ag_label_edge    |        17439 |   0 | goodreads_db | goodreads_db | _ag_label_edge    | 17442 |  2 | e    | goodreads_db._ag_label_edge
 _ag_label_vertex  |        17439 |   0 | goodreads_db | goodreads_db | _ag_label_vertex  | 17442 |  1 | v    | goodreads_db._ag_label_vertex
(8 rows)

@MJinH
Copy link
Contributor

MJinH commented Jan 19, 2023

The result looks correct to me and now I have about 80nodes and 100 more edges, but I still get the correct result. I've tested with both pg version 11 and 12 on window and ubuntu environment and worked fine. I think there might be some other factor that trigger vertices turning into edges but it's difficult for me to find out the bug at this moment. I'd suggest you to do the following.

  1. use postgres version 12 as marodins suggested and see if the same bug still occurs.
  2. remove the current graph and start over. but this time, see the result right after running a query to know exactly at what point the bug occurs. (ex: create a node, and go to viewer app to see if a node is placed in the correct position, then edge and so on).

Thank you for reporting this bug and I'm sorry I couldn't be more helpful.

@MatheusFarias03
Copy link
Author

No worries! I'll try it again with postgres version 12 and write here if I stumble on any bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants