14.8.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:

  1. Get a graph configuration for the graph:
    opg4j> var config = GraphConfigFactory.forAnyFormat().fromPath("<path_to_json>")
    ==> {"format":"adj_list", ... }
    GraphConfig config = GraphConfigFactory.forAnyFormat().fromPath("<path_to_json>");
    config = GraphConfigFactory.for_any_format().from_path("<path_to_json>")
  2. Check the loaded snapshots for this graph config using getAvailableSnapshots():
    opg4j> 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]
    Deque<GraphMetaData> snapshots = session.getAvailableSnapshots(G);
    session.get_available_snapshots(G)
  3. Check out the snapshot of the graph which has 4 vertices and 4 edges and having the timestamp 1453315122685:
    opg4j> 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
    PgxGraph G = session.readGraphAsOf( config, 1453315122685 );
    G = read_graph_as_of(config, creation_timestamp=1453315122685)