3.1 Loading a Graph into the Graph Server (PGX) from a Property Graph View

You can load a graph into the graph server (PGX) from a property graph view by name.

You can use the following PgxSession method to load a graph from a property graph view by name:

readGraphByName(String name, GraphSource source)

The arguments used in the method are as follows:

  • name: Name of the property graph view.
  • source: Source for the graph. In this case, PG_VIEW.

The readGraphByName(String name, GraphSource source) method reads the property graph view metadata tables and internally generates the graph configuration to load the graph. You must have PGX_SESSION_NEW_GRAPH permission to use this API.

For example you can load the graph from a property graph view as shown:

opg4j> var graph = session.readGraphByName("BANKDATAVIEW", GraphSource.PG_VIEW)
$12 ==> PgxGraph[name=bankdataview,N=1000,E=5001,created=1625730942294]
PgxGraph graph = session.readGraphByName("BANKDATAVIEW", GraphSource.PG_VIEW);
Graph: PgxGraph[name=bankdataview,N=1000,E=5001,created=1625732149262]
>>> graph = session.read_graph_by_name('BANKDATAVIEW', 'pg_view')
>>> graph
PgxGraph(name: bankdataview, v: 1000, e: 5001, directed: True, memory(Mb): 0)

Using Graph Optimization Options When Loading a Property Graph View

You can optimize the read or update performance when loading a property graph view by name by using an additional options parameter as shown:

readGraphByName(String name, GraphSource source, ReadGraphOption options)

The options parameter can have the following supported values:

  • ReadGraphOption.optimizeFor(GraphOptimizedFor.READ): Specifies that the loaded graph is optimized for READ.
  • ReadGraphOption.optimizeFor(GraphOptimizedFor.UPDATE): Specifies that the loaded graph is optimized for UPDATE.
  • ReadGraphOption.synchronizable(): Specifies that the loaded graph can be synchronized.

It is important to note that the synchronizable() option can be used in combination with UPDATE and READ. However, the UPDATE and READ options cannot be used at the same time.

The following example loads a property graph view for READ and SYNCHRONIZABLE options:

opg4j> var graph = session.readGraphByName("BANK_GRAPH_VIEW", GraphSource.PG_VIEW,
...>                            ReadGraphOption.optimizeFor(GraphOptimizedFor.READ),
...>                            ReadGraphOption.synchronizable())
graph ==> PgxGraph[name=BANK_GRAPH_VIEW_2,N=1000,E=5001,created=1648457198462]
PgxGraph graph = session.readGraphByName("BANKDATAVIEW", GraphSource.PG_VIEW, "BANK_GRAPH_VIEW", GraphSource.PG_VIEW,