1
votes

I want to add property constraint on a specific vertex label to disallow null values or insertion of a vertex without specific properties

I added the name property to the person vertex as below, so the person will not take other properties except name but I need to add constraint on the value so it can not be null

mgmt = graph.openManagement()
person = mgmt.makeVertexLabel('person').make()
name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SET).make()
mgmt.addProperties(person, name)
mgmt.commit()

The Problem is :

A vertex with label person requires existence of a name property always. Or this vertex should not be created .

Is this achievable in janusgraph?

1

1 Answers

4
votes

It is currently not possible to enforce the presence of certain property keys for certain vertex or edge labels in JanusGraph. However, this would be a good addition for the schema constraints that were introduced in JanusGraph 0.3.0. So, feel free to create an issue with JanusGraph for this feature request.

Until something like this is implemented in JanusGraph, you probably have to implement a logic to enforce this in your application that inserts the data.

If you for some reason cannot or don't want to implement this in your application (e.g. because you don't control all applications that insert data in your graph), then you could also implement your own TinkerPop TraversalStrategy that checks every addV step to ensure that the property is also added. These strategies are evaluated for all traversals and can change (e.g. as an optimization) the steps of the traversal or even throw an exception if the traversal is not legal which would be the correct behaviour in your case. JanusGraph itself would probably also implement a strategy to add these additional schema constraints.