RLx
RLx

Reputation: 57

OrientDb: graph visualization via function?

Following is the use case: We would like to open OrientDB visualization tool to our business users; this way, they can query the data themselves. We thought, that it would be nice to create predefined functions with embedded queries to hide the complexity of the data model.

Here are generic examples:

Example 1: SearchCity (parameter: city name) Example 2: SearchProvince (parameter: province name) and show all the countries connected and cities related to that province

Issue: Unfortunately, visualization tool is only displaying @rid in a single circle but not as a linked objects.

Question: Is it possible to create a function, which users can call via SELECT from the Graph Visualization tool and show all the branches?

Orientdb version: 2.2 rc1

Below is my test data:

Data:

CREATE CLASS xCOUNTRY EXTENDS V;
CREATE CLASS xPROVINCE EXTENDS V;
CREATE CLASS xCITY EXTENDS V;
CREATE CLASS part_of EXTENDS E;
CREATE VERTEX xCOUNTRY  SET  COUNTRY_ID=1,COUNTRY_NAME='CANADA';
CREATE VERTEX xPROVINCE SET  PROVINCE_ID=1.1,PROVINCE_NAME='ONTARIO',COUNTRY_ID=1;
CREATE VERTEX xCITY SET  CITY_ID=1.11,CITY_NAME='TORONTO',PROVINCE_ID=1.1;
CREATE VERTEX xCITY SET  CITY_ID=1.12,CITY_NAME='OTTAWA',PROVINCE_ID=1.1;
CREATE EDGE part_of from (select from xCOUNTRY Where COUNTRY_ID =1) to (select from xPROVINCE Where COUNTRY_ID=1);
CREATE EDGE part_of from (select from xPROVINCE Where PROVINCE_ID =1.1) to (select from xCITY Where PROVINCE_ID=1.1);

Function:

Name: SearchProvince (parameter "prov_name")

var db = orient.getGraph(); var x = db.command('sql',"TRAVERSE BOTH()
FROM (SELECT FROM XPROVINCE WHERE PROVINCE_NAME= '"+ prov_name + "')
LIMIT 20"); return x;

Upvotes: 0

Views: 149

Answers (1)

Ivan Mainetti
Ivan Mainetti

Reputation: 1982

you need to use expand

in graph editor call like this:

select expand(SearchProvince("ONTARIO"))

Ivan

Upvotes: 1

Related Questions