PGX 21.1.1

Loading Subgraphs

In this guide you will learn how to create a subgraph of a graph that is not already loaded into memory. First, we will recap about graph loading and subgraph filtering. Then we will show how to merge these two techniques into subgraph loading.

Not available for all graph formats

Subgraph loading is only available on the following graph formats: - Adjacency List - Oracle Property Graph loaded from Oracle RDBMS, Oracle NoSQL or Apache HBase

Recap: Graph Loading and Subgraph Creation

Loading a Graph

As previously explained you can load a graph like this:

var g = session.readGraphWithProperties("examples/graphs/sample.adj.json")
import oracle.pgx.api.*;

PgxSession session = Pgx.createSession("my-session");
PgxGraph g = session.readGraphWithProperties("examples/graphs/sample.adj.json");
session = pypgx.get_session(session_name-"my-session")
g = session.read_graph_with_properties("examples/graphs/sample.adj.json")

Creating a Subgraph from a Loaded Graph

The loaded graph is based on the sample graph that is used throughout the project.

To create a subgraph having only edges and the vertices connecting them, where the source vertex's property prop equals to 10, you can use the following expression:

src.prop == 10

This expression selects the following edges:

sample graph with highlighted edges

In PGX the subgraph is created by evaluating a filter on a loaded graph:

var subgraph = g.filter(EdgeFilter.fromExpression("src.prop == 10"))
import oracle.pgx.filter.expressions.*;
PgxGraph subgraph = g.filter(EdgeFilter.fromExpression("src.prop == 10"));
subgraph = g.filter(EdgeFilter("src.prop1 == 10"))

Combining Loading and Subgraph Creation

Now assume that you are only interested in a subgraph from the beginning. In this case loading the whole graph and then creating a subgraph might not the best way: If the full graph is too big to fit into memory, loading the graph is not an option at all and even if the whole graph fits into memory, memory is wasted to hold both the original graph and the subgraph.

Therefore we provide a combined operation to load a subgraph based on a filter expression. Imagine you want to load a subgraph of the above graph based on the filter expression src.prop == 10. To do so you need to specify the filter in the graph-config like this:

  "uri": "sample.adj", 
  "format": "adj_list",
  "vertex_props": [{ 
    "name": "prop", 
    "type": "integer" 
  "edge_props": [{ 
    "name": "cost", 
    "type": "double" 
  "separator": " ",
  "loading_options": {
    "filter": {
      "type": "edge",
      "expression": "src.prop == 10"

Notice the new section loading which contains the configuration for the filter.

If you load the graph using this configuration only the following subgraph will be loaded:

sample filtered graph

To read more about subgraph loading, see the documentation.