Path Traversals

Path traversals map traversal steps to a location to use in the event that a previous location must be revisited.

This path traversal starts at an ingredient, traverses to a recipe, and eventually finds a book that contains the recipe with the ingredients specified.

g.V().hasLabel('ingredient').has('name',within('beef','carrots')).
   in().as('Recipe').
   out().hasLabel('book').as('Book').
   select('Book','Recipe').
      by('name').
      by('name').
   path()

The output for this traversal lists each result:

==>path[v[dseg:/ingredient/3028], v[dseg:/recipe/2007], v[dseg:/book/1004], 
{Book=The Art of Simple Food: Notes, Lessons, and Recipes from a Delicious Revolution, Recipe=Carrot Soup}]
==>path[v[dseg:/ingredient/3001], v[dseg:/recipe/2001], v[dseg:/book/1001], 
{Book=The Art of French Cooking, Vol. 1, Recipe=Beef Bourguignon}]

Another path traversal creates a tree that emanates from a vertex label, in this case a book.

g.V().hasLabel('book').in().tree().by('name').next()

The output for this traversal lists each result:

==>Simca's Cuisine: 100 Classic French Recipes for Every Occasion={Simone BECK={}, Patricia SIMON={}}
==>The Art of French Cooking, Vol. 1={Julia CHILD={}, Beef Bourguignon={}, Salade Nicoise={}, Simone BECK={}}
==>The Art of Simple Food: Notes, Lessons, and Recipes from a Delicious Revolution={Kelsie KERR={}, Alice WATERS={}, Carrot Soup={}, Patricia CURTAN={}, Fritz STREIFF={}}
==>The French Chef Cookbook={Julia CHILD={}}

Each book lists the authors and recipes that are included in the book.

Another tree traversal discovers all the vertices that are on outgoing tree branch from a recipe that attach with an includes edge.

g.V().hasLabel('recipe').out('includes').tree().next()

The output for this traversal lists each result:

==>Roast Pork Loin={red wine={}, pork loin={}, chicken broth={}}
==>Spicy Meatloaf={bacon={}, celery={}, pork sausage={}, onion={}, ground beef={}, green bell pepper={}}
==>Beef Bourguignon={mashed garlic={}, butter={}, onion={}, tomato paste={}, beef={}}
==>Carrot Soup={butter={}, onion={}, chicken broth={}, carrots={}, thyme={}}
==>Rataouille={mashed garlic={}, yellow onion={}, olive oil={}, zucchini={}, eggplant={}}
==>Salade Nicoise={tuna={}, hard-boiled egg={}, olive oil={}, tomato={}, green beans={}}
==>Wild Mushroom Stroganoff={mushrooms={}, yellow onion={}, egg noodles={}}
==>Oysters Rockefeller={oyster={}, chervil={}, parsley={}, celery={}, fennel={}, shallots={}, Pernod={}}

Each recipe lists the ingredients required to make the recipe.

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