Branching Traversals

Branching traversals allow decision points to be inserted into the traversal processing. Prior to trying out branching traversals shown here, you must create the data as described in Simple Traversals.

This branching traversal example chooses between two labels, either author or reviewer to fork the traversal. If the vertex label is author, the edges labeled created are counted. If the vertex label is reviewer, the edges labeled rated are counted.

g.V().choose(label()).
  option('author', out('created').count()).
  option('reviewer', out('rated').count())

The output for this traversal lists each result, the count returned. This type of traversal is useful as an intermediary step in a query process, but clearly the output is not useful without reference.

==>0
==>0
==>2
==>0
==>0
==>0
==>2
==>1
==>0
==>0
==>0
==>3
==>0
==>2
==>2
==>1
==>2

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