Is there a way to write a schema-less query (so that the modification is done in one transaction) for a “set” (i.e., group, collection) of vertices and edges?
E.g., to delete one set of vertices it is trivial:
CREATE QUERY deleteVertices(STRING vType, SET<STRING> vertices) FOR GRAPH TestHierarchicalData2 {
SetAccum<VERTEX> @@set;
@@set += to_vertex_set(vertices, vType);
Start = @@set;
Result = SELECT s FROM Start:s POST-ACCUM DELETE (s);
PRINT Result;
}
How to generalize the parameters to delete arbitrary number of sets of vertices (each of different type)? How to parameterize the edges?
Here is a query which can delete up to 3 kinds of vertices and edges in one call. This can be expanded upon to delete graph components in even larger batches.
CREATE QUERY deletion(STRING vType1, STRING vType2, STRING vType3, STRING eType1, STRING eType2, STRING eType3) FOR GRAPH TestHierarchicalData2 {
// VERTEX DELETION
IF vType1 != "" THEN
start1 = {vType1.*};
del = SELECT s FROM start1:s POST-ACCUM DELETE (s);
END;
IF vType2 != "" THEN
start2 = {vType2.*};
del = SELECT s FROM start2:s POST-ACCUM DELETE (s);
END;
IF vType3 != "" THEN
start3 = {vType3.*};
del = SELECT s FROM start3:s POST-ACCUM DELETE (s);
END;
// EDGE DELETION
start4 = {ANY};
del = SELECT s FROM start4:s - (:e) - :t WHERE e.type == eType1 or e.type == eType2 or e.type == eType3 ACCUM DELETE (e);
}
Note that unused vertex/edge names can be left blank and nothing will be affected.
Thanks for the reply. I’ve been looking into this a bit more… is there a way in a query to delete one specific edge? Not one type of edge but one edge exactly. For example, query parameters specify source vertex, edge type, and target vertex. The query would delete that one edge.