Moraltox
Moraltox

Reputation: 924

Running online algorithms only on specific node and edge types in Memgraph

I am trying to execute the .update() method on specific node and edge types during a trigger execution. The .update() method currently accepts the following parameters: (createdVertices, createdEdges, updatedVertices, updatedEdges, deletedVertices, deletedEdges). It doesn't allow me to run the update on a projection and I am trying to find a workaround.

Here's a sample trigger for online community detection that I am using:

CREATE TRIGGER sample_trigger BEFORE COMMIT
EXECUTE CALL community_detection_online.update(createdVertices, createdEdges, updatedVertices, updatedEdges, deletedVertices, deletedEdges) YIELD *;

By default, the update method would operate on any vertex and edge supplied by the trigger, but I want to restrict the online update to propagate only across specific vertex and edge types.

One possible solution I considered was to allow conditional triggers based on types, but it appears that Memgraph doesn't currently support this feature.

How can I filter createdVertices, createdEdges, updatedVertices, updatedEdges, deletedVertices, and deletedEdges based on their types before they are passed to the .update() method?

Upvotes: 0

Views: 32

Answers (1)

MPesi
MPesi

Reputation: 357

You can also run .update() on projections. You can set a subgraph as the first parameter for every procedure, including the community_detection_online.update. You would have to use MATCH to match the specific types you want and project it as a subgraph, something like this:

MATCH p=(n:SpecificLabel)-[r:REL_TYPE]->(m:SpecificLabel)
WITH project(p) AS subgraph

You would then add that subgraph as a first parameter when calling a certain procedure. In this case, it would be:

CALL community_detection_online.update(**subgraph**, createdVertices, createdEdges, updatedVertices, updatedEdges, deletedVertices, deletedEdges)

Upvotes: 1

Related Questions