0

Is there any possible way to change the current label of a vertex or an edge? For example, if I create a graph to store movies and series and then create the following vertex:

SELECT * FROM cypher ('visual_arts', $$
CREATE (v:Movie {title: "The Last of Us", episodes: 4, seasons: 1, main_actors: ["Pedro Pascal", "Bella Ramsey"]})
RETURN v $$) as (v agtype);

And then I want to correct this vertex by changing the label to "Series" instead of "Movie". How can I do that?

Matheus Farias
  • 716
  • 1
  • 10

3 Answers3

0

In current version of AGE, we cannot update label of any vertex or edge.

To do so, the best way is to introduce a new property UpdatedLabel and set it to Series. You can do so by:

SELECT * FROM cypher('visual_arts', $$
MATCH (v:Movie)
SET v.UpdatedLabel = "Series" RETURN v
$$) as (v agtype);

Now you can retrieve the Series by using:

SELECT * FROM cypher('visual_arts', $$
MATCH (v:Movie)
where v.UpdatedLabel = "Series" RETURN v
$$) as (v agtype);
0

Unfortunately, we don't have update label functionality in Apache-age but sooner we will be having that functionality.

It will most prolly be on the same pattern as it works in cypher queries in Neo4j like

  1. first match the node you want to update label for
  2. then delete the previous label for the node
  3. then add the new label for the node

Note: node here refers to vertex or edge

For example: if we have a node with label "Engine" and want to update it to "EnginePower" then in the following way we can do that in cypher Neo4j

MATCH (c:Car)-[r]-(e:Engine)
REMOVE e:Engine
SET e:EnginePower
RETURN e

For the same if we want to add functionality in apache-age then it can be something in the following manner

SELECT * FROM cypher('graph_name', $$
MATCH (c:Car)-[r]-(e:Engine)
REMOVE e:Engine 
SET e:EnginePower 
RETURN e
$$) as (e agtype);
umerFreak
  • 9
  • 2
0

As AGE currently exists, it is not possible to directly change the label of a vertex or an edge once it has been created, because they are immutable by definition.

A possible workaround that you could try is to create a new node with the correct label and copy over the relevant properties from the existing node. Something like:

MATCH (m:Movie {title: "The Last of Us"})
CREATE (s:Series)
SET s = m
REMOVE m:Movie
RETURN s
tokamak32
  • 27
  • 7