3.3.1 PGQL Based Subgraph Loading

You can use the PgViewSubgraphReader#fromPgView API to create an in-memory subgraph from a property graph view using a set of PGQL queries.

These PGQL queries define the vertices and edges that are to be loaded into the subgraph. You can also use multiple PGQL queries and the resulting output graph is a union of the subgraphs, each being loaded independently by each PGQL query.

Note:

PGQL queries with GROUP BY or ORDER BY clauses are not supported for loading of subgraphs from a property graph view.

The following example create a subgraph using multiple PGQL queries from the property graph view FRIENDS.

opg4j> var graph = session.readSubgraph().
...>                       fromPgView("FRIENDS").
...>                       queryPgql("MATCH (v1:Person)-[e:FRIENDOF]->(v2:Person) WHERE id(v1) = 'PERSONS(1)'").
...>                       queryPgql("MATCH (v:Person) WHERE id(v) = 'PERSONS(2)'").
...>                       load()
graph ==> PgxGraph[name=FRIENDS,N=3,E=1,created=1646726883194]
PgxGraph graph = session.readSubgraph()
                          .fromPgView("FRIENDS")
                          .queryPgql("MATCH (v1:Person)-[e:FRIENDOF]->(v2:Person) WHERE id(v1) = 'PERSONS(1)'")
                          .queryPgql("MATCH (v:Person) WHERE id(v) = 'PERSONS(2)'")
                          .load();
>>> graph = session.read_subgraph_from_pg_view("FRIENDS", ["MATCH (v1:Person)-[e:FRIENDOF]->(v2:Person) WHERE id(v1) = 'PERSONS(1)'",
...                                                        "MATCH (v:Person) WHERE id(v) = 'PERSONS(2)'"])
>>> graph
PgxGraph(name: FRIENDS, v: 3, e: 1, directed: True, memory(Mb): 0)

The following displays the output for the preceding PGQL query using the graph visualization tool.

Figure 3-2 Subgraph Visualization

Description of Figure 3-2 follows
Description of "Figure 3-2 Subgraph Visualization"