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_VIEW,
...> 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_VIEW,
ReadGraphOption.optimizeFor(GraphOptimizedFor.READ),
ReadGraphOption.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_VIEW,
...> 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_VIEW, ReadGraphOption.onMissingVertex(OnMissingVertex.IGNORE_EDGE_LOG_ONCE));