orientechnologies / orientjs

The official fast, lightweight node.js client for OrientDB
http://orientdb.com
Other
327 stars 67 forks source link

How to interpret query results. #422

Closed Davenporten closed 4 years ago

Davenporten commented 4 years ago

I put this on Stack Overflow, but figured it might be better to ask here:

I'm creating an interactive graph in my web page by querying my OrientDB instance using Orientjs then pulling out the needed data from the query and passing it to cytoscape.js. I'm able to get data down from the OrientDB instance and graph it, but I realized that the result of running a query in OrientDB Studio is different than when I run the query through Orientjs. In Studio I get 20 nodes with 67 edges from the query. When I run the same query through Orientjs I get 65 individual objects back. Originally I thought each object represented a node and the 'in_links'/'out_links' were the edges. However, this obviously isn't the case.

So I figure it is 1 of 3 problems:

  1. Orientjs just isn't working and is giving me back bad data (I think and hope this is unlikely).
  2. I am somehow running the query on two different instances of OrientDB (I'm pretty sure this is impossible).
  3. I am not interpreting the query results from Orientjs correctly and therefore not feeding them into cytoscape.js correctly (I think this is most likely the problem).

Here are a few examples of the objects I'm getting back from my query:

{ "@class": "", "@type": "d", "Cluster_ID": 8, "@rid": "#25:5", "@version": 1 }, { "@class": "", "@type": "d", "out_links": [ "#33:65", "#34:65", "#35:65", "#36:65", "#33:67", "#34:67", "#35:67", "#36:67", "#33:69", "#34:69", "#35:69", "#36:69", "#33:71", "#34:71", "#35:71", "#36:71", "#36:127", "#37:126", "#38:126", "#39:126", "#40:126", "#37:130", "#38:129", "#39:129", "#40:129", "#33:130", "#38:133", "#39:132", "#40:132", "#33:133", "#34:133", "#39:136", "#40:135", "#33:136", "#34:136", "#35:136" ], "Cluster_ID": 0, "@rid": "#25:6", "@version": 9 }, { "@class": "", "@type": "d", "Cluster_ID": 8, "@rid": "#25:7", "@version": 1 }, { "@class": "", "@type": "d", "out_links": [ "#36:112", "#37:112", "#38:112", "#39:112", "#40:111", "#37:115", "#38:115", "#39:115", "#40:115", "#33:115" ], "in_links": [ "#38:95", "#35:94", "#40:94", "#37:93", "#34:93", "#33:105", "#38:103", "#35:104", "#40:102", "#37:102" ], "Cluster_ID": 3, "@rid": "#25:8", "@version": 5 }

Like I mentioned I thought each of these represented a node and the in/out_links were the edges. Is this correct? Or is there something I'm missing in interpreting the query results?

Thanks for all the help in advance.

luigidellaquila commented 4 years ago

Hi @Davenporten

The difference could be due to the fact that Studio by default adds a LIMIT 20 to the queries (where a limit is not explicitly set in the query).

Thanks

Luigi

Davenporten commented 4 years ago

Thanks @luigidellaquila for getting back to me.

I didn't realize there was that implicit limit, but that definitely makes sense in accounting for the discrepancy. Is my interpretation of the objects correct then? Each object being a node and the in/out_links being the edges? How should the in/out_links be interpreted? It seems like it is not as simple as an in/out_link goes to another node in the query.

Thanks again!

luigidellaquila commented 4 years ago

Hi @Davenporten

That's correct, each record is a vertex and the in/out are pointers to the edges, that are documents as well

Thanks

Luigi

Davenporten commented 4 years ago

So would I know if two vertices are connected by looking at the in_links of one and the out_links of another? Meaning, if there is the same ID in the in_link of one vertex and the out_link of another vertex, those two vertices are connected by that edge?

Again, thanks so much for your help!

luigidellaquila commented 4 years ago

Exactly ;-) out are outgoing edges, in are incoming edges, the same RID means the same edge

Davenporten commented 4 years ago

Your help has been much appreciated @luigidellaquila, really thanks!