14.8.5 Checking Out Different Snapshots of a Graph

You can also check out a specific snapshot, again using the PgxSession.setSnapshot().

For example, consider the following two snapshots of a graph:

==> 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]

To check out a specific snapshot of the graph, you must pass the creationTimestamp of the snapshot you want to load to setSnapshot().

For example, if G is pointing to the newest graph with 5 vertices and 5 edges, but you want to analyze the older graph, you need to set the snapshot to 1453315122685.

opg4j> G.getNumVertices()
==> 5
opg4j> G.getNumEdges()
==> 5
opg4j> session.setSnapshot( G, 1453315122685 )
==> null
opg4j> G.getNumVertices()
==> 4
opg4j> G.getNumEdges()
==> 4
session.setSnapshot(G,1453315122685);
session.set_snapshot(G,1453315122685)

Note that setting the snapshot, changes the number of vertices and edges from 5 to 4.

Alternatively, you can also retrieve the creation timestamp of each snapshot from its associated GraphMetaData object via the GraphMetaData.getCreationTimestamp() method. The easiest way to get the GraphMetaData information of all the snapshots is to use the PgxSession.getAvailableSnapshots() method, which returns a collection of GraphMetaData information of each snapshot ordered by creation timestamp from the most recent to the oldest.