Search code examples
gremlinamazon-neptunetinkerpop3gremlin-java

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


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?


Solution

  • 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