This guide will explain to you how a graph loaded into memory can be saved to disk in various formats. By doing this, you can make sub-graphs and graph data computed at runtime through analytics persistent, for future use. The resulting file can be used later as input for PGX.
Java and Shell only
PGX does not currently support storing graphs over HTTP/REST.
First, load a graph into memory and perform a PageRank analysis on it, to provide something interesting to save. To do so, you need create a new vertex property that will receive the PageRank values:
var g = session.readGraphWithProperties("examples/graphs/connections.edge_list.json") var rank = analyst.pagerank(g, 0.001, 0.85, 100)
PgxGraph g = session.readGraphWithProperties("examples/graphs/connections.edge_list.json"); Analyst analyst = session.createAnalyst(); VertexProperty<Integer, Double> rank = analyst.pagerank(g, 0.001, 0.85, 100);
Next, store the graph, together with the result of the PageRank analysis and all original edge properties, as a file in edge-list format, on disk. When a graph is stored, you need to specify the graph format, a path where the file should be stored, the properties to store and a flag that specifies whether or not a file should be overwritten should a file with the same name already exist.
var config = g.store(Format.EDGE_LIST, "/tmp/connections_pagerank.elist", List.of(rank), EdgeProperty.ALL, false)
FileGraphConfig config = g.store(Format.EDGE_LIST, "/tmp/sample_pagerank.elist", Collections.singletonList(rank), EdgeProperty.ALL, false);
The graph data can now be found under
/tmp/connections_pagerank.elist. The graph configuration returned by the
store method can be used to load the new graph back into memory. To persist the graph configuration to disk as well,
you can use the config's
toString method to get a JSON representation:
var path = Paths.get("/tmp/connections_pagerank.elist.json") Files.writeString(path, config.toString())
import apache.commons.io.*; // PGX contains a version of Apache Commons IO ... FileUtils.write(new File("/tmp/connections_pagerank.elist.json"), config.toString());