14.12.12 Creating a Graph from Multiple PgxFrame Objects
You can create a PgxGraph
with vertex PgxFrame
(s) and edge PgxFrame
(s).
Consider the following
PgxFrame
objects:
people
+--------------+
| id | name |
+--------------+
| 1 | Alice |
| 2 | Bob |
| 3 | Charlie |
+--------------+
houses
+---------------------------+
| identification | location |
+---------------------------+
| 1 | Road 1 |
| 2 | Street 5 |
| 3 | Avenue 4 |
+---------------------------+
knows
+-----------+
| src | dst |
+-----------+
| 1 | 1 |
| 2 | 3 |
| 3 | 2 |
+-----------+
lives
+----------------------+
| source | destination |
+----------------------+
| 1 | 2 |
| 2 | 1 |
| 3 | 3 |
+----------------------+
You can now create a
PgxGraph
as shown in the following examples:
Creating a Graph from Multiple PgxFrame
Objects Using
JShell
opg4j> var graphFromFramesCreator = session.createGraphFromFrames("example graph")
opg4j> graphFromFramesCreator.vertexProvider("people", people)
opg4j> graphFromFramesCreator.vertexProvider("houses", houses).vertexKeyColumn("identification")
opg4j> graphFromFramesCreator.edgeProvider("knows", "people", "people", knows)
opg4j> var edge_provider = graphFromFramesCreator.edgeProvider("lives", "people", "houses", lives)
opg4j> edge_provider.sourceVertexKeyColumn("source")
opg4j> edge_provider.destinationVertexKeyColumn("destination")
opg4j> graphFromFramesCreator.partitioned(true)
opg4j> var graph = graphFromFramesCreator.create()
Creating a Graph from Multiple PgxFrame
Objects Using
Java
PgxGraphFromFramesCreator graphFromFramesCreator = session.createGraphFromFrames("example graph");
graphFromFramesCreator.vertexProvider("people", people);
graphFromFramesCreator.vertexProvider("houses", houses).vertexKeyColumn("identification");
graphFromFramesCreator.edgeProvider("knows", "people", "people", knows);
PgxEdgeProviderFromFramesCreator edgeProvider = graphFromFramesCreator.edgeProvider("lives", "people", "houses", lives);
edgeProvider.sourceVertexKeyColumn("source");
edgeProvider.destinationVertexKeyColumn("destination");
graphFromFramesCreator.partitioned(true);
PgxGraph graph = graphFromFramesCreator.create();
Creating a Graph from Multiple PgxFrame
Objects Using
Python
vertex_providers_from_frames = [
session.vertex_provider_from_frame("person",
people),
session.vertex_provider_from_frame("house",
frame = houses,
vertex_key_column = "identification")
]
edge_providers_from_frames = [
session.edge_provider_from_frame("person_knows_person",
source_provider = "person",
destination_provider = "person",
frame = knows),
session.edge_provider_from_frame("person_lives_at_house",
source_provider = "person",
destination_provider = "house",
frame = lives,
source_vertex_column="source",
destination_vertex_column="destination")
]
graph = session.graph_from_frames("example graph", vertex_providers_from_frames, edge_providers_from_frames, partitioned=True)
Parent topic: PgxFrames Tabular Data-Structure