Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Gremlin

Traverse nodes and relationships step by step with Gremlin, then project the values your application needs.

Conformance

OrchidDB passes all 1,511 scenarios in the pinned Apache TinkerPop 3.7.4 Gremlin suite. The complete run uses one OrchidDB instance. The conformance comparison includes individual outcomes, upstream assertions, execution timings, and downloadable evidence.

Start a traversal

OrchidDB accepts Gremlin traversal text through gremlin(query).await. In the standalone CLI request, set "language": "gremlin". The optional managed core binary uses --language gremlin.

JVM callbacks and TinkerPop vertex programs execute as operators in the same SQL IR/DataFusion pipeline. Typed callbacks can be supplied through gremlin_with_bindings. The compatibility matrix reports one OrchidDB outcome per scenario.

g.V().hasLabel('Person').values('name')

g.V() starts at vertices, hasLabel selects a label, and values projects a property. Examples here use the mapped tutorial.

Filter vertices

g.V().hasLabel('Person').has('name', 'alice').values('age')

The tutorial returns 30. Predicates express comparisons:

g.V().hasLabel('Person').has('age', gt(29)).values('name').order()

This selects alice and carol.

Follow relationships

g.V().hasLabel('Person').has('name', 'alice')
  .out('FOLLOWS').values('name').order()

Use out(type) to follow relationships from source to destination and in(type) to walk toward their source. Use both(type) when the question concerns either direction.

For an edge property, traverse the edges themselves:

g.V().hasLabel('Person').has('name', 'alice')
  .outE('ORDERED').values('total')

This returns alice’s two order totals, 50 and 120.

Reduce values

g.V().hasLabel('Person').has('name', 'alice')
  .out('ORDERED').values('total').sum()

The sum is 170. Use count() to count traversers at the current step:

g.V().hasLabel('Person').count()

The tutorial contains three people.

Order and deduplicate

g.V().hasLabel('Person').out('FOLLOWS')
  .values('name').dedup().order()

dedup() removes repeated values from this projection. order() makes the output order explicit. Use limit(n) or range(start, end) when selecting a window of traversal results.

Name traversal positions

as records a binding for later select steps:

g.V().hasLabel('Person').as('person')
  .out('ORDERED').as('order')
  .select('person', 'order')

Bindings are useful when the result needs information from multiple stages. For simple application output, project properties directly with values.

Repeated traversal

A bounded repeat expresses a repeated graph step:

g.V().hasLabel('Person').has('name', 'alice')
  .repeat(out('FOLLOWS')).times(2).values('name')

This asks for people reached after exactly two outgoing steps. Use a bound that matches the domain question, and inspect the execution plan when integrating a traversal into an application.