Chapter 25. Advanced Schema

This page describes some of the advanced schema definition options that Titan provides. For general information on Titan’s schema and how to define it, refer to Chapter 5, Schema and Data Modeling.

25.1. Static Vertices

Vertex labels can be defined as static which means that vertices with that label cannot be modified outside the transaction in which they were created.

mgmt = g.openManagement()
tweet = mgmt.makeVertexLabel('tweet').setStatic().make()

Static vertex labels are a method of controlling the data lifecycle and useful when loading data into the graph that should not be modified after its creation.

25.2. Edge and Vertex TTL

Edge and vertex labels can be configured with a time-to-live (TTL). Edges and vertices with such labels will automatically be removed from the graph when the configured TTL has passed after their initial creation. TTL configuration is useful when loading a large amount of data into the graph that is only of temporary use. Defining a TTL removes the need for manual clean up and handles the removal very efficiently. For example, it would make sense to TTL event edges such as user-page visits when those are summarized after a certain period of time or simply no longer needed for analytics or operational query processing.

The following storage backends support vertex and edge label TTL.

  1. Vertex and Edge Label Time-to-Live support

    • Cassandra

25.2.1. Edge TTL

Edge TTL is defined on a per-edge label basis, meaning that all edges of that label have the same time-to-live.

mgmt = g.openManagement()
visits = mgmt.makeEdgeLabel('visits').make()

Note, that modifying an edge resets the TTL for that edge. Also note, that the TTL of an edge label can be modified but it might take some time for this change to propagate to all running Titan instances which means that two different TTLs can be temporarily in use for the same label.

25.2.2. Property TTL

Property TTL is very similar to edge TTL and defined on a per-property key basis, meaning that all properties of that key have the same time-to-live.

mgmt = g.openManagement()
sensor = mgmt.makePropertyKey('sensor').cardinality(Cardinality.LIST).dataType(Double.class).make()

As with edge TTL, modifying an existing property resets the TTL for that property and modifying the TTL for a property key might not immediately take effect.

25.2.3. Vertex TTL

Vertex TTL is defined on a per-vertex label basis, meaning that all vertices of that label have the same time-to-live. The configured TTL applies to the vertex, its properties, and all incident edges to ensure that the entire vertex is removed from the graph. For this reason, a vertex label must be defined as static before a TTL can be set to rule out any modifications that would invalidate the vertex TTL. Vertex TTL only applies to static vertex labels.

mgmt = g.openManagement()
tweet = mgmt.makeVertexLabel('tweet').setStatic().make()

Note, that the TTL of a vertex label can be modified but it might take some time for this change to propagate to all running Titan instances which means that two different TTLs can be temporarily in use for the same label.

25.3. Multi-Properties

As dicussed in Chapter 5, Schema and Data Modeling, Titan supports property keys with SET and LIST cardinality. Hence, Titan supports multiple properties with the same key on a single vertex. Furthermore, Titan treats properties similarly to edges in that single-valued property annotations are allowed on properties as shown in the following example.

mgmt = g.openManagement()
v = g.addVertex()
p1 ='name','Dan LaRocque')
p2 ='name','dalaro')
==> Iterable over all name properties

These features are useful in a number of applications such as those where attaching provenance information (e.g. who added a property, when and from where?) to properties is necessary. Support for higher cardinality properties and property annotations on properties is also useful in high-concurrency, scale-out design patterns as described in Chapter 26, Eventually-Consistent Storage Backends._

Vertex-centric indexes and global graph indexes are supported for properties in the same manner as they are supported for edges. Refer to Chapter 8, Indexing for better Performance for information on defining these indexes for edges and use the corresponding API methods to define the same indexes for properties.

25.4. Unidirected Edges

Unidirected edges are edges that can only be traversed in the out-going direction. Unidirected edges have a lower storage footprint but are limited in the types of traversals they support. Unidirected edges are conceptually similar to hyperlinks in the world-wide-web in the sense that the out-vertex can traverse through the edge, but the in-vertex is unaware of its existence.

mgmt = g.openManagement()
link = mgmt.makeEdgeLabel('link').unidirected().make()

Unidirected edges can be added on edges and properties, thereby giving Titan limited support for hyper-edges. For example, this can be useful for capturing authorship provenance information for edges as shown in the following example, where we add a unidirected author edge on the knows edge to store the fact that user added this edge to the graph.

mgmt = g.openManagement()
user = g.v(4)
u = g.v(8)
v = g.v(16)

Note, that unidirected edges do not get automatically deleted when their in-vertices are deleted. The user must ensure that such inconsistencies do not arise or resolve them at query time by explicitly checking vertex existence in a transaction. See the discussion in Section 26.2.2, “Ghost Vertices” for more information.