Gremlin
Gremlin is evaluated by a native step engine inside the Gremlin wire. It does not produce a LogicalPlan and does not pass through QueryEngine for reads. The step list, predicates, storage tables, limits and tests are documented in Gremlin (TinkerPop): implementation reference; this page describes the translation path only.
Translation path
(source: src/protocol/gremlin/mod.rs, handle_eval, handle_bytecode; src/protocol/gremlin/script.rs; src/protocol/gremlin/strategies.rs, StrategyManager::apply; src/protocol/gremlin/engine.rs, Engine::step; src/protocol/gremlin/traversal.rs, GremlinGraphStore::with_storage, persist_vertex, persist_edge)
-
Front end. The
evalop parses a gremlin-lang text script intoBytecode; thebytecodeop receives GraphSON bytecode, or GraphBinary bytecode converted to GraphSON. Both end in the sameBytecodevalue (source:src/protocol/gremlin/mod.rs,handle_eval,handle_bytecode;src/protocol/gremlin/bytecode.rs,Bytecode). -
Strategies.
StrategyManager::applyrewrites the instruction list (filter ranking, inline filters, count, adjacent-to-incident and others). A strategy failure is logged and the original bytecode runs. No strategy reads a storage index (source:src/protocol/gremlin/strategies.rs,StrategyManager::new). -
Step engine.
engine.rsgroups instructions into steps with their modulators and runs child traversals per traverser. Unknown step names return "Unknown step: <name>" (source:src/protocol/gremlin/engine.rs,compile,Engine::step). -
Storage. Reads come from the in-memory
GremlinGraphStore. Each vertex or edge write is mirrored to SQL through a newQueryEngineas aDELETEthen anINSERTof that one row, so a multi-step mutation is not one transaction (source:src/protocol/gremlin/traversal.rs,persist_vertex,persist_edge).
Relation to other graph languages
The Gremlin graph, the Bolt Cypher graph (_bolt_* tables) and the engine-side Cypher graph (__graph_nodes__, __graph_edges__) are three separate stores; data written through one is not visible to the others (source: src/protocol/gremlin/traversal.rs, GremlinGraphStore::with_storage; src/protocol/bolt/mod.rs, GraphStore::with_storage; src/query/cypher/planner.rs, node_to_insert). The _gremlin_vertices and _gremlin_edges tables are ordinary SQL tables, so SQL wires can read the mirrored rows with properties as JSON text. Because their names start with _gremlin_, the engine treats them as wire-internal tables: a role that is not a superuser needs a GRANT to read them (source: src/protocol/gremlin/traversal.rs, GremlinGraphStore::with_storage; src/query/engine.rs, is_wire_internal_relation). Not verified: no test reads the Gremlin tables over a SQL wire.
The only reference to the Gremlin module outside src/protocol/gremlin/ is the server start-up in src/server/mod.rs; no HTTP or SQL path evaluates Gremlin (source: src/server/mod.rs, GremlinServer).
Supported and unsupported
Supported steps, predicates and the script grammar are listed in section 5 of the reference. Unsupported: math, sack, match, tree, mergeV, mergeE, subgraph, profile, explain, lambdas, and transactions through g.tx() (source: src/protocol/gremlin/engine.rs, Engine::step).
Tests
Tested by tests/protocol_gremlin.rs, the unit tests under src/protocol/gremlin/, and the differential harness test-scripts/diff-gremlin/diff_gremlin.py against gremlin-server 3.7.2 (source: section 9 of the reference).
The repository maps in the top-level README and in How it works list Gremlin under src/query/; the code is in src/protocol/gremlin/, and src/query/ has no Gremlin module (source: README.md, repository map; src/protocol/gremlin/mod.rs).