Reputation: 1886
i' have created label schema using graph.OpenManagement() as described in https://docs.janusgraph.org/basics/schema/#schema-constraints
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()
How can I get the person
label schema. What is the gremlin query to get the properties list along with the datatype and cardinality info for a label.
Im using the following query to get the properties list with the data type, but there is no map for property to the label
gremlin> mgmt.printPropertyKeys()
==>------------------------------------------------------------------------------------------------
Property Key Name | Cardinality | Data Type |
---------------------------------------------------------------------------------------------------
name2 | SINGLE | class java.lang.String |
age2 | SINGLE | class java.lang.Integer |
name3 | SET | class java.lang.String |
birthDate3 | SINGLE | class java.lang.Long |
name4 | SET | class java.lang.String |
birthDate4 | SINGLE | class java.lang.Long |
name6 | SINGLE | class java.lang.String |
age6 | SINGLE | class java.lang.Integer |
name5 | SINGLE | class java.lang.String |
age5 | SINGLE | class java.lang.Integer |
mean_radius | SINGLE | class java.lang.Integer |
distance_in_kms | SINGLE | class java.lang.Integer |
new_field | SINGLE | class java.lang.String |
radius_in_kms | SINGLE | class java.lang.Integer |
name | SINGLE | class java.lang.String |
---------------------------------------------------------------------------------------------------
Upvotes: 1
Views: 737
Reputation: 3744
Getting vertex labels and their basic information:
mgmt.getVertexLabels().forEach(vertexLabel -> {
System.out.println("Vertex label: "+vertexLabel.name()+" isPartitioned: "+vertexLabel.isPartitioned()+" isStatic: "+vertexLabel.isStatic());
});
Getting edge labels and their basic information:
mgmt.getRelationTypes(EdgeLabel.class).forEach(edgeLabel ->{
System.out.println("Edge label: "+edgeLabel.name()+" Multiplicity: "+edgeLabel.multiplicity().name()+" isUnidirected:"+edgeLabel.isUnidirected());
});
Getting properties and their basic information:
mgmt.getRelationTypes(PropertyKey.class).forEach(propertyKey -> {
System.out.println("Property key: "+propertyKey.name()+" Cardinality: "+propertyKey.cardinality().name()+" Datatype: "+propertyKey.dataType().getName());
});
Now, when you got a specific Vertex label or a specific Edge label (as shown above), you can ask for the schema constraints information as shown below. Same methods are available for both VertexLabel
and EdgeLabel
.
Getting vertex label properties:
VertexLabel vertexLabel = mgmt.getVertexLabel("myVertexLabel");
vertexLabel.mappedProperties().forEach(propertyKey -> {
// get information about `propertyKey` as shown above in `Getting properties and their basic information` section
});
Getting vertex label connections:
VertexLabel vertexLabel = mgmt.getVertexLabel("myVertexLabel");
vertexLabel.mappedConnections().forEach(connection -> {
// connection.getEdgeLabel() - return the label of the edge. You can use it to access the edge itself if needed like:
EdgeLabel edgeLabel = mgmt.getEdgeLabel(connection.getEdgeLabel());
// You can access JanusGraphEdge via:
JanusGraphEdge janusGraphEdge = connection.getConnectionEdge();
// Having JanusGraphEdge you can access EdgeLabel directly via:
edgeLabel = janusGraphEdge.edgeLabel();
// You can also access incoming or outgoing vertices of this connection via: connection.getIncomingVertexLabel() or connection.getOutgoingVertexLabel()
});
Upvotes: 3