Why is T.label immutable and do we have to create a new node to change a label?
We cannot do g.V('some label').property(T.label, 'new label').iterate() ? Is this correct? Thank you
Solution:Jump to solution
you have a few questions here @Julius Hamilton
Why is T.label immutablei'm not sure there's a particular reason except to say that many graphs have not allowed that functionality so TinkerPop hasn't offered a way to do it.
and do we have to create a new node to change a label?...
Stack Overflow
gremlin clone a node and its edges
Does gremlin provide the ability to clone a vertex for instance
v1->v2, v1->v3, v1->v4 how can I simply and efficiently create a new vertex v5 that also has edges that point to v2, v3, v4 ...
16 Replies
Hi,
Gremlin has no support for managing a graph's schema, so what you are doing is wrong.
Solution
you have a few questions here @Julius Hamilton
Why is T.label immutablei'm not sure there's a particular reason except to say that many graphs have not allowed that functionality so TinkerPop hasn't offered a way to do it.
and do we have to create a new node to change a label?yes
We cannot do g.V('some label').property(T.label, 'new label').iterate()no, because you can't modify the label as mentioned earlier, but also
V()
does not take a label
as an argument. it would be more correct to do g.V().hasLabel('some label').property(...)
to modify all things with a particular label (but, again label
and id
cannot be one of those things. you'd have to sort of clone the vertex. there are some patterns for doing it: https://stackoverflow.com/q/51900116/1831717
also, in the future, i think a mutable label probably should be allowed. we'll see how that comes to pass.Stack Overflow
gremlin clone a node and its edges
Does gremlin provide the ability to clone a vertex for instance
v1->v2, v1->v3, v1->v4 how can I simply and efficiently create a new vertex v5 that also has edges that point to v2, v3, v4 ...
What you are doing, I think of as a
renameVertexLabel
operation. Most graphs have a custom api to handle such things.didn't really think too hard about it, but shouldn't we just allow
property(label, 'new-label')
to work?I'd prefer a more dedicated approach. An api (gremlin lang) that deals with schema creation and modification.
Gremlin comes with a implicit meta model, which can be supported fairly easily. We need to leave some extension points for all the implementation specific details that exist outside of Gremlin's meta model.
Stuff like partitions, gis, strange data types and ...
What I have in mind is something like,
From what I have seen this is the approach most implementations have taken.
i see...you're thinking of a bigger picture and one that fits the specific nature of the OP's question about changing the label for all vertices of a particular label. you might just want to do that from a schema perspective, whre you are modifying the schema as a whole. i still think there is a Gremlin component though where you just want to do
g.V(1).property(label, 'new-label')
and just change it for one vertex."
g.V(1).property(label, 'new-label')
and just change it for one vertex"
I see this as a,
On Sqlg
at least only some rdbms support transactional schema changes, which means its best to handle the schema outside of the data.
Actually come to think of it, the above is wrong, as it needs to migrate all edges attached to the vertex also.yeah, i see that in sqlg's case you have a situation where changing the label for one vertex isn't quite as direct as something like TinkerGraph where it's probably just:
vertex.setLabel("new-label")
which updates a member variable.Yeah, I'd suggest that
TinkerGraph
not be used as a guide for schema/meta management but rather Janus
, ArcadeGraph
and others.@Julius Hamilton What database are you using? Amazon Neptune does allow you to have multiple labels but the syntax is different.
Also to Dave's point, while Gremlin doesn't allow for you to change a label on a node, openCypher does. There are a lot of interoperability aspects that have driven how Neptune supports labels.
Using multiple labels in Gremlin on Neptune: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html#feature-gremlin-differences-labels You can change a label on a vertex/node in openCypher via: ( where the old label is
Using multiple labels in Gremlin on Neptune: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html#feature-gremlin-differences-labels You can change a label on a vertex/node in openCypher via: ( where the old label is
user
and new label is newuser
)
This also brings up the point that openCypher supports the ability to do this, while Gremlin does not. So likely a gap that Gremlin needs to address even without addressing this from a schema/constraint standpoint.Gremlin standards compliance in Amazon Neptune - Amazon Neptune
Overview of differences between the Neptune and TinkerPop implementations of Gremlin.
Are labels on Neptune more like a tag, i.e. different vertices with the same label might have completely different properties?
Neptune has very few constraints. Primarily only that each vertex and edge must have a unique ID (and those IDs must be a String). Each vertex and edge must have a label (though if not defined at creation, a label of
vertex
or edge
is used). And that every edge must have a vertex at either end of the edge. Outside of that, there are no constraints on what properties a vertex/edge must have, data types, etc.Ok and that it not just saying that all properties are optional, but that they can have different types even if they are on the same label?
label: 'Person', "ID": 1, name: "John"
label: 'Person', "ID": 2, name: 1L
This kind of modelling is ok?
"Ok" is of opinion. It's entirely possible and a tradeoff in supporting multiple frameworks and query languages.
Ok, thanks