Class GqlDeclarativeMatchStrategy

All Implemented Interfaces:
Serializable, Comparable<Class<? extends TraversalStrategy>>, TraversalStrategy<TraversalStrategy.ProviderOptimizationStrategy>, TraversalStrategy.ProviderOptimizationStrategy

TraversalStrategy.ProviderOptimizationStrategy that replaces every DeclarativeMatchStep in a traversal with a concrete GqlMatchStep backed by a DefaultGqlPlanner and DefaultGqlExecutor.

Singleton usage (recommended)

The no-arg instance() singleton maintains a static ConcurrentHashMap keyed by graph identity. The first traversal executed against a given Graph instance allocates one DefaultGqlPlanner and one DefaultGqlExecutor for that graph; all subsequent traversals reuse them, so the planner's parse cache is shared across all traversals on the same graph.

Graph providers should register the singleton in their global strategy cache:

   TraversalStrategies.GlobalCache.registerStrategies(
       AcmeGraph.class,
       TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone()
           .addStrategies(GqlDeclarativeMatchStrategy.instance()));
 

When the graph is closed call evict(Graph) to release the cached pair:

   @Override
   public void close() {
       GqlDeclarativeMatchStrategy.evict(this);
       // ... other cleanup
   }
 

Custom planner / executor

Providers that supply their own GqlPlanner or GqlExecutor implementations can use create(GqlPlanner, GqlExecutor) to construct a per-instance strategy. That strategy instance holds the supplied objects directly and does not interact with the shared cache.

OLAP / GraphComputer limitation

match(String) is not supported in OLAP (GraphComputer) mode. The strategy's apply(org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin<?, ?>) method detects a graph-computer traversal context via TraversalHelper.onGraphComputer(org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin<?, ?>) and returns immediately without replacing the placeholder step. Attempting to execute match(String) in OLAP mode will therefore result in an UnsupportedOperationException at traversal execution time.

The limitation exists because TinkerGQL execution relies on direct, lazy vertex and edge iteration against an OLTP graph (seed scans, DFS backtracking), which has no equivalent in the scatter-gather message-passing model of OLAP. Providers seeking to support declarative pattern matching in OLAP would need to implement it as a VertexProgram.

See Also:
  • Method Details

    • instance

      public static GqlDeclarativeMatchStrategy instance()
      Returns the singleton strategy that uses DefaultGqlPlanner and DefaultGqlExecutor cached per graph instance. This is the recommended way for providers to register TinkerGQL support.
    • create

      public static GqlDeclarativeMatchStrategy create(GqlPlanner planner, GqlExecutor executor)
      Creates a per-instance strategy with explicit planner and executor objects. Use this when you want to supply custom implementations; the strategy holds planner and executor directly and does not interact with the shared cache.
      Parameters:
      planner - the planner to use for every traversal that goes through this strategy
      executor - the executor to use for every traversal that goes through this strategy
      Returns:
      a new strategy instance
    • evict

      public static void evict(Graph graph)
      Removes the cached GqlPlanner / GqlExecutor pair for the given graph instance. Graph implementations should call this from their close() method to release the cache entry and allow the planner and executor to be garbage-collected.
      Parameters:
      graph - the graph whose cached pair should be removed
    • apply

      public void apply(Traversal.Admin<?,?> traversal)
      Description copied from interface: TraversalStrategy
      The transformation the strategy applies to the traversal.
      Specified by:
      apply in interface TraversalStrategy<TraversalStrategy.ProviderOptimizationStrategy>