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
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe query language identifier that this step accepts when set explicitly.Fields inherited from class org.apache.tinkerpop.gremlin.process.traversal.step.map.DeclarativeMatchStep
parametersFields inherited from class org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep
id, labels, nextEnd, nextStep, previousStep, starts, traversal, traverserStepIdAndLabelsSetByChild -
Constructor Summary
ConstructorsConstructorDescriptionGqlMatchStep(DeclarativeMatchStep<S> originalStep) Constructs aGqlMatchStepwithout pre-injected planner or executor.GqlMatchStep(DeclarativeMatchStep<S> originalStep, GqlPlanner planner, GqlExecutor executor) Constructs aGqlMatchStepwith pre-injected planner and executor. -
Method Summary
Modifier and TypeMethodDescriptionclone()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.voidclose()Closes the current row iterator so that the executor can release any provider resources it holds, for example when a downstreamlimit()ends the traversal before the match is exhausted.DeclaresTraverserRequirement.LABELED_PATHso that traversers track their path labels, enabling downstreamselect()steps to retrieve bound variables.protected Traverser.Admin<Map<String,Object>> Returns the next output traverser.voidreset()Resets lazy row state, closing the current row iterator.Methods inherited from class org.apache.tinkerpop.gremlin.process.traversal.step.map.DeclarativeMatchStep
configure, getMatchQuery, getParameters, getParams, getQueryLanguage, isStart, toStringMethods inherited from class org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep
addLabel, addStart, addStarts, clearLabels, equals, getId, getLabels, getNextStep, getPreviousStep, getStarts, getTraversal, hashCode, hasNext, hasStarts, isTraverserStepIdAndLabelsSetByChild, next, prepareTraversalForNextStep, removeLabel, setId, setNextStep, setPreviousStep, setTraversalMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Field Details
-
SUPPORTED_QUERY_LANGUAGE
The query language identifier that this step accepts when set explicitly.nullis also accepted and is treated as a request to use this native language.- See Also:
-
-
Constructor Details
-
GqlMatchStep
Constructs aGqlMatchStepwithout pre-injected planner or executor. Both are initialised lazily from the traversal's graph on the firstprocessNextStart()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
Constructs aGqlMatchStepwith pre-injected planner and executor. Whenplannerandexecutorare non-null the plan cache is shared across all traversals that use the same objects — normally the per-graph-instance pair cached byGqlDeclarativeMatchStrategy.- Parameters:
originalStep- the step being replacedplanner- the planner to use, ornullfor lazy initexecutor- the executor to use, ornullfor lazy init
-
-
Method Details
-
processNextStart
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 compiledGqlMatchPlanis always obtained from the planner's cache so identical query strings cost only a map lookup after the first compilation.- Overrides:
processNextStartin classDeclarativeMatchStep<S>- Throws:
UnsupportedOperationException- if the query language is non-null and not "gql"NoSuchElementException
-
getRequirements
DeclaresTraverserRequirement.LABELED_PATHso that traversers track their path labels, enabling downstreamselect()steps to retrieve bound variables.- Specified by:
getRequirementsin interfaceStep<S,Map<String, Object>> - Overrides:
getRequirementsin classDeclarativeMatchStep<S>- Returns:
- the set of requirements
-
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. -
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 compiledGqlMatchPlanis 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. -
close
public void close()Closes the current row iterator so that the executor can release any provider resources it holds, for example when a downstreamlimit()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:
closein interfaceAutoCloseable
-