简体   繁体   中英

Gremlin - run additional traversal in same query in case not enough values are found

Is there a way to check how many records were found, and in case less than X records were returned do another query?

For example first run this query ->

g.V().
  hasLabel('courseContent').
  has('status', 'active').as('cc').
  outE('ccBelongsToCourse').
  has('status', 'active').
  inV().
  hasLabel('course').
  has('externalId', ':courseId').
  select('cc').by(valueMap('externalId')).
  dedup().
  range(:offSet, :limit);

And in case less than 10 records were found, run this query:

g.V().
  hasLabel('educatorContent').
  has('status', 'active').as('ec').
  select('ec').by(valueMap('externalId')).
  dedup().
  range(:offSet, :limit);

but do it all inside the same .gremlin file?

(Sorry if the question is too basic, super new to Gremlin)

You could use choose() which provides if-then semantics:

range(:offSet, :limit).fold().
choose(count(local).is(gt(9)),
       identity(),
       V().has('educatorContent', 'status','active')....)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM