Search code examples
orientdbcytoscape.jsorientjs

How to interpret orientjs query result?


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": "<class_name>",
    "@type": "d",
    "Cluster_ID": 8,
    "@rid": "#25:5",
    "@version": 1
},
{
    "@class": "<class_name>",
    "@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": "<class_name>",
    "@type": "d",
    "Cluster_ID": 8,
    "@rid": "#25:7",
    "@version": 1
},
{
    "@class": "<class_name>",
    "@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?


Solution

  • After some help from the people at Orientjs's GitHub (see here) I've got the answer.

    When running a query on OrientDB studio there is an implicit LIMIT 20 added to each query unless there is a limit specified. I went back and specified a limit of 100 and sure enough I had the same number of nodes being rendered as there were objects from the Orientjs query. From there is confirmed the number of edges. So the above description of what the result of a Orientjs query means is correct: each object is a node and the in/out_links are the edges. The key to the edges is that 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.