27.6.1.2 PARTITIONED_IDS Strategy
PARTITIONED_IDS
strategy implies that IDs are
constructed by combining the label name with user-provided keys or auto-generated keys.
Therefore, the uniqueness requirement for IDs applies at the label level once the graph is
built.
However, note that the GraphBuilder
API enforces all IDs (user-provided
keys or auto-generated keys) to be unique at the time of graph creation.
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 to retain and partition
vertex and edge IDs.
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(true). // Retain user-provided vertex IDs (enabled by default)
setRetainEdgeIds(true). // Retain user-provided edge IDs (enabled by default)
partitionedVertexIds(true). // Partition vertex IDs
partitionedEdgeIds(true) // Partition edge IDs
opg4j> builder.addVertex(1).addLabel("Person").setProperty("name", "Alice")
opg4j> builder.addVertex(2).addLabel("Account").setProperty("IBAN", "12345")
opg4j> builder.addEdge(1, 1, 2).setLabel("Owns") // (edge ID, source vertex ID, destination vertex ID)
opg4j> var graph = builder.build("Graph_PartitionedIds")
GraphBuilder<Integer> builder = session.createGraphBuilder();
builder.setVertexIdGenerationStrategy(IdGenerationStrategy.USER_IDS) // Using user-provided IDs for vertices
.setEdgeIdGenerationStrategy(IdGenerationStrategy.USER_IDS) // Using user-provided IDs for edges
.setRetainVertexIds(true) // Retain user-provided vertex IDs (enabled by default)
.setRetainEdgeIds(true) // Retain user-provided edge IDs (enabled by default)
.partitionedVertexIds(true) // Partition vertex IDs
.partitionedEdgeIds(true); // Partition edge IDs
builder.addVertex(1).addLabel("Person").setProperty("name", "Alice");
builder.addVertex(2).addLabel("Account").setProperty("IBAN", "12345");
builder.addEdge(1, 1, 2).setLabel("Owns"); // (edge ID, source vertex ID, destination vertex ID)
PgxGraph graph = builder.build("Graph_PartitionedIds");
>>> builder = session.create_graph_builder(vertex_id_generation_strategy='user_ids',
... edge_id_generation_strategy='user_ids')
>>> builder.set_retain_vertex_ids(True)
>>> builder.set_retain_edge_ids(True)
>>> builder.partitioned_edge_ids(True)
>>> builder.partitioned_vertex_ids(True)
>>> builder.add_vertex(1).add_label("Person").set_property("name", "Alice")
>>> builder.add_vertex(2).add_label("Account").set_property("IBAN", "12345")
>>> builder.add_edge(1, 2, 1).set_label("Owns") # (source vertex ID, destination vertex ID, edge ID)
>>> graph = builder.build(name="Graph_PartitionedIds")
As seen in the preceding example, the vertex IDs 1
and
2
are globally unique across the graph. Also, the edge ID
1
is unique in the graph.
The following shows an example for retrieving the vertices and edges using a combination of the label name and the ID.
opg4j> var alice = graph.getVertex("Person(1)") // Retrieves Alice
opg4j> var account = graph.getVertex("Account(2)") // Retrieves the Account
opg4j> var owns = graph.getEdge("Owns_Person_Account(1)") // Retrieves the edge
PgxVertex<String> alice = graph.getVertex("Person(1)"); // Retrieves Alice
PgxVertex<String> account = graph.getVertex("Account(2)"); // Retrieves the Account
PgxEdge<String> owns = graph.getEdge("Owns_Person_Account(1)"); // Retrieves the edge
>>> graph.get_vertex("Person(1)")
>>> graph.get_vertex("Account(2)")
>>> graph.get_edge("Owns_Person_Account(1)")