I am new to Graph DBs in general and trying to learn Gremlin QL. I was wondering if there is a way to directly merge two immediate neighbors of two vertices who ids are known. For example, in the below graph
I don't want to traverse the entire graph, I just want the two subgraphs to merge based on their common neighbors and sort based on the sum of the weights of the two edges leading to the same Vertex.
In the above graph, I want to be able to display the vertices A, B, C, D
when I query with the vertices 1 and 2
. I want to be able to merge the outE of vertex 1 and vertex 2, aggregate the weights of (edge 1 -> A and Edge 2 -> A), (edge 1 -> B and Edge 2 -> B), (edge 1 -> C and Edge 2 -> C) and (edge 1 -> D and Edge 2 -> D) and sort the result based on this combined score.
The code for the graph creation is below
g.addV().property('id',1).property("type","A").as('1')
addV().property('id',2).property("type","B").as('2').
addV().property('id',A).property("type","X").as('A').
addV().property('id',B).property("type","X").as('B').
addV().property('id',C).property("type","X").as('C').
addV().property('id',D).property("type","X").as('D').
addE('connects').from('1').to('A').property("weight",0.1d)
addE('connects').from('1').to('B').property("weight",0.4d)
addE('connects').from('1').to('C').property("weight",0.2d)
addE('connects').from('1').to('D').property("weight",0.7d)
addE('connects').from('2').to('A').property("weight",0.5d)
addE('connects').from('2').to('B').property("weight",0.2d)
addE('connects').from('2').to('C').property("weight",0.7d)
addE('connects').from('2').to('D').property("weight",0.4d).iterate()
If I were to represent the above data in an SQL, a sample model is as below
create table items(id varchar(20), toId varchar(20), weight double(5,4), primary key (id, toId);
insert into items values("1","A",0.1);
insert into items values("1","B",0.4);
insert into items values("1","C",0.2);
insert into items values("1","D",0.7);
insert into items values("2","A",0.5);
insert into items values("2","B",0.2);
insert into items values("2","C",0.7);
insert into items values("2","D",0.4);
select toId, a.weight+b.weight as weight from items a, items b where a.id = "1" and b.id = "2" and a.toId = b.toId order by weight desc;
This typically returns
D, 0.11
C, 0.9
B, 0.6
A, 0.5
Any help in this is highly appreciated.