1

How to find the cardinality of property in apache tinkerpop Gremlin?

Is there any method to find the given property cardinality is SET or SINGLE?

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
Thirumal
  • 8,280
  • 11
  • 53
  • 103

1 Answers1

0

Some database implementations allow you to set and query a schema, but Apache TinkerPop/Gremlin currently does not have a schema API. Further, the cardinality of a property value is not stored explicitly as something you can query.

The set and single cardinality keywords are only really used when properties are changed/created. They tell the query engine whether to replace the value, or add it in a set fashion.

Once added, Gremlin does not provide an explicit way to ask "is this property value part of a set?".

However, you can always count to find out. If the count is greater than one then you have a set or a list.

gremlin> g.addV('test').property('myset',1)
==>v[61407]

gremlin> g.V(61407).property(set,'myset',2)
==>v[61407]

gremlin> g.V(61407).values('myset').count()
==>2 
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38