Skip to content

Latest commit

 

History

History

translation

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Cypher to Gremlin Translation

Maven Central

The translation module provides facilities to:

  • parse Cypher queries using the Cypher frontend,
  • produce a translation to Gremlin,
  • transform results to a format that is accepted by a Gremlin Server-based database, Amazon Neptune, or Azure Cosmos DB.

Getting Started

To add a dependency using Maven:

<dependency>
    <groupId>org.opencypher.gremlin</groupId>
    <artifactId>translation</artifactId>
    <version>1.0.4</version>
</dependency>

To add a dependency using Gradle:

dependencies {
  compile 'org.opencypher.gremlin:translation:1.0.4'
}

You can also build the snapshot from source.

Usage

To translate a Cypher query to a Gremlin query:

String cypher = "MATCH (p:Person) WHERE p.age > 25 RETURN p.name";
TranslationFacade cfog = new TranslationFacade();
String gremlin = cfog.toGremlinGroovy(cypher);

A bit more verbose version of the above, demonstrating several extension points:

String cypher = "MATCH (p:Person) WHERE p.age > 25 RETURN p.name";
CypherAst ast = CypherAst.parse(cypher);
Translator<String, GroovyPredicate> translator = Translator.builder().gremlinGroovy().build();
String gremlin = ast.buildTranslation(translator);

Note that Translator instances are not reusable. A new one has to be created for each buildTranslation call. TranslationFacade handles this for you.

Translator instances support other common translation targets out of the box, like Gremlin bytecode:

Translator<Bytecode, P> translator = Translator.builder()
    .bytecode()
    .build();

Connecting to TinkerPop <3.4.0

Note that by default, translation targets TinkerPop 3.4.0 and uses steps and predicates that are unavailable in earlier Gremlin versions, for example With Step and startingWith. To provide translation suitable for these environments (for example JanusGraph <0.4.0) use gremlinServer33x flavor

Translator<String, GroovyPredicate> translator = Translator.builder()
    .gremlinGroovy()
    .build(TranslatorFlavor.gremlinServer33x());

Amazon Neptune

A translator for Amazon Neptune can be configured like so:

Translator<String, GroovyPredicate> translator = Translator.builder()
    .gremlinGroovy()
    .inlineParameters()
    .enableMultipleLabels()
    .build(TranslatorFlavor.neptune());

Azure Cosmos DB

A translator for Azure Cosmos DB can be configured like so:

Translator<String, GroovyPredicate> translator = Translator.builder()
    .gremlinGroovy()
    .build(TranslatorFlavor.cosmosDb());

Custom Translation

Custom translation targets can be provided by implementing GremlinSteps, GremlinPredicates, and GremlinParameters:

Translator.builder()
    .custom(
        new MyGremlinSteps(),
        new MyGremlinPredicates(),
        new MyGremlinBindings()
    )
    .build();

Consult the Javadoc for more information.

Running Cypher

If you want to run queries, not just translate them, you might be interested in the Cypher client for Gremlin Server.