Class DefaultGqlExecutor
- All Implemented Interfaces:
GqlExecutor
GqlMatchPlan against any TinkerPop Graph using a DFS
backtracking pattern matching algorithm.
Algorithm
- Seed iteration: vertices are scanned from the graph (or looked up
via
Graph.Indexwhen available), filtered by the seed label and seed property predicates. Each matching vertex is bound to the seed variable and used as the starting point for DFS extension. - DFS extension: the search runs on an explicit stack rather than by
recursion, with a shared
MatchStateholding the current partial match. Each stack frame is either one pending plain step expansion or one hop of a quantified walk, and holds its candidate edge iterator plus what to undo on backtrack. Steps are selected from the remaining list using DAG eligibility (anchor variable already bound), with observed selectivity, then estimated cost, then plain before quantified as the tiebreakers. - Lazy delivery:
execute(org.apache.tinkerpop.gremlin.gql.GqlMatchPlan)returns anIteratorthat runs the DFS only until the next complete match, so eachhasNext()/next()pair does the work for one row and nothing is buffered. Stack depth is bounded by heap, not by the thread stack, so long variable-length walks do not overflow.
The search checks Thread.interrupted() as it iterates and throws
TraversalInterruptedException when the thread is interrupted, so a traversal timeout
can stop a long-running match.
Index access is provided via Graph.index(). When
Graph.Index.countVertexIndex(String, Object) returns a value less than
Long.MAX_VALUE for a seed predicate key, an index lookup replaces the full vertex
scan. When all counts equal Long.MAX_VALUE (no index), a full scan is used.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
DefaultGqlExecutor
-
-
Method Details
-
execute
Returns a lazyIteratorof result rows using an empty params map.- Specified by:
executein interfaceGqlExecutor- Parameters:
plan- the compiled execution plan- Returns:
- a lazy iterator of result rows
-
execute
Returns a lazyIteratorof result rows. EachGqlRowis keyed by the variable indices defined in theGqlMatchPlan; seeGqlRowfor the binding contract.Rows are produced on demand: each
hasNext()advances the search only until the next match, so a consumer that stops early (for example underlimit(1)) does not pay for the rest of the search. Iteration throwsTraversalInterruptedExceptionif the calling thread is interrupted.The returned iterator is a
CloseableIterator. It closes the provider iterators it opens (fromGraph.vertices(Object...),Graph.Index.queryVertexIndex(java.lang.String, java.lang.Object)andVertex.edges(org.apache.tinkerpop.gremlin.structure.Direction, java.lang.String...)) once they are exhausted, when the search ends, and when it is itself closed, so a consumer that stops early should close it. Once an exception escapeshasNext()the search cannot be resumed, and every later call throwsIllegalStateExceptionwith that exception as its cause.- Specified by:
executein interfaceGqlExecutor- Parameters:
plan- the compiled execution planparams- parameter bindings for$namereferences in property predicates; may be empty if the query contains no parameter references- Returns:
- a lazy iterator of result rows
-