| Jan | FEB | Mar |
| 03 | ||
| 2019 | 2020 | 2021 |
COLLECTED BY
Collection: Wikipedia Eventstream
mgmt.printIndexes(), mgmt.printPropertyKeys(), mgmt.printVertexLabels(), and mgmt.printEdgeLabels().
There is also a method that displays all the combined output named printSchema().
1 2 | mgmt = graph.openManagement() mgmt.printSchema() |
friend
between vertices A and B encodes a friendship between the two
individuals.
To define an edge label, call makeEdgeLabel(String) on an open graph
or management transaction and provide the name of the edge label as the
argument. Edge label names must be unique in the graph. This method
returns a builder for edge labels that allows to define its
multiplicity. The multiplicity of an edge label defines a
multiplicity constraint on all edges of this label, that is, a maximum
number of edges between pairs of vertices. JanusGraph recognizes the
following multiplicity settings.
mother is an example with MANY2ONE multiplicity since
each person has at most one mother but mothers can have multiple
children.
●ONE2MANY: Allows at most one incoming edge of such label on any
vertex in the graph but places no constraint on outgoing edges. The
edge label winnerOf is an example with ONE2MANY multiplicity since
each contest is won by at most one person but a person can win
multiple contests.
●ONE2ONE: Allows at most one incoming and one outgoing edge of
such label on any vertex in the graph. The edge label marriedTo is
an example with ONE2ONE multiplicity since a person is married to
exactly one other person.
The default multiplicity is MULTI. The definition of an edge label is
completed by calling the make() method on the builder which returns
the defined edge label as shown in the following example.
1 2 3 4 | mgmt = graph.openManagement() follow = mgmt.makeEdgeLabel('follow').multiplicity(MULTI).make() mother = mgmt.makeEdgeLabel('mother').multiplicity(MANY2ONE).make() mgmt.commit() |
name='Daniel' has the key name and the value 'Daniel'.
Property keys are part of the JanusGraph schema and can constrain the
allowed data types and cardinality of values.
To define a property key, call makePropertyKey(String) on an open
graph or management transaction and provide the name of the property key
as the argument. Property key names must be unique in the graph, and it
is recommended to avoid spaces or special characters in property names.
This method returns a builder for the property keys.
Note
During property key creation, consider creating also graph indices for better
performance, see Index Performance.
dataType(Class) to define the data type of a property key.
JanusGraph will enforce that all values associated with the key have the
configured data type and thereby ensures that data added to the graph is
valid. For instance, one can define that the name key has a String
data type.
Define the data type as Object.class in order to allow any
(serializable) value to be associated with a key. However, it is
encouraged to use concrete data types whenever possible. Configured data
types must be concrete classes and not interfaces or abstract classes.
JanusGraph enforces class equality, so adding a sub-class of a
configured data type is not allowed.
JanusGraph natively supports the following data types.
Native JanusGraph Data Types
| Name | Description |
|---|---|
| String | Character sequence |
| Character | Individual character |
| Boolean | true or false |
| Byte | byte value |
| Short | short value |
| Integer | integer value |
| Long | long value |
| Float | 4 byte floating point number |
| Double | 8 byte floating point number |
| Date | Specific instant in time (java.util.Date) |
| Geoshape | Geographic shape like point, circle or box |
| UUID | Universally unique identifier (java.util.UUID) |
cardinality(Cardinality) to define the allowed cardinality of the
values associated with the key on any given vertex.
●SINGLE: Allows at most one value per element for such key. In
other words, the key→value mapping is unique for all elements in the
graph. The property key birthDate is an example with SINGLE
cardinality since each person has exactly one birth date.
●LIST: Allows an arbitrary number of values per element for such
key. In other words, the key is associated with a list of values
allowing duplicate values. Assuming we model sensors as vertices in
a graph, the property key sensorReading is an example with LIST
cardinality to allow lots of (potentially duplicate) sensor readings
to be recorded.
●SET: Allows multiple values but no duplicate values per element
for such key. In other words, the key is associated with a set of
values. The property key name has SET cardinality if we want to
capture all names of an individual (including nick name, maiden
name, etc).
The default cardinality setting is SINGLE. Note, that property keys used
on edges and properties have cardinality SINGLE. Attaching multiple
values for a single key on an edge or property is not supported.
1 2 3 4 5 | mgmt = graph.openManagement() birthDate = mgmt.makePropertyKey('birthDate').dataType(Long.class).cardinality(Cardinality.SINGLE).make() name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SET).make() sensorReading = mgmt.makePropertyKey('sensorReading').dataType(Double.class).cardinality(Cardinality.LIST).make() mgmt.commit() |
1 2 3 4 5 | mgmt = graph.openManagement() if (mgmt.containsRelationType('name')) name = mgmt.getPropertyKey('name') mgmt.getRelationTypes(EdgeLabel.class) mgmt.commit() |
addVertex methods use JanusGraph’s
default label.
To create a label, call makeVertexLabel(String).make() on an open
graph or management transaction and provide the name of the vertex label
as the argument. Vertex label names must be unique in the graph.
1 2 3 4 5 6 7 8 | mgmt = graph.openManagement() person = mgmt.makeVertexLabel('person').make() mgmt.commit() // Create a labeled vertex person = graph.addVertex(label, 'person') // Create an unlabeled vertex v = graph.addVertex() graph.tx().commit() |
DefaultSchemaMaker configured for the JanusGraph graph defines such
types.
By default, implicitly created edge labels have multiplicity MULTI and
implicitly created property keys have cardinality SINGLE and data type
Object.class. Users can control automatic schema element creation by
implementing and registering their own DefaultSchemaMaker.
When defining a cardinality for a vertex property which differs from SINGLE,
the cardinality should be used for all values of the vertex property in the
first query (i.e. the query which defines a new vertex property key).
It is strongly encouraged to explicitly define all schema elements and
to disable automatic schema creation by setting schema.default=none in
the JanusGraph graph configuration.
JanusGraphManagement.changeName(JanusGraphSchemaElement, String) as
shown in the following example where the property key place is renamed
to location.
1 2 3 4 | mgmt = graph.openManagement() place = mgmt.getPropertyKey('place') mgmt.changeName(place, 'location') mgmt.commit() |
god can be a brother of another god, but not of a monster and a god can have a property age, but location can not have a property age. These constraints are disabled by default.
Enable these schema constraints by setting schema.constraints=true. This setting depends on the setting schema.default. If config schema.default is set to none, then an IllegalArgumentException is thrown for schema constraint violations. If schema.default is not set none, schema constraints are automatically created, but no exception is thrown.
Activating schema constraints has no impact on the existing data, because these schema constraints are only applied during the insertion process. So reading of data is not affected at all by those constraints.
Multiple properties can be bound to a vertex using JanusGraphManagement.addProperties(VertexLabel, PropertyKey...), for example:
1 2 3 4 5 6 | mgmt = graph.openManagement() person = mgmt.makeVertexLabel('person').make() name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SET).make() birthDate = mgmt.makePropertyKey('birthDate').dataType(Long.class).cardinality(Cardinality.SINGLE).make() mgmt.addProperties(person, name, birthDate) mgmt.commit() |
JanusGraphManagement.addProperties(EdgeLabel, PropertyKey...), for example:
1 2 3 4 5 | mgmt = graph.openManagement() follow = mgmt.makeEdgeLabel('follow').multiplicity(MULTI).make() name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SET).make() mgmt.addProperties(follow, name) mgmt.commit() |
JanusGraphManagement.addConnection(EdgeLabel, VertexLabel out, VertexLabel in) between an outgoing, an incoming and an edge, for example:
1 2 3 4 5 6 | mgmt = graph.openManagement() person = mgmt.makeVertexLabel('person').make() company = mgmt.makeVertexLabel('company').make() works = mgmt.makeEdgeLabel('works').multiplicity(MULTI).make() mgmt.addConnection(works, person, company) mgmt.commit() |