14.7.6 Directly Loading a Specific Snapshot of a Graph
You can also load a specific snapshot of a graph directly using the PgxSession.readGraphAsOf()
method. This is a shortcut for loading a graph with readGraphWithProperties()
followed by a setSnapshot()
.
Consider two snapshots of a graph that are already loaded into the PGX session. The following example shows how to get a reference to a specific snapshot:
- Get a graph configuration for the graph
Get the Graph Configuration Using JShell
opg4j> var config = GraphConfigFactory.forAnyFormat().fromPath("<path_to_json>") ==> {"format":"adj_list", ... }
Get the Graph Configuration Using JavaGraphConfig config = GraphConfigFactory.forAnyFormat().fromPath("<path_to_json>");
Get the Graph Configuration Using Pythonconfig = GraphConfigFactory.for_any_format().from_path("<path_to_json>")
- Check the loaded snapshots for this graph config using
getAvailableSnapshots()
:Get the Available Snapshots Using JShellopg4j> session.getAvailableSnapshots(G) ==> GraphMetaData [getNumVertices()=4, getNumEdges()=4, memoryMb=0, dataSourceVersion=1453315103000, creationRequestTimestamp=1453315122669 (2016-01-20 10:38:42.669), creationTimestamp=1453315122685 (2016-01-20 10:38:42.685), vertexIdType=integer, edgeIdType=long] ==> GraphMetaData [getNumVertices()=5, getNumEdges()=5, memoryMb=3, dataSourceVersion=1452083654000, creationRequestTimestamp=1453314938744 (2016-01-20 10:35:38.744), creationTimestamp=1453314938833 (2016-01-20 10:35:38.833), vertexIdType=integer, edgeIdType=long]
Get the Available Snapshots Using JavaDeque<GraphMetaData> snapshots = session.getAvailableSnapshots(G);
Get the Available Snapshots Using Pythonsession.get_available_snapshots(G)
- Check out the snapshot of the graph which has 4 vertices and 4 edges and having the timestamp
1453315122685
:Load a Specific Snapshot Using JShellopg4j> var G = session.readGraphAsOf( config, 1453315122685 ) ==> PGX Graph named 'sample' bound to PGX session 'a1744e86-65fb-4bd1-b2dc-5458b20954a9' registered at PGX Server Instance running in embedded mode opg4j> G.getNumVertices() ==> 4 opg4j> G.getNumEdges() ==> 4
Load a Specific Snapshot Using JavaPgxGraph G = session.readGraphAsOf( config, 1453315122685 )a
Load a Specific Snapshot Using PythonG = read_graph_as_of(config, creation_timestamp=1453315122685)
Parent topic: Graph Versioning