14.6.1.1 Creating a Simple Graph

This section shows an example of creating a simple graph using the createGraphBuilder() method .

opg4j> var builder = session.createGraphBuilder()
builder ==> GraphBuilderImpl[session=cd201ac9-e73f-447c-9cec-cd929293acc3,vertexChanges=0,edgeChanges=0]

opg4j> builder.addEdge(1, 2)
opg4j> builder.addEdge(2, 3)
opg4j> builder.addEdge(2, 4)
opg4j> builder.addEdge(3, 4)
opg4j> builder.addEdge(4, 2)

opg4j> var graph = builder.build()
graph ==> PgxGraph[name=anonymous_graph_16,N=4,E=5,created=1629805890550]
import oracle.pgx.api.*;

PgxSession session = Pgx.createSession("example");
GraphBuilder<Integer> builder = session.createGraphBuilder();

builder.addEdge(1, 2);
builder.addEdge(2, 3);
builder.addEdge(2, 4);
builder.addEdge(3, 4);
builder.addEdge(4, 2);

PgxGraph graph = builder.build();
from pypgx import get_session

session = get_session(session_name="example")
builder = session.create_graph_builder()
builder.add_edge(1, 2)
builder.add_edge(2, 3)
builder.add_edge(2, 4)
builder.add_edge(3, 4)
builder.add_edge(4, 2)
graph = builder.build()

Also, note that the following:

  • A call to addEdge consists of the new unique edge ID, the source vertex ID and the destination vertex ID.
  • No graph configuration is required.
  • When adding edges, all vertices that do not already exist are created on the fly as edges are created.
  • GraphBuilder supports only the following two generation strategies for creating vertices and edge IDs:
    • USER_IDS (the default value)
    • AUTO_GENERATED