Managing Transient Properties and Collections

PGX allows each client to maintain its own isolated workspace, called session. Clients may create additional data objects in their own session, which they can then use for analysis.

Transient Properties

PGX adopts the Property Graph data model. Once a graph is loaded into PGX, the graph instance itself and its original properties are set as immutable. However, the client can create and attach additional properties to the graph dynamically. These extra properties are referred to as transient properties and are mutable by the client.

The methods for creating transient properties are available in PgxGraph:

1graph.create_vertex_property(data_type, name=None)

The data_type argument is an enum for the data type of the property, which must be one of the primitive types supported by PGX.

name is an optional argument to assign a unique name to the newly created property. If no name is specified, PGX will assign one to the client. Note that names must be unique. There cannot be two different vertex/edge properties for the same graph and with the same name.

All methods return a PgxProperty object, which represent the newly created transient property. Both of the underlying classes, VertexProperty and EdgeProperty, are parametrized with the value type V the property holds. V matches the given PgxProperty. VertexProperty is additionally parametrized with the vertex ID type. This is due to PGX support of several types of vertex identifiers. EdgeProperty is not parameterized with the edge ID type, because PGX only supports edge identifiers of type long.

Example:

1G = session.read_graph_with_properties(config)
2p1 = G.create_vertex_property("string")
3p2 = G.create_edge_property("double")

To delete a transient property from the session, call destroy() on the property object.

Collections and Scalars

The client can create graph-bound vertex and edge collections to use during the analysis with the following methods in PgxGraph:

1graph.create_edge_sequence(name=None)
2graph.create_vertex_sequence(name=None)
3graph.create_edge_set(name=None)
4graph.create_edge_sequence(name=None)

PGX also supports scalar collections such as set and sequence. Each of these collections can hold elements of various primitive data types like INTEGER, FLOAT or BOOLEAN. Scalar collections are session-bound and can be created with the following methods in PgxSession:

1create_set(content_type, name=None)
2create_sequence(content_type, name=None)

The optional argument (name) specifies the name of the newly created collection. If omitted, PGX chooses a name for the client. As with properties, the collections holding vertices are parametrized with the ID type of the vertices.

The return value is the collection object which points to the newly created empty collection.

To drop a collection from the session, call destroy() on the collection object.

To check which collections are currently allocated for a graph you can use the following method:

1graph.get_collections()

The returned map contains the names of the collections as keys and the collections as values. The collections can be casted to the matching collection subclass.

PGX supports special Map collection types and allows users to map between different data types. Maps can be created using PgxGraph or PgxSession APIs, the difference is that the latter supports only non graph-related types, and that the created maps directly depend on the session:

1graph.create_map(key_type, value_type, name=None)

Similarly, scalar variables can be created in the client session using the following methods:

1graph.create_scalar(data_type, name=None)

These collections and scalar variables can then be passed as arguments to graph algorithms.