Skip to content

Commit

Permalink
Add content to state that id/label are immutable #238
Browse files Browse the repository at this point in the history
  • Loading branch information
spmallette committed Sep 28, 2023
1 parent 2b86632 commit 2d11946
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions book/Section-Writing-Gremlin-Queries.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2233,18 +2233,19 @@ Working with IDs
~~~~~~~~~~~~~~~~

Every vertex, every edge and even every property in a graph has a unique ID that can
be used to reference it individually or as part of a group. Beware that the IDs you
provide when loading a graph from a GraphML or GraphSON file may not in many cases
end up being the IDs that the back-end graph store actually uses as it builds up your
graph. TinkerGraph for example will preserve user provided IDs but many graph
databases such as JanusGraph generate their own IDs. The same is true when you add
vertices and edges using a graph traversal or using the TinkerPop API. This is a long
winded way of saying that you should not depend on the IDs in your GraphML or
GraphSON file that you just loaded remaining unchanged once the data has been loaded
into the graph store. When you add a new vertex or edge to your graph using a
traversal, the graph system will automatically generate a new, unique ID for it. If
you need to figure out the ID for a vertex or an edge you can always get it from a
query of the graph itself.
be used to reference it individually or as part of a group. These IDs are immutable
and therefore, cannot be changed once assigned. Beware that the IDs you provide when
loading a graph from a GraphML or GraphSON file may not in many cases end up being
the IDs that the back-end graph store actually uses as it builds up your graph.
TinkerGraph for example will preserve user provided IDs but many graph databases such
as JanusGraph generate their own IDs. The same is true when you add vertices and
edges using a graph traversal or using the TinkerPop API. This is a long winded way
of saying that you should not depend on the IDs in your GraphML or GraphSON file that
you just loaded remaining unchanged once the data has been loaded into the graph
store. When you add a new vertex or edge to your graph using a traversal, the graph
system will automatically generate a new, unique ID for it. If you need to figure out
the ID for a vertex or an edge you can always get it from a query of the graph
itself.

TIP: Don't rely on the graph preserving the ID values you provide. Write code that
can query the graph itself for ID values. How IDs are managed will be graph database
Expand Down Expand Up @@ -2344,10 +2345,11 @@ Working with labels
~~~~~~~~~~~~~~~~~~~

It's a good idea when designing a graph to give the vertices and edges meaningful
labels. You can use these to help refine searches. For example in the 'air-routes'
labels. As with IDs, labels are immutable and therefore cannot be changed once
assigned. You can use these to help refine searches. For example in the 'air-routes'
graph, every airport vertex is labelled 'airport' and every country vertex, not
surprisingly, is labelled 'country'. Similarly, edges that represent a flight route
are labelled 'route'. You can use labels in many ways. We already saw the 'hasLabel'
are labelled 'route'. You can use labels in many ways. We already saw the 'hasLabel'
step being used in the basic queries section to test for a particular label. Here are
a few more examples.

Expand Down

0 comments on commit 2d11946

Please sign in to comment.