16.2.3 Publishing a Graph
You can publish a graph that can be referenced by other sessions.
Publishing a Single Graph Snapshot
The PgxGraph#publish()
method can be used to publish the
current selected snapshot of the graph. The publish operation will move the graph
name from the session-private namespace to the public namespace. If a graph with the
same name has been already published, then the publish()
method
will fail with an exception. Graphs published with snapshots and single published
snapshots share the same namespace.
Table 14-5 describes the grants required to publish a graph.
Note that calling the publish()
method without arguments
publishes the snapshot with its persistent properties only. However, if you want to
publish specific transient properties, then you must list them within the
publish()
call as shown:
opg4j> var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
opg4j> prop1.fill(0)
opg4j> var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
opg4j> cost.fill(0d)
opg4j> graph.publish(List.of(prop1), List.of(cost))
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop1.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")
prop1.fill(0)
cost = graph.create_edge_property("double", "cost")
cost.fill(0d)
vertex_props = [prop]
edge_props = [cost]
graph.publish(vertex_props, edge_props)
Publishing a Graph with Snapshots
If you want to make all snapshots of the graph
visible to other sessions, then use the publishWithSnapshots()
method. When a graph is published with snapshots, the GraphMetaData
information of each snapshot is also made available to the other sessions, with the
exception of the graph configuration, which is null
.
When calling the publishWithSnapshots()
method, all
the persistent properties of all the snapshots are published and made visible to the
other sessions. Transient properties are session-private and therefore they must be
published explicitly. Once published, all properties become read-only.
Similar
to publishing a single graph snapshot, the publishWithSnapshots()
method will move the graph name from the session-private namespace to the public
namespace. If a graph with the same name has been already published, then the
publishWithSnapshots()
method will fail with an exception.
If you want to publish specific transient
properties, you should list them within the publishWithSnapshots()
call, as in the following example:
opg4j> var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
opg4j> prop1.fill(0)
opg4j> var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
opg4j> cost.fill(0d)
opg4j> graph.publishWithSnapshots(List.of(prop1), List.of(cost))
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop1.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);
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
prop1.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)
Referencing a Published Graph from Another Session
You can reference a published graph by its name in another session,
using the PgxSession#getGraph()
method.
The following example references a published graph
myGraph
in a new session (session2
):
opg4j> var session2 = instance.createSession("session2")
opg4j> 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
can access only the published snapshot. If the graph has
been published without snapshots, calling the
getAvailableSnapshots()
method will return an empty queue.
In case if the graph snapshots have been published, then the call to
getGraph()
returns the most recent available snapshot.
session2
can see all the available snapshots through the
getAvailableSnapshots()
method. You can then set a specific
snapshot using the PgxSession#setSnapshot()
method.
Note:
If a referenced graph is not required anymore, then it is important that you release the graph. See Deleting a Graph for more information.Publishing a Property
After publishing (a single snapshot or all of them), you can still publish transient properties individually. Published properties are associated to a specific snapshot on which they are created, and hence visible only on that snapshot.
opg4j> graph.getVertexProperty("prop1").publish()
opg4j> graph.getEdgeProperty("cost").publish()
graph.getVertexProperty("prop1").publish();
graph.getEdgeProperty("cost").publish();
graph.get_vertex_property("prop1").publish()
graph.get_edge_property("cost").publish()
Getting a Published Property in Another Session
Sessions referencing a published graph (with or without snapshots) can reference a published property through the
PgxGraph#getVertexProperty
and
PgxGraph#getEdgeProperty
.
opg4j> var session2 = instance.createSession("session2")
opg4j> var graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph")
opg4j> var vertexProperty = graph2.getVertexProperty("prop1")
opg4j> 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")
Pinning a Published Graph
You can pin a published graph so that it remains published even if no session uses it.
opg4j> graph.pin()
graph.pin();
>>> graph.pin()
Unpinning a Published Graph
You can unpin a published graph that was earlier pinned. By doing this, you can remove the graph and all its snapshots, if no other session is using a snapshot of the graph.
opg4j> var graph = session.getGraph("bank_graph_analytics")
graph ==> PgxGraph[name=bank_graph_analytics,N=999,E=4993,created=1660217577201]
opg4j> graph.unpin()
PgxGraph graph = session.getGraph("bank_graph_analytics");
graph.unpin();
>>> graph = session.get_graph("bank_graph_analytics")
>>> graph.unpin()
Related Topics
Parent topic: Graph Management in the Graph Server (PGX)