local

Limit the operation of the traversal to a single element within the traversal.

Synopsis

local(traversal)

Description

The local() step is a branch step that allows the action within the step to be applied to the element within the local() step.

Examples

Get a list of all people and the countries they have lived in, ordered by the year that the person started living in the country:

g.V().hasLabel('person').as('person').
   local(properties('country').order().by('startYear', incr).limit(2)).value().as('country').
   select('person','country').
      by('name').by()

Here, local() is used to restrict the sorting by the meta-property startYear for each person.

g.V().has('person','personId','1').local(outE('created').has('createDate', gte('1962-03-03')).order().by('createDate'))
// explain
//g.V().hasLabel('person').outE('reviewed').has('stars', gte(1)).order().by('stars').profile()
// Sorts the reviews by stars for each user - uses the edge index
//g.V().hasLabel('person').local(outE('reviewed').has('stars', gte(1)).order().by('stars')).profile()
// Sorts the users by name, and then their reviews by stars
//g.V().hasLabel('person').order().by('name').local(outE('reviewed').has('stars', gte(1)).order().by('stars')).profile()

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