Moving all edges from one vertex to another

Hi Team,
I am trying to move all edges(with attributes on them) of a vertex to another. For example, lets consider Master vertex(M1) and Slave Vertices (S1, S2, S3).
S1 - e1(a1,a2) -T1
Above is an edge(e1) between S1 and T1 with edge attribute a1,a2.
S2-e1(a1,a2)-T2
s2-e2(b1,b2)-T3
S3-e3-T3 (no attribute on edge e3)

I want to move all these edges to Master Vertex M1 such that
M1 - e1(a1,a2) -T1
M1-e1(a1,a2)-T2
M1-e2(b1,b2)-T3
M1-e3-T3 (no attribute on edge e3)
Here I have replaced all Slave vertices with Master Vertex. In other words, source vertices have been replaced while the edges(with attributes) and target vertices remain same.

I saw Webinar: The Power of Graph Analytics for Performing Entity Resolution and there was a query named “user_grouping” which is exactly what I am trying to do.
However I am having some hard time forming this query. Could you please help me with it?
Also, is it possible to download the schema file of this webinar from somewhere? I can see there are many useful webinars that tigergraph has created but I am unable to find their corresponding schema files anywhere on github.

Thanks,
Mohit

Hello,

The query “user_grouping” that you describe is actually available in the Cloud Starter Kits. It exists under “In-Database Machine Learning for Big Data Entity Resolution v3.1.1”, which is the second entity resolution preset.

The functionality that you are looking for lies in the “INSERT INTO” statement (https://docs.tigergraph.com/dev/gsql-ref/querying/data-modification-statements)

Here is a query (and schema) that I wrote which fulfills your requirements. Note that you will need separate edge types (S_to_T) and (M_to_T) to transfer information between. You will also need a separate SELECT statement that filters down to a single Master (to map all these new edges onto).

CREATE vertex Master (
    PRIMARY_ID id INT,
    masterID INT
)

CREATE vertex Slave (
    PRIMARY_ID id INT
)

CREATE vertex T_vertex (
    PRIMARY_ID id INT
)

CREATE undirected edge S_to_T (FROM Slave, TO T_vertex, a1 INT, a2 INT)
CREATE undirected edge M_to_T (FROM Master, TO T_vertex, a1 INT, a2 INT)

CREATE GRAPH forumPost (*)
USE GRAPH forumPost


CREATE QUERY swap(INT targetMasterID) {
    VERTEX<Master> M1;
    
    start = {Master.*};
    findM1 = SELECT s
             FROM start:s
             WHERE s.masterID == targetMasterID
             ACCUM M1 = s;

    start = {Slave.*};
    T_vertices = SELECT t
                 FROM start:s - (_:e) -> T_vertex:t
                 ACCUM
                    INSERT INTO M_to_T VALUES (M1,t,e.a1,e.a2),
                    DELETE (e);
}
2 Likes

Hi @Ishestakov,
Thanks for creating query. In my case, both Slave and Master vertices are of same type “Profile”, thus separate edges (S_to_T) and (M_to_T) are not possible. Instead, I’ve a common edge, for e.g., (P_to_T). However, the starter kit information that you shared, it helped me a lot in solving this problem. I was able to move past it, all thanks to you!

Regards,
Mohit

2 Likes