OrientDB Example

MdsTab与MdsTabCol分别是2种V

Tab与Tab之前的数据流向关系使用TabDataFlow连接

TabCol与TabCol之前的数据流向关系使用TabColDataFlow连接

类型图

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/7417e0e1-4bfc-458d-9355-e7711500b109/Screen_Shot_2021-03-24_at_1.59.26_PM.png

测试数据

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d0e3b837-d12b-439b-a660-f085617f25bb/Screen_Shot_2021-03-24_at_2.01.41_PM.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# clear Data 

delete vertex MdsTab;
delete vertex MdsTabCol;
drop class MdsTab;
drop class MdsTabCol;
delete edge TabDataFlow;
delete edge TabColDataFlow;
drop class TabDataFlow;
drop class TabColDataFlow;

# create Class
Create class MdsTab extends V;
Create property MdsTab.id Long (NotNull);
Create property MdsTab.name String;
Create property MdsTab.tenantId Long (NotNull);
Create index MdsTab.id ON MdsTab (id) UNIQUE;

Create class MdsTabCol extends V;
Create property MdsTabCol.id Long (NotNull);
Create property MdsTabCol.name String;
Create property MdsTabCol.tabId Long (NotNull);
Create property MdsTabCol.tenantId Long (NotNull);
Create index MdsTabCol.id ON MdsTabCol (id) UNIQUE;

Create class TabDataFlow extends E;
Create property TabDataFlow.in LINK MdsTab;
Create property TabDataFlow.out LINK MdsTab;
Create index TabDataFlow.in_out ON TabDataFlow(in,out) UNIQUE;

Create class TabColDataFlow extends E;
Create property TabColDataFlow.in LINK MdsTabCol;
Create property TabColDataFlow.out LINK MdsTabCol;
Create index TabColDataFlow.in_out ON TabColDataFlow(in,out) UNIQUE;

# insert data

insert into `MdsTab` (id, tenantId, name) values (1,10000,'table1'), (2,10000,'table2'), (3,10000,'table3'), (4,10000,'table4'), (5,10000,'table5'), (6,10000,'table6'), (7,10000,'table7'), (8,10000,'table8'), (9,10000,'table9');
insert into `MdsTabCol` (id, tabId, tenantId, name) values (11, 1, 10000, 'col11'), (12, 1, 10000, 'col12'), (21, 2, 10000, 'col21'), (22, 2, 10000, 'col22'), (31, 3, 10000, 'col31'), (32, 3, 10000, 'col32'), (41, 4, 10000, 'col41'), (42, 4, 10000, 'col42'), (51, 5, 10000, 'col51'), (52, 5, 10000, 'col52'), (61, 6, 10000, 'col61'), (62, 6, 10000, 'col62'), (71, 7, 10000, 'col71'), (72, 7, 10000, 'col72'), (81, 8, 10000, 'col81'), (82, 8, 10000, 'col82'), (91, 9, 10000, 'col91'), (92, 9, 10000, 'col92');

CREATE EDGE TabDataFlow FROM (select from MdsTab where id = '1') TO (select from MdsTab where id = '2');
CREATE EDGE TabDataFlow FROM (select from MdsTab where id = '1') TO (select from MdsTab where id = '7');

CREATE EDGE TabDataFlow FROM (select from MdsTab where id = '2') TO (select from MdsTab where id = '3');
CREATE EDGE TabDataFlow FROM (select from MdsTab where id = '2') TO (select from MdsTab where id = '8');

CREATE EDGE TabDataFlow FROM (select from MdsTab where id = '3') TO (select from MdsTab where id = '4');
CREATE EDGE TabDataFlow FROM (select from MdsTab where id = '8') TO (select from MdsTab where id = '9');

CREATE EDGE TabDataFlow FROM (select from MdsTab where id = '4') TO (select from MdsTab where id = '5');
CREATE EDGE TabDataFlow FROM (select from MdsTab where id = '5') TO (select from MdsTab where id = '6');

CREATE EDGE TabColDataFlow FROM (select from MdsTabCol where id = '11') TO (select from MdsTabCol where id = '21');
CREATE EDGE TabColDataFlow FROM (select from MdsTabCol where id = '11') TO (select from MdsTabCol where id = '71');

CREATE EDGE TabColDataFlow FROM (select from MdsTabCol where id = '21') TO (select from MdsTabCol where id = '31');
CREATE EDGE TabColDataFlow FROM (select from MdsTabCol where id = '22') TO (select from MdsTabCol where id = '82');

CREATE EDGE TabColDataFlow FROM (select from MdsTabCol where id = '31') TO (select from MdsTabCol where id = '41');
CREATE EDGE TabColDataFlow FROM (select from MdsTabCol where id = '82') TO (select from MdsTabCol where id = '92');

CREATE EDGE TabColDataFlow FROM (select from MdsTabCol where id = '41') TO (select from MdsTabCol where id = '51');
CREATE EDGE TabColDataFlow FROM (select from MdsTabCol where id = '51') TO (select from MdsTabCol where id = '61');

查询

使用 traverse 查询MdsTab id为1最大深度3层关系

1
TRAVERSE out("TabDataFlow") FROM (select from MdsTab where id =1) maxDepth 3

查询MdsTabCol id为11的关系

1
TRAVERSE out("TabColDataFlow") FROM (select from MdsTabCol where id =11) maxDepth 2