PGX 20.2.2
Documentation

Publishing a Graph

This guide shows how to publish a graph so it can be referenced by other sessions. Similarly, the snapshots of a graph can also be made available to other sessions.

Recap: Loading a Graph

At first you need to load a graph. For detailed instructions, refer to the Graph Loading Guide.

var graph = session.readGraphWithProperties("examples/graphs/sample.csv.json", "myGraph")
import oracle.pgx.api.*;

PgxSession session = Pgx.createSession("my-session");
PgxGraph graph = session.readGraphWithProperties("examples/graphs/sample.csv.json", "myGraph");
session = pypgx.get_session("my-session")
G = session.read_graph_with_properties("examples/graphs/sample.csv.json",graph_name="myGraph")

The chosen graph name needs to be unique within the session.

Publishing a Graph with Snapshots

Now that you have a loaded graph, you can publish it and all its current and future snapshots via the publishWithSnapshots() method, which makes all the graph snapshots available to all sessions under the same name, regardless of how snapshots are added to the graph. When a graph is published with snapshots, the GraphMetaData information (see Graph Versioning for more information) of each snapshot is also made available to the other sessions, with the exception of the graph configuration (see Graph Configuration), which is null.

With publishing, all persistent properties of all snapshots are also published and made visible to the other sessions, while transient properties are session-private and thus should be published explicitly (see here for an explanation of properties types). Once published, all properties become read-only. Hence, transient properties are not published when calling publishWithSnapshots() without arguments.

Publishing a graph will move the graph name from the session-private namespace to the public namespace; see the reference here for more information about namespaces. If a graph with the same name has been published already, the publishWithSnapshots() method will fail with an exception.

graph.publishWithSnapshots()
graph.publishWithSnapshots();
publish_with_snapshots(self)

If you want to publish specific transient properties, you should list them within the publishWithSnapshots() call, as in the following example.

var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
prop.fill(0)
var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
cost.fill(0d)
graph.publishWithSnapshots(List.of(prop1), List.of(cost))
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop.fill(0);
EdgeProperty<Double> cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost");
cost.fill(0d);
List<VertexProperty<Integer, Integer> vertexProps = Arrays.asList(prop);
List<EdgeProperty<Double>> edgeProps = Arrays.asList(cost);
graph.publishWithSnapshots(vertexProps, edgeProps);

Note that the published properties, like the original transient properties, are associated to the specific snapshot they had been created on, so they are not visible on other snapshots.

Publishing a Single Graph Snapshot

PGX offers a separate publish() API to only publish one specific snapshot of a graph. This method will only make the current snapshot of that graph visible to other sessions. See the Graph Versioning programming guide on how to set the current snapshot for a certain graph.

As with publishWithSnapshots(), calling publish() without arguments publishes the snapshot with its persistent properties but does not publish transient properties.

Similarly to publishing with snapshots, this operation will move the graph name from the session-private namespace to the public namespace; see the reference here for more information about namespaces. If a graph with the same name has been already published, the publish() method will fail with an exception. Note that graphs published with snapshots and single published snapshots share the same namespace.

graph.publish()
graph.publish();
graph.publish()

If you want to publish specific transient properties, you should list them within the publish() call.

var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
prop.fill(0)
var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
cost.fill(0d)
graph.publish(List.of(prop1), List.of(cost))
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop.fill(0);
EdgeProperty<Double> cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost");
cost.fill(0d);
List<VertexProperty<Integer, Integer> vertexProps = Arrays.asList(prop);
List<EdgeProperty<Double>> edgeProps = Arrays.asList(cost);
graph.publish(vertexProps, edgeProps);
prop = graph.create_vertex_property("integer", "prop1")
prop.fill(0)
cost = graph.create_edge_property("double", "cost")
cost.fill(0d)
vertex_props = [prop]
edge_props = [cost]
graph.publish(vertex_props, edge_props)

Referencing a Published Graph from Another Session

Other sessions can reference a published graph by its name via the getGraph() method of the session object.

var session2 = instance.createSession("session2")
var graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph")
PgxSession session2 = instance.createSession("session2");
PgxGraph graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph");
session2 = pypgx.get_session("session2");
PgxGraph graph2 = session2.get_graph("myGraph")

session2 now has a reference to the published graph of session1 called myGraph. If the graph has been published without snapshots, session2 can see only the published snapshot: calls to the getAvailableSnapshots() method of session2 return an empty queue.

Instead, if also the snapshots have been published, the call to getGraph() returns the most recent snapshot available; as usual, session2 can see all the available snapshots via getAvailableSnapshots() and set a specific one via the setSnapshot() method of PgxSession. For more information about snapshots, you can read Graph Versioning.

As for every graph you reference, you should remember to release it when you do not need it anymore, as explained in the Graph Deletion section.

Publishing a Property

After publishing (a single snapshot or all of them), you can still publish transient properties individually:

graph.getVertexProperty("prop1").publish()
graph.getEdgeProperty("cost").publish()
graph.getVertexProperty("prop1").publish();
graph.getEdgeProperty("cost").publish();
graph.get_vertex_property("prop1").publish()
graph.get_edge_property("cost").publish()

Note that, as before, the published properties are associated to the specific snapshot they have been created on and thus visible only on that snapshot.

Getting a Published Property in Another Session

Sessions referencing a published graph (with or without snapshots) can reference a published property via the usual getVertexProperty/getEdgeProperty calls of PgxGraph.

var session2 = instance.createSession("session2")
var graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph")
var vertexProperty = graph2.getVertexProperty("prop1")
var edgeProperty = graph2.getEdgeProperty("cost")
PgxSession session2 = instance.createSession("session2");
PgxGraph graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph");
VertexProperty<Integer, Integer> vertexProperty = graph2.getVertexProperty("prop1");
EdgeProperty<Double> edgeProperty = graph2.getEdgeProperty("cost");
session2 = pypgx.get_session(session_name ="session2")
graph2 = session2.get_graph("myGraph")
vertex_property = graph2.get_vertex_property("prop1")
edge_property = graph2.get_edge_property("cost")

session2 now has a reference to the published graph of session1 called myGraph and can reference its published properties via myGraph itself.

Read more about PGX APIs here.