27.6.1.3 UNSTABLE_GENERATED_IDS Strategy
UNSTABLE_GENERATED_IDS
strategy implies that the IDs are
system-generated and may change. These IDs are not guaranteed to be stable.
The following example creates a partitioned graph using the
createGraphBuilder
API with USER_IDS
generation
strategy for vertices and edges. Also, the graph is configured not to retain the IDs.
Therefore, system-generated IDs are used.
opg4j> var builder = session.createGraphBuilder()
opg4j> builder.setVertexIdGenerationStrategy(IdGenerationStrategy.USER_IDS). // Using user-provided IDs for vertices
setEdgeIdGenerationStrategy(IdGenerationStrategy.USER_IDS). // Using user-provided IDs for edges
setRetainVertexIds(false). // Do not retain user-provided vertex IDs
setRetainEdgeIds(false) // DO not retain user-provided edge IDs
opg4j> builder.addVertex(1).addLabel("Person").setProperty("name", "Alice")
opg4j> builder.addVertex(2).addLabel("Person").setProperty("name", "Bob")
opg4j> builder.addEdge(1, 1, 2).setLabel("Knows") // Edge from Alice to Bob with ID 1
opg4j> var graph = builder.build("Graph_UnstableIds")
GraphBuilder<Integer> builder = session.createGraphBuilder();
builder.setVertexIdGenerationStrategy(USER_IDS) // Using user-provided IDs for vertices
.setEdgeIdGenerationStrategy(USER_IDS) // Using user-provided IDs for edges
.setRetainVertexIds(false) // Do not retain user-provided vertex IDs
.setRetainEdgeIds(false) // Do not retain user-provided edge IDs
builder.addVertex(1).addLabel("Person").setProperty("name", "Alice");
builder.addVertex(2).addLabel("Person").setProperty("name", "Bob");
builder.addEdge(1, 1, 2).setLabel("Knows"); // Edge from Alice to Bob with ID 1
PgxGraph graph = builder.build("Graph_UnstableIds");
>>> builder = session.create_graph_builder(vertex_id_generation_strategy='user_ids',
... edge_id_generation_strategy='user_ids')
>>> builder.set_retain_vertex_ids(False)
>>> builder.set_retain_edge_ids(False)
>>> builder.add_vertex(1).add_label("Person").set_property("name", "Alice")
>>> builder.add_vertex(2).add_label("Person").set_property("name", "Bob")
>>> builder.add_edge(1, 1, 2).set_label("Knows")
>>> graph = builder.build(name="Graph_UnstableIds")
In the preceding example, regardless of the ID generation strategy used
by the GraphBuilder (USER_IDS
or AUTO_GENERATED
),
the graph server (PGX) will automatically regenerate the IDs since the IDs provided
by the GraphBuilder
API are not retained.
As these IDs may not be stable, you can retrieve the elements by obtaining their IDs at runtime or by iterating over the graph. In this case, it is recommended to use properties as identifiers to locate vertices and edges.