Discovering properties about graphs and traversals

After schema and data are inserted into a graph, it is important to verify that the information is correct. Checking simple information about inserted data is a good way to get started with traversals. The graph.schema() calls can be used to check how the graph is storing data.

  • Use the graph traversal instance g to check if data is loaded by checking the count of vertices. Note that the command is a remote command to Gremlin Server, as are all commands of discovery shown below.

    g.V().count()
    ==>56
  • Check the properties of a loaded vertex. Find all the information for the vertex with an name value of Julia Child.

    g.V().has('name','Julia Child').valueMap()
    ==>{gender=[F], name=[Julia Child]}
  • Check the properties of a loaded edge. Find all the information for the edges with a label of rated.

    g.E().hasLabel('rated').values()
    ==>5
    ==>Pretty tasty!
    ==>2014-01-01T00:00:00Z
  • Find the id information for vertices:

    g.V().hasLabel('FridgeSensor').id()
    ==>{~label=FridgeSensor, sensor_id=93c4ec9b-68ff-455e-8668-1056ebc3689f, city_id=santaCruz}
    ==>{~label=FridgeSensor, sensor_id=9c23b683-1de2-4c97-a26a-277b3733732a, city_id=sacramento}
    ==>{~label=FridgeSensor, sensor_id=eff4a8af-2b0d-4ba9-a063-c170130e2d84, city_id=sacramento}
  • Discover schema information using a describe() step. This traversal step provides a sorted list of the same information as the next alternative below.

    schema.describe()
    ==>schema.propertyKey("member_id").Smallint().single().create()
    schema.propertyKey("instructions").Text().single().create()
    schema.propertyKey("amount").Text().single().create()
    schema.propertyKey("gender").Text().single().create()
    schema.propertyKey("year").Int().single().create()
    schema.propertyKey("calories").Int().single().create()
    schema.propertyKey("stars").Int().single().create()
    schema.propertyKey("community_id").Int().single().create()
    schema.propertyKey("ISBN").Text().single().create()
    schema.propertyKey("name").Text().single().create()
    schema.propertyKey("comment").Text().single().create()
    schema.propertyKey("timestamp").Timestamp().single().create()
    schema.edgeLabel("authored").multiple().create()
    schema.edgeLabel("rated").multiple().properties("timestamp", "stars", "comment").create()
    schema.edgeLabel("includedIn").multiple().create()
    schema.edgeLabel("created").multiple().properties("year").create()
    schema.edgeLabel("includes").multiple().properties("amount").create()
    schema.vertexLabel("meal").properties("name", "timestamp", "calories").create()
    schema.vertexLabel("ingredient").properties("name").create()
    schema.vertexLabel("author").properties("name", "gender").create()
    schema.vertexLabel("book").properties("name", "year", "ISBN").create()
    schema.vertexLabel("recipe").properties("name", "instructions").create()
    schema.vertexLabel("reviewer").properties("name").create()
    schema.edgeLabel("authored").connection("author", "book").connection("book", "author").add()
    schema.edgeLabel("rated").connection("recipe", "reviewer").connection("reviewer", "recipe").add()
    schema.edgeLabel("includedIn").connection("meal", "recipe").connection("meal", "book").connection("book", "recipe").connection("book", "meal").connection("recipe", "book").connection("recipe", "meal").add()
    schema.edgeLabel("created").connection("author", "recipe").connection("recipe", "author").add()
    schema.edgeLabel("includes").connection("ingredient", "recipe").connection("recipe", "ingredient").add()
    gremlin> schema.edgeLabel('includes').describe()
    ==>schema.edgeLabel("includes").multiple().properties("amount").create()
    schema.edgeLabel("includes").connection("ingredient", "recipe").connection("recipe", "ingredient").add()
    gremlin> schema.vertexLabel('author').describe()
    ==>schema.vertexLabel("author").properties("name", "gender").create()
  • An alternative to discover schema information uses a valueMap() step on the traversal.

    schema.traversal().V().valueMap()
    ==>{mode=[Development]}
    ==>{name=[author]}
    ==>{name=[recipe]}
    ==>{name=[ingredient]}
    ==>{name=[book]}
    ==>{name=[meal]}
    ==>{name=[reviewer]}
    ==>{name=[byName], type=[Secondary]}
    ==>{name=[includedIn], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{name=[fridgeItem_single]}
    ==>{name=[rated], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{name=[fridgeItem_multiple]}
    ==>{dataType=[Timestamp], name=[timestamp], cardinality=[Single]}
    ==>{dataType=[Text], name=[ISBN], cardinality=[Single]}
    ==>{dataType=[Text], name=[category], cardinality=[Single]}
    ==>{name=[byLocation]}
    ==>{dataType=[Int], name=[year], cardinality=[Single]}
    ==>{name=[ratedByStars], directionality=[OUT]}
    ==>{dataType=[Text], name=[gender], cardinality=[Single]}
    ==>{unique=[false], name=[byIngredient], type=[Materialized]}
    ==>{dataType=[Text], name=[instructions], cardinality=[Single]}
    ==>{unique=[false], name=[byReviewer], type=[Materialized]}
    ==>{unique=[false], name=[byRecipe], type=[Materialized]}
    ==>{unique=[false], name=[byMeal], type=[Materialized]}
    ==>{dataType=[Int], name=[stars], cardinality=[Single]}
    ==>{dataType=[Text], name=[comment], cardinality=[Single]}
    ==>{dataType=[Int], name=[calories], cardinality=[Single]}
    ==>{dataType=[Text], name=[blah], cardinality=[Single]}
    ==>{dataType=[Text], name=[amount], cardinality=[Single]}
    ==>{name=[created], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{name=[includes], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{dataType=[Bigint], name=[member_id], cardinality=[Single]}
    ==>{name=[authored], directionality=[Bidirectional], cardinality=[Multiple]}
    ==>{dataType=[Text], name=[country], cardinality=[Multiple]}
    ==>{dataType=[Text], name=[item_mult], cardinality=[Multiple]}
    ==>{dataType=[Int], name=[community_id], cardinality=[Single]}
    ==>{dataType=[Text], name=[livedIn], cardinality=[Single]}
    ==>{dataType=[Text], name=[item_single], cardinality=[Single]}
    ==>{dataType=[Text], name=[name], cardinality=[Single]}

    Using valueMap() without specifying properties can result in slow query latencies, if a large number of property keys exist for the queried vertex or edge. Specific properties can be specified, such as valueMap('name')

  • Changing valueMap() to valueMap(true) adds the id for each field.

    graph.schema().traversal().V().valueMap(true)
    ==>{mode=[Development], id=0, label=schema}
    ==>{id=129, label=incident}
    ==>{id=133, label=incident}
    ==>{id=73, label=incident}
    ==>{id=137, label=incident}
    ==>{id=77, label=incident}
    ==>{id=141, label=incident}
    ==>{id=32784, dataType=[Text], name=[comment], label=propertyKey, cardinality=[Single]}
    ==>{id=32782, name=[rated], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=32783, dataType=[Int], name=[stars], label=propertyKey, cardinality=[Single]}
    ==>{id=85, label=incident}
    ==>{id=149, label=incident}
    ==>{id=32780, dataType=[Timestamp], name=[timestamp], label=propertyKey, cardinality=[Single]}
    ==>{id=32781, dataType=[Int], name=[calories], label=propertyKey, cardinality=[Single]}
    ==>{id=32769, dataType=[Smallint], name=[member_id], label=propertyKey, cardinality=[Single]}
    ==>{id=94, label=incident}
    ==>{id=32767, dataType=[Int], name=[community_id], label=propertyKey, cardinality=[Single]}
    ==>{id=98, label=incident}
    ==>{id=108, label=incident}
    ==>{id=32775, name=[authored], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=112, label=incident}
    ==>{id=32776, name=[created], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=1, name=[author], label=vertexLabel}
    ==>{id=32773, dataType=[Text], name=[ISBN], label=propertyKey, cardinality=[Single]}
    ==>{id=2, name=[book], label=vertexLabel}
    ==>{id=32774, dataType=[Text], name=[instructions], label=propertyKey, cardinality=[Single]}
    ==>{id=3, name=[recipe], label=vertexLabel}
    ==>{id=32771, dataType=[Text], name=[gender], label=propertyKey, cardinality=[Single]}
    ==>{id=4, name=[ingredient], label=vertexLabel}
    ==>{id=116, label=incident}
    ==>{id=32772, dataType=[Int], name=[year], label=propertyKey, cardinality=[Single]}
    ==>{id=5, name=[meal], label=vertexLabel}
    ==>{id=6, name=[reviewer], label=vertexLabel}
    ==>{id=32770, dataType=[Text], name=[name], label=propertyKey, cardinality=[Single]}
    ==>{id=32779, name=[includedIn], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=125, label=incident}
    ==>{id=32777, name=[includes], directionality=[Bidirectional], label=edgeLabel, cardinality=[Multiple]}
    ==>{id=32778, dataType=[Text], name=[amount], label=propertyKey, cardinality=[Single]}
  • Running traversal() will supply information about the number of schema element exist for vertices and edges, as well as the TraversalSource type.

    schema.traversal()
    ==>graphtraversalsource[tinkergraph[vertices:58 edges:106], standard]
  • A list of all vertex labels using utilities split() and grep().

    schema.describe().split('\n').grep(~/.*vertexLabel.*/)
    gremlin> schema.describe().split('\n').grep(~/.*vertexLabel.*/)
    ==>schema.vertexLabel("meal").properties("name", "timestamp", "calories").create()
    ==>schema.vertexLabel("ingredient").properties("name").create()
    ==>schema.vertexLabel("ingredient").index("byIngredient").materialized().by("name").add()
    ==>schema.vertexLabel("test").partitionKey("tester").clusteringKey("foor").create()
    ==>schema.vertexLabel("FridgeSensor").create()
    ==>schema.vertexLabel("author").properties("name", "gender", "nationality").create()
    ==>schema.vertexLabel("author").index("byName").secondary().by("name").add()
    ==>schema.vertexLabel("author").index("byAuthor").materialized().by("name").add()
    ==>schema.vertexLabel("FridgeItem").properties("name", "expiration_date", "amount").create()
    ==>schema.vertexLabel("book").properties("name", "year", "ISBN").create()
    ==>schema.vertexLabel("recipe").properties("name", "instructions").create()
    ==>schema.vertexLabel("recipe").index("byRecipe").materialized().by("name").add()
    ==>schema.vertexLabel("reviewer").properties("name").create()
    ==>schema.vertexLabel("reviewer").index("byReviewer").materialized().by("name").add()
    ==>schema.vertexLabel("reviewer").index("ratedByStars").outE("rated").by("stars").add()
  • Get the name of the current graph.

    graph.name()
    ==>quickstart

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com