10.1 Loading a PGQL Property Graph Using the readGraphByName API
You can load a PGQL property graph by name into the graph server (PGX).
You can use the PgxSession#readGraphByName API to load a PGQL property graph:
readGraphByName(String schemaName, String graphName,
GraphSource source, ReadGraphOption options)
The arguments used in the method are described in the following table:
Table 10-1 Parameters for
the readGraphByName method
| Parameter | Description | Optional |
|---|---|---|
schemaName |
Schema owner | Yes |
graphName |
Name of the PGQL property graph | No |
source |
Source format for the
graph:
|
No |
options |
Represents the graph optimization options | Yes |
The readGraphByName() method reads the PGQL property graph 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 PGQL property graph as shown:
opg4j> var graph = session.readGraphByName("BANKDATA", GraphSource.PG_PGQL)
$12 ==> PgxGraph[name=bankdata,N=1000,E=5001,created=1625730942294]PgxGraph graph = session.readGraphByName("BANKDATA", GraphSource.PG_PGQL);
Graph: PgxGraph[name=bankdata,N=1000,E=5001,created=1625732149262]>>> graph = session.read_graph_by_name('BANKDATA', 'pg_pgql')
>>> graph
PgxGraph(name: bankdata, v: 1000, e: 5001, directed: True, memory(Mb): 0)
- Specifying Options for the readGraphByName API
You can specify graph optimization options,OnMissingVertexOptionor both when using thereadGraphByNameAPI for loading a PGQL property graph. - Specifying the Schema Name for the readGraphByName API
You can specify the schema name when using thereadGraphByNameAPI for loading a PGQL property graph.
See Also:
Mapping Oracle Database Types to PGX Types for more information on the supported types in the graph server (PGX)10.1.1 Specifying Options for the
readGraphByName API
You can specify graph optimization options,
OnMissingVertexOption or both when using the readGraphByName
API for loading a PGQL property graph.
The ReadGraphOption interface supports an
additional options parameter when loading a PGQL property graph by name.
The following sections explain the various options supported by the
ReadGraphOption interface.
Using the Graph Optimization Options
You can optimize the read or update performance
when loading a PGQL property graph by name by using one
of the following options:
ReadGraphOption.optimizeFor(GraphOptimizedFor.READ): Specifies that the loaded graph is optimized for READ.ReadGraphOption.optimizeFor(GraphOptimizedFor.UPDATES): Specifies that the loaded graph is optimized for UPDATE.ReadGraphOption.synchronizable(): Specifies that the loaded graph can be synchronized.
It is important to note the following:
-
synchronizable()option can be used in combination withUPDATEandREAD. However, theUPDATEandREADoptions cannot be used at the same time. - If you are loading a PGQL property graph
for
SYNCHRONIZABLEoption, then ensure that the vertex and edge keys are numeric and non-composite.
The following example loads a PGQL property graph for READ and
SYNCHRONIZABLE options:
opg4j> var graph = session.readGraphByName("BANK_GRAPH", GraphSource.PG_PGQL,
...> ReadGraphOption.optimizeFor(GraphOptimizedFor.READ),
...> ReadGraphOption.synchronizable())
graph ==> PgxGraph[name=BANK_GRAPH_2,N=1000,E=5001,created=1648457198462]
PgxGraph graph = session.readGraphByName("BANK_GRAPH", GraphSource.PG_PGQL,
ReadGraphOption.optimizeFor(GraphOptimizedFor.READ),
ReadGraphOption.synchronizable());
>>> graph = session.read_graph_by_name('BANK_GRAPH',
... 'pg_pgql', options=['optimized_for_read', 'synchronizable'])Using the
OnMissingVertex Options
If either the source or destination vertex or both are missing for an edge,
then you can use the OnMissingVertexOption which specifies the behavior for
handling the edge with the missing vertex. The following values are supported for this
option:
ReadGraphOption.onMissingVertex(OnMissingVertex.ERROR): This is the default option and this specifies that an error must be thrown for edges with missing vertices.ReadGraphOption.onMissingVertex(OnMissingVertex.IGNORE_EDGE): Specifies that the edge for a missing vertex must be ignored.ReadGraphOption.onMissingVertex(OnMissingVertex.IGNORE_EDGE_LOG): Specifies that the edge for a missing vertex must be ignored and all ignored edges must be logged.ReadGraphOption.onMissingVertex(OnMissingVertex.IGNORE_EDGE_LOG_ONCE): Specifies that the edge for a missing vertex must be ignored and only the first ignored edge must be logged.
The following example loads the PGQL property graph by ignoring the edges with missing vertices and logging only the first ignored
edge. Note, to view the logs, you must update the default Logback configuration file in
/etc/oracle/graph/logback.xml and the graph server (PGX) logger
configuration file in /etc/oracle/graph/logback-server.xml to log the DEBUG
logs. You can then view the ignored edges in /var/opt/log/pgx-server.log
file.
opg4j> session.readGraphByName("REGIONS", GraphSource.PG_PGQL,
...> ReadGraphOption.onMissingVertex(OnMissingVertex.IGNORE_EDGE_LOG_ONCE))
$7 ==> PgxGraph[name=REGIONVIEW_3,N=27,E=18,created=1655903219910]
PgxGraph graph = session.readGraphByName("REGIONS", GraphSource.PG_PGQL, ReadGraphOption.onMissingVertex(OnMissingVertex.IGNORE_EDGE_LOG_ONCE));>>> graph = session.read_graph_by_name('REGIONS',
... 'pg_pgql', options=['on_missing_vertex_ignore_edge_log_once'])10.1.2 Specifying the Schema Name for the readGraphByName API
You can specify the schema name when using the
readGraphByName API for loading a PGQL property graph.
This feature allows you to load a PGQL property graph from another user schema into the graph
server (PGX). However, ensure that you have READ permission on all the
underlying metadata and data tables when loading a PGQL property graph from another schema.
The following example loads a PGQL property graph from the GRAPHUSER
schema:
opg4j> var graph = session.readGraphByName("GRAPHUSER", "FRIENDS", GraphSource.PG_PGQL)
graph ==> PgxGraph[name=FRIENDS,N=6,E=4,created=1672743474212]
PgxGraph graph = session.readGraphByName("GRAPHUSER", "FRIENDS", GraphSource.PG_PGQL);