Class GqlMatchStep<S>

Type Parameters:
S - the traverser start type
All Implemented Interfaces:
Serializable, AutoCloseable, Cloneable, Iterator<Traverser.Admin<Map<String,Object>>>, Step<S,Map<String,Object>>, Configuring, Parameterizing

public final class GqlMatchStep<S> extends DeclarativeMatchStep<S> implements AutoCloseable
Concrete executable replacement for the generic DeclarativeMatchStep that runs TinkerGQL patterns via a GqlPlanner and GqlExecutor.

The planner and executor are normally supplied by GqlDeclarativeMatchStrategy, which caches one pair per graph instance so the planner's parse cache is shared across all traversals on the same graph. When the step is constructed without injected instances (e.g. in tests that use a substitute strategy), they are initialised lazily from the traversal's graph on the first call to processNextStart().

For each incoming traverser the plan is executed against the graph and one output traverser is emitted per result row. Each result row's named variable bindings are recorded in the emitted traverser's path so that downstream select() steps can retrieve them by name.

Only the "gql" query language is supported. If the step's query language is set to any other non-null value, UnsupportedOperationException is thrown.

The step closes the executor's row iterator with CloseableIterator.closeIterator(Iterator) when it moves on to the next incoming traverser, on reset(), and on close(). An executor whose iterator holds provider resources, such as DefaultGqlExecutor, releases them then, including when the traversal finishes early because of a downstream limit(). A caller that stops pulling results before the traversal is exhausted keeps the iterator open until it closes the traversal. Traversal.close() calls close() only on the steps of the traversal it is called on, so a match() nested in a child traversal is not closed by it; as with GraphStep, such a step releases its row iterator when the parent step resets the child traversal or when its own match is exhausted.

See Also:
  • Field Details

    • SUPPORTED_QUERY_LANGUAGE

      public static final String SUPPORTED_QUERY_LANGUAGE
      The query language identifier that this step accepts when set explicitly. null is also accepted and is treated as a request to use this native language.
      See Also:
  • Constructor Details

    • GqlMatchStep

      public GqlMatchStep(DeclarativeMatchStep<S> originalStep)
      Constructs a GqlMatchStep without pre-injected planner or executor. Both are initialised lazily from the traversal's graph on the first processNextStart() call. Intended for use in tests where a substitute strategy replaces the placeholder step without access to the shared graph-level cache.
      Parameters:
      originalStep - the step being replaced by this concrete implementation
    • GqlMatchStep

      public GqlMatchStep(DeclarativeMatchStep<S> originalStep, GqlPlanner planner, GqlExecutor executor)
      Constructs a GqlMatchStep with pre-injected planner and executor. When planner and executor are non-null the plan cache is shared across all traversals that use the same objects — normally the per-graph-instance pair cached by GqlDeclarativeMatchStrategy.
      Parameters:
      originalStep - the step being replaced
      planner - the planner to use, or null for lazy init
      executor - the executor to use, or null for lazy init
  • Method Details

    • processNextStart

      protected Traverser.Admin<Map<String,Object>> processNextStart() throws NoSuchElementException
      Returns the next output traverser.

      On the first invocation (or after a clone()), if the planner was not injected it is initialised from the traversal's graph. The compiled GqlMatchPlan is always obtained from the planner's cache so identical query strings cost only a map lookup after the first compilation.

      Overrides:
      processNextStart in class DeclarativeMatchStep<S>
      Throws:
      UnsupportedOperationException - if the query language is non-null and not "gql"
      NoSuchElementException
    • getRequirements

      public Set<TraverserRequirement> getRequirements()
      Declares TraverserRequirement.LABELED_PATH so that traversers track their path labels, enabling downstream select() steps to retrieve bound variables.
      Specified by:
      getRequirements in interface Step<S,Map<String,Object>>
      Overrides:
      getRequirements in class DeclarativeMatchStep<S>
      Returns:
      the set of requirements
    • clone

      public GqlMatchStep<S> clone()
      Creates a clone with a fresh output queue and a null plan reference so the plan is re-fetched from the planner's cache on first use. The planner and executor references are retained: when they are graph-level singletons (the normal path) the clone shares the plan cache; when they are per-step instances (test path) the clone will lazily re-create its own.
      Specified by:
      clone in interface Step<S,Map<String,Object>>
      Overrides:
      clone in class AbstractStep<S,Map<String,Object>>
      Returns:
      The cloned step
    • reset

      public void reset()
      Resets lazy row state, closing the current row iterator. The planner and executor singletons are preserved so the QueryGraph parse cache survives a traversal reset, but the compiled GqlMatchPlan is cleared so that seed selection is recomputed from live label counts on the next execution — ensuring graph mutations between resets are reflected. The row state is cleared even when closing the row iterator throws, so the step is never left half-reset.
      Specified by:
      reset in interface Step<S,Map<String,Object>>
      Overrides:
      reset in class AbstractStep<S,Map<String,Object>>
    • close

      public void close()
      Closes the current row iterator so that the executor can release any provider resources it holds, for example when a downstream limit() ends the traversal before the match is exhausted. A spawn step that has been closed produces no more rows, so a caller that keeps pulling from it does not run the match again; reset() makes it runnable again.
      Specified by:
      close in interface AutoCloseable