You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/08/13 18:43:05 UTC

[24/50] tinkerpop git commit: TINKERPOP-1878 Renamed "transpiler" to "compiler"

TINKERPOP-1878 Renamed "transpiler" to "compiler"

Since we're converting to Gremlin bytecode it's really compiling and not transpiling (as in converting to other source code)


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9d96a7f3
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9d96a7f3
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9d96a7f3

Branch: refs/heads/TINKERPOP-1878
Commit: 9d96a7f35e2c55478dffb6a0fe29a834f226024f
Parents: 4f45cde
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jun 20 07:25:17 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Aug 13 14:39:23 2018 -0400

----------------------------------------------------------------------
 docs/site/home/index.html                       |   1 +
 docs/src/reference/compilers.asciidoc           | 450 +++++++++++++++++++
 docs/src/reference/index.asciidoc               |   2 +-
 docs/src/reference/transpilers.asciidoc         | 449 ------------------
 .../gremlin/sparql/SparqlToGremlinCompiler.java | 266 +++++++++++
 .../sparql/SparqlToGremlinTranspiler.java       | 266 -----------
 .../traversal/strategy/SparqlStrategy.java      |   4 +-
 7 files changed, 720 insertions(+), 718 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9d96a7f3/docs/site/home/index.html
----------------------------------------------------------------------
diff --git a/docs/site/home/index.html b/docs/site/home/index.html
index 472e77a..bbba419 100644
--- a/docs/site/home/index.html
+++ b/docs/site/home/index.html
@@ -259,6 +259,7 @@ limitations under the License.
             <li><a href="https://github.com/pm-dev/kotlin-gremlin-ogm">kotlin-gremlin-ogm</a> (kotlin/dsl) - An Object Graph Mapping Library for Kotlin and Gremlin.</li>
             <li><a href="http://ogre.clojurewerkz.org/">ogre</a> (clojure/variant) - A Clojure language wrapper for TinkerPop3.</li>
             <li><a href="http://bayofmany.github.io/">Peapod</a> (java/dsl) - An object-graph-wrapper.</li>
+            <li><a href="http://tinkerpop.apache.org/docs/current/reference/#sparql-gremlin">sparql-gremlin</a> (sparql/distinct) - A SPARQL to Gremlin traversal compiler.</li>
             <li><a href="https://github.com/LITMUS-Benchmark-Suite/sparql-to-gremlin">sparql-gremlin</a> (sparql/distinct) - A SPARQL to Gremlin traversal compiler.</li>
             <li><a href="https://github.com/Microsoft/spring-data-gremlin">spring-data-gremlin</a> (java/dsl) - Spring Data support for TinkerPop-enabled graph systems.</li>
             <li><a href="https://github.com/twilmes/sql-gremlin">sql-gremlin</a> (sql/distinct) - An SQL to Gremlin traversal compiler.</li>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9d96a7f3/docs/src/reference/compilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/compilers.asciidoc b/docs/src/reference/compilers.asciidoc
new file mode 100644
index 0000000..e015cc8
--- /dev/null
+++ b/docs/src/reference/compilers.asciidoc
@@ -0,0 +1,450 @@
+////
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+////
+[[compilers]]
+= Gremlin Compilers
+
+There are many languages built to query data. SQL is typically used to query relational data. There is SPARQL for RDF
+data. Cypher is used to do pattern matching in graph data. The list could go on. compilers convert languages like
+these to Gremlin so that it becomes possible to use them in any context that Gremlin is used. In other words, a
+Gremlin Cranspiler enables a particular query language to work on any TinkerPop-enabled graph system.
+
+[[sparql-gremlin]]
+== SPARQL-Gremlin
+
+image::gremlintron.png[width=225]
+
+The SPARQL-Gremlin compiler, transforms link:https://en.wikipedia.org/wiki/SPARQL[SPARQL] queries into Gremlin
+traversals. It uses the https://jena.apache.org/index.html[Apache Jena] SPARQL processor
+link:https://jena.apache.org/documentation/query/index.html[ARQ], which provides access to a syntax tree of a
+SPARQL query.
+
+The goal of this work is to bridge the query interoperability gap between the two famous, yet fairly disconnected,
+graph communities: Semantic Web (which relies on the RDF data model) and Graph database (which relies on property graph
+data model).
+
+NOTE: The foundational research work on SPARQL-Gremlin compiler (aka Gremlinator) can be found in the
+link:https://arxiv.org/pdf/1801.02911.pdf[Gremlinator paper]. This paper presents the graph query language semantics of
+SPARQL and Gremlin, and a formal mapping between SPARQL pattern matching graph patterns and Gremlin traversals.
+
+[source,xml]
+----
+<dependency>
+   <groupId>org.apache.tinkerpop</groupId>
+   <artifactId>sparql-gremlin</artifactId>
+   <version>x.y.z</version>
+</dependency>
+----
+
+The SPARQL-Gremlin compiler converts link:https://en.wikipedia.org/wiki/SPARQL[SPARQL] queries into Gremlin so that
+they can be executed across any TinkerPop-enabled graph system. To use this compiler in the Gremlin Console, first
+install and activate the "tinkerpop.sparql" plugin:
+
+[source,text]
+----
+gremlin> :install org.apache.tinkerpop sparql-gremlin x.y.z
+==>Loaded: [org.apache.tinkerpop, sparql-gremlin, x.y.z]
+gremlin> :plugin use tinkerpop.sparql
+==>tinkerpop.sparql activated
+----
+
+Installing this plugin will download appropriate dependencies and import certain classes to the console so that they
+may be used as follows:
+
+[gremlin-groovy,modern]
+----
+graph = TinkerFactory.createModern()
+g = graph.traversal(SparqlTraversalSource)                                                             <1>
+g.sparql("""SELECT ?name ?age
+            WHERE { ?person v:name ?name . ?person v:age ?age }
+            ORDER BY ASC(?age)""")                                                                     <2>
+----
+
+<1> Define `g` as a `TraversalSource` that uses the `SparqlTraversalSource` - by default, the `traversal()` method
+usually returns a `GraphTraversalSource` which includes the standard Gremlin starts steps like `V()` or `E()`. In this
+case, the `SparqlTraversalSource` enables starts steps that are specific to SPARQL only - in this case the `sparql()`
+start step.
+<2> Execute a SPARQL query against the TinkerGraph instance. The `SparqlTraversalSource` uses a
+<<traversalstrategy,TraversalStrategy>> to transparently converts that SPARQL query into a standard Gremlin traversal
+and then when finally iterated, executes that against the TinkerGraph.
+
+[[prefixes]]
+=== Prefixes
+
+The SPARQL-Gremlin compiler supports the following prefixes to traverse the graph:
+
+[cols=",",options="header",]
+|====================================
+|Prefix |Purpose
+|`v:<label>` |label-access traversal
+|`e:<label>` |out-edge traversal
+|`p:<name>` |property traversal
+|`v:<name>` |property-value traversal
+|====================================
+
+Note that element IDs and labels are treated like normal properties, hence they can be accessed using the same pattern:
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?name ?id ?label 
+	WHERE { 
+	?element v:name ?name . 
+	?element v:id ?id . 
+	?element v:label ?label .}""")
+----
+
+[[supported-queries]]
+=== Supported Queries
+
+The SPARQL-Gremlin compiler currently supports translation of the SPARQL 1.0 specification, especially `SELECT`
+queries, though there is an on-going effort to cover the entire SPARQL 1.1 query feature spectrum. The supported
+SPARQL query types are:
+
+* Union 
+* Optional 
+* Order-By 
+* Group-By 
+* STAR-shaped or _neighbourhood queries_ 
+* Query modifiers, such as: 
+** Filter with _restrictions_ 
+** Count 
+** LIMIT 
+** OFFSET
+
+[[limitations]]
+=== Limitations
+
+The current implementation of SPARQL-Gremlin compiler (i.e. SPARQL-Gremlin) does not support the following cases:
+
+* SPARQL queries with variables in the predicate position are not currently covered, with an exception of the following
+case:
+
+[source,groovy]
+----
+g.sparql("""SELECT * WHERE { ?x ?y ?z . }""")
+----
+
+* A SPARQL Union query with un-balanced patterns, i.e. a gremlin union traversal can only be generated if the input
+SPARQL query has the same number of patterns on both the side of the union operator. For instance, the following
+SPARQL query cannot be mapped using Gremlinator, since a union is executed between different number of graph patterns
+(two patterns `union` 1 pattern).
+
+[source,groovy]
+----
+g.sparql("""SELECT * WHERE {
+	{?person e:created ?software .
+	?person v:name "josh" .}
+	UNION
+	{?software v:lang "java" .} }""")
+----
+
+* A non-Group key variable cannot be projected in a SPARQL query. This is a SPARQL langauge limitation rather than that of Gremlin/TinkerPop. Apache Jena throws the exception " Non-group key variable in SELECT" if this occurs.
+For instance, in a SPARQL query with GROUP-BY clause, only the variable on which the grouping is declared, can be projected. The following query is valid:
+
+[source,groovy]
+----
+g.sparql("""SELECT ?age WHERE {
+    ?person v:label "person" .
+    ?person v:age ?age .
+    ?person v:name ?name .} GROUP BY (?age)""")
+----
+
+Whereas, the following SPARQL query will be invalid:
+
+[source,groovy]
+----
+g.sparql("""SELECT ?person WHERE {
+      ?person v:label "person" .
+      ?person v:age ?age .
+      ?person v:name ?name .} GROUP BY (?age)""")
+----
+
+
+* In a SPARQL query with an ORDER-BY clause, the ordering occurs wrt to the first projected variable in the query. You may choose any number of variable to be projected, however, the first variable in the selection will be the ordering decider.
+For instance, in the query:
+
+
+[source,groovy]
+----
+g.sparql("""SELECT ?name ?age WHERE {
+    ?person v:label "person" .
+    ?person v:age ?age .
+    ?person v:name ?name . } ORDER BY (?age)""")
+----
+
+the result set will be ordered according to the `?name` variable (in ascending order by default) despite having passed `?age` in the order by. Whereas, for the following query:
+
+[source,groovy]
+----
+g.sparql("""SELECT ?age ?name WHERE {
+    ?person v:label "person" .
+    ?person v:age ?age .
+    ?person v:name ?name . } ORDER BY (?age)""")
+----
+
+the result set will be ordered according to the `?age` (as it is the first projected variable). Finally, for the select all case (`SELECT *`):
+
+[source,groovy]
+----
+g.sparql("""SELECT *
+WHERE { ?person v:label "person" . ?person v:age ?age . ?person v:name ?name . } ORDER BY (?age)""")
+----
+
+The the variable encountered first will be the ordering decider, i.e. since we have `?person` being encountered first, the result set will be ordered according to the `?person` variable (which are vertex id).
+
+* OPTIONAL
+....
+currently fixing this...
+....
+
+[[examples]]
+=== Examples
+
+The following section presents a comprehensive examples of SPARQL queries that are currently covered by the
+SPARQL-Gremlin compiler.
+
+[[select-all]]
+==== Select All
+
+Select all vertices in the graph.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT * WHERE { }""")
+----
+
+[[match-constant-values]]
+==== Match Constant Values
+
+Select all vertices with the label `person`.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT * WHERE {  ?person v:label "person" .}""")
+----
+
+[[select-specific-elements]]
+==== Select Specific Elements
+
+Select the values of the properties `name` and `age` for each `person` vertex.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?name ?age
+WHERE {
+  ?person v:label "person" .
+  ?person v:name ?name .
+  ?person v:age ?age . }""")
+----
+
+[[pattern-matching]]
+==== Pattern Matching
+
+Select only those persons who created a project.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?name ?age
+WHERE {
+  ?person v:label "person" .
+  ?person v:name ?name .
+  ?person v:age ?age .
+  ?person e:created ?project . }""")
+----
+
+[[filtering]]
+==== Filtering
+
+Select only those persons who are older than 30.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?name ?age
+WHERE {
+  ?person v:label "person" .
+  ?person v:name ?name .
+  ?person v:age ?age .
+    FILTER (?age > 30) }""")
+----
+
+[[deduplication]]
+==== Deduplication
+
+Select the distinct names of the created projects.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT DISTINCT ?name
+WHERE {
+  ?person v:label "person" .
+  ?person v:age ?age .
+  ?person e:created ?project .
+  ?project v:name ?name .
+    FILTER (?age > 30)}""")
+----
+
+[[multiple-filters]]
+==== Multiple Filters
+
+Select the distinct names of all Java projects.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT DISTINCT ?name
+WHERE {
+  ?person v:label "person" .
+  ?person v:age ?age .
+  ?person e:created ?project .
+  ?project v:name ?name .
+  ?project v:lang ?lang .
+    FILTER (?age > 30 && ?lang = "java") }""")
+----
+
+////
+[[pattern-filters]]
+==== Pattern Filter(s)
+
+A different way to filter all person who created a project.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?name
+WHERE {
+  ?person v:label "person" .
+  ?person v:name ?name .
+    FILTER EXISTS { ?person e:created ?project } }""")
+----
+
+Filter all person who did not create a project.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?name
+WHERE {
+  ?person v:label "person" .
+  ?person v:name ?name .
+    FILTER NOT EXISTS { ?person e:created ?project } }""")
+----
+////
+
+[[union]]
+==== Union
+
+Select all persons who have developed a software in java using union.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT * 
+WHERE {
+  {?person e:created ?software .}
+  UNION
+  {?software v:lang "java" .} }""")
+----
+
+[[optional]]
+==== Optional
+
+Return the names of the persons who have created a software in java and optionally python.
+
+[source,groovy]
+----
+g.sparql("""SELECT ?person 
+WHERE {
+  ?person v:label "person" .
+  ?person e:created ?software .
+  ?software v:lang "java" .
+  OPTIONAL {?software v:lang "python" . }}""")
+----
+
+[[order-by]]
+==== Order By
+
+Select all vertices with the label `person` and order them by their age.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?age ?name
+WHERE {
+  ?person v:label "person" .
+  ?person v:age ?age .
+  ?person v:name ?name .
+} ORDER BY (?age))
+----
+
+[[group-by]]
+==== Group By
+
+Select all vertices with the label `person` and group them by their age.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?age 
+WHERE {
+  ?person v:label "person" .
+  ?person v:age ?age .
+} GROUP BY (?age)""")
+----
+
+[[mixedcomplexaggregation-based-queries]]
+==== Mixed/complex/aggregation-based queries
+
+Count the number of projects which have been created by persons under the age of 30 and group them by age. Return only
+the top two.
+
+[source,groovy]
+----
+g.sparql("""SELECT (COUNT(?project) as ?p)
+WHERE {
+  ?person v:label "person" .
+  ?person v:age ?age . FILTER (?age < 30)
+  ?person e:created ?project .
+} GROUP BY (?age) LIMIT 2""")
+----
+
+[[meta-property-access]]
+==== Meta-Property Access
+
+Accessing the Meta-Property of a graph element. Meta-Property can be perceived as the reified statements in an RDF
+graph.
+
+[gremlin-groovy,theCrew]
+----
+g = graph.traversal(SparqlTraversalSource)
+g.sparql("""SELECT ?name ?startTime
+WHERE {
+  ?person v:name "daniel" .
+  ?person p:location ?location .
+  ?location v:value ?name .
+  ?location v:startTime ?startTime }""")
+----
+
+[[star-shaped-queries]]
+==== STAR-shaped queries
+
+STAR-shaped queries are the queries that form/follow a star-shaped execution plan. These in terms of graph traversals
+can be perceived as path queries or neighborhood queries. For instance, getting all the information about a specific
+`person` or `software`.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?age ?software ?lang ?name
+WHERE {
+  ?person v:name "josh" .
+  ?person v:age ?age .
+  ?person e:created ?software .
+  ?software v:lang ?lang .
+  ?software v:name ?name . }""")
+----

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9d96a7f3/docs/src/reference/index.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/index.asciidoc b/docs/src/reference/index.asciidoc
index 02a218b..9d92c28 100644
--- a/docs/src/reference/index.asciidoc
+++ b/docs/src/reference/index.asciidoc
@@ -45,7 +45,7 @@ include::implementations-hadoop-end.asciidoc[]
 
 include::gremlin-variants.asciidoc[]
 
-include::transpilers.asciidoc[]
+include::compilers.asciidoc[]
 
 include::conclusion.asciidoc[]
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9d96a7f3/docs/src/reference/transpilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/transpilers.asciidoc b/docs/src/reference/transpilers.asciidoc
deleted file mode 100644
index 0483a5d..0000000
--- a/docs/src/reference/transpilers.asciidoc
+++ /dev/null
@@ -1,449 +0,0 @@
-////
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements.  See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-////
-[[transpilers]]
-= Gremlin Transpilers
-
-There are many languages built to query data. SQL is typically used to query relational data. There is SPARQL for RDF
-data. Cypher is used to do pattern matching in graph data. The list could go on. Transpilers convert languages like
-these to Gremlin so that it becomes possible to use them in any context that Gremlin is used. In other words, a
-Gremlin Transpiler enables a particular query language to work on any TinkerPop-enabled graph system.
-
-== SPARQL-Gremlin
-
-image::gremlintron.png[width=225]
-
-The SPARQL-Gremlin transpiler, transforms link:https://en.wikipedia.org/wiki/SPARQL[SPARQL] queries into Gremlin
-traversals. It uses the https://jena.apache.org/index.html[Apache Jena] SPARQL processor
-link:https://jena.apache.org/documentation/query/index.html[ARQ], which provides access to a syntax tree of a
-SPARQL query.
-
-The goal of this work is to bridge the query interoperability gap between the two famous, yet fairly disconnected,
-graph communities: Semantic Web (which relies on the RDF data model) and Graph database (which relies on property graph
-data model).
-
-NOTE: The foundational research work on SPARQL-Gremlin transpiler (aka Gremlinator) can be found in the
-link:https://arxiv.org/pdf/1801.02911.pdf[Gremlinator paper]. This paper presents the graph query language semantics of
-SPARQL and Gremlin, and a formal mapping between SPARQL pattern matching graph patterns and Gremlin traversals.
-
-[source,xml]
-----
-<dependency>
-   <groupId>org.apache.tinkerpop</groupId>
-   <artifactId>sparql-gremlin</artifactId>
-   <version>x.y.z</version>
-</dependency>
-----
-
-The SPARQL-Gremlin transpiler converts link:https://en.wikipedia.org/wiki/SPARQL[SPARQL] queries into Gremlin so that
-they can be executed across any TinkerPop-enabled graph system. To use this transpiler in the Gremlin Console, first
-install and activate the "tinkerpop.sparql" plugin:
-
-[source,text]
-----
-gremlin> :install org.apache.tinkerpop sparql-gremlin x.y.z
-==>Loaded: [org.apache.tinkerpop, sparql-gremlin, x.y.z]
-gremlin> :plugin use tinkerpop.sparql
-==>tinkerpop.sparql activated
-----
-
-Installing this plugin will download appropriate dependencies and import certain classes to the console so that they
-may be used as follows:
-
-[gremlin-groovy,modern]
-----
-graph = TinkerFactory.createModern()
-g = graph.traversal(SparqlTraversalSource)                                                             <1>
-g.sparql("""SELECT ?name ?age
-            WHERE { ?person v:name ?name . ?person v:age ?age }
-            ORDER BY ASC(?age)""")                                                                     <2>
-----
-
-<1> Define `g` as a `TraversalSource` that uses the `SparqlTraversalSource` - by default, the `traversal()` method
-usually returns a `GraphTraversalSource` which includes the standard Gremlin starts steps like `V()` or `E()`. In this
-case, the `SparqlTraversalSource` enables starts steps that are specific to SPARQL only - in this case the `sparql()`
-start step.
-<2> Execute a SPARQL query against the TinkerGraph instance. The `SparqlTraversalSource` uses a
-<<traversalstrategy,TraversalStrategy>> to transparently converts that SPARQL query into a standard Gremlin traversal
-and then when finally iterated, executes that against the TinkerGraph.
-
-[[prefixes]]
-=== Prefixes
-
-The SPARQL-Gremlin transpiler supports the following prefixes to traverse the graph:
-
-[cols=",",options="header",]
-|====================================
-|Prefix |Purpose
-|`v:<label>` |label-access traversal
-|`e:<label>` |out-edge traversal
-|`p:<name>` |property traversal
-|`v:<name>` |property-value traversal
-|====================================
-
-Note that element IDs and labels are treated like normal properties, hence they can be accessed using the same pattern:
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT ?name ?id ?label 
-	WHERE { 
-	?element v:name ?name . 
-	?element v:id ?id . 
-	?element v:label ?label .}""")
-----
-
-[[supported-queries]]
-=== Supported Queries
-
-The SPARQL-Gremlin transpiler currently supports translation of the SPARQL 1.0 specification, especially `SELECT`
-queries, though there is an on-going effort to cover the entire SPARQL 1.1 query feature spectrum. The supported
-SPARQL query types are:
-
-* Union 
-* Optional 
-* Order-By 
-* Group-By 
-* STAR-shaped or _neighbourhood queries_ 
-* Query modifiers, such as: 
-** Filter with _restrictions_ 
-** Count 
-** LIMIT 
-** OFFSET
-
-[[limitations]]
-=== Limitations
-
-The current implementation of SPARQL-Gremlin transpiler (i.e. SPARQL-Gremlin) does not support the following cases:
-
-* SPARQL queries with variables in the predicate position are not currently covered, with an exception of the following
-case:
-
-[source,groovy]
-----
-g.sparql("""SELECT * WHERE { ?x ?y ?z . }""")
-----
-
-* A SPARQL Union query with un-balanced patterns, i.e. a gremlin union traversal can only be generated if the input
-SPARQL query has the same number of patterns on both the side of the union operator. For instance, the following
-SPARQL query cannot be mapped using Gremlinator, since a union is executed between different number of graph patterns
-(two patterns `union` 1 pattern).
-
-[source,groovy]
-----
-g.sparql("""SELECT * WHERE {
-	{?person e:created ?software .
-	?person v:name "josh" .}
-	UNION
-	{?software v:lang "java" .} }""")
-----
-
-* A non-Group key variable cannot be projected in a SPARQL query. This is a SPARQL langauge limitation rather than that of Gremlin/TinkerPop. Apache Jena throws the exception " Non-group key variable in SELECT" if this occurs.
-For instance, in a SPARQL query with GROUP-BY clause, only the variable on which the grouping is declared, can be projected. The following query is valid:
-
-[source,groovy]
-----
-g.sparql("""SELECT ?age WHERE {
-    ?person v:label "person" .
-    ?person v:age ?age .
-    ?person v:name ?name .} GROUP BY (?age)""")
-----
-
-Whereas, the following SPARQL query will be invalid:
-
-[source,groovy]
-----
-g.sparql("""SELECT ?person WHERE {
-      ?person v:label "person" .
-      ?person v:age ?age .
-      ?person v:name ?name .} GROUP BY (?age)""")
-----
-
-
-* In a SPARQL query with an ORDER-BY clause, the ordering occurs wrt to the first projected variable in the query. You may choose any number of variable to be projected, however, the first variable in the selection will be the ordering decider.
-For instance, in the query:
-
-
-[source,groovy]
-----
-g.sparql("""SELECT ?name ?age WHERE {
-    ?person v:label "person" .
-    ?person v:age ?age .
-    ?person v:name ?name . } ORDER BY (?age)""")
-----
-
-the result set will be ordered according to the `?name` variable (in ascending order by default) despite having passed `?age` in the order by. Whereas, for the following query:
-
-[source,groovy]
-----
-g.sparql("""SELECT ?age ?name WHERE {
-    ?person v:label "person" .
-    ?person v:age ?age .
-    ?person v:name ?name . } ORDER BY (?age)""")
-----
-
-the result set will be ordered according to the `?age` (as it is the first projected variable). Finally, for the select all case (`SELECT *`):
-
-[source,groovy]
-----
-g.sparql("""SELECT *
-WHERE { ?person v:label "person" . ?person v:age ?age . ?person v:name ?name . } ORDER BY (?age)""")
-----
-
-The the variable encountered first will be the ordering decider, i.e. since we have `?person` being encountered first, the result set will be ordered according to the `?person` variable (which are vertex id).
-
-* OPTIONAL
-....
-currently fixing this...
-....
-
-[[examples]]
-=== Examples
-
-The following section presents a comprehensive examples of SPARQL queries that are currently covered by the
-SPARQL-Gremlin transpiler.
-
-[[select-all]]
-==== Select All
-
-Select all vertices in the graph.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT * WHERE { }""")
-----
-
-[[match-constant-values]]
-==== Match Constant Values
-
-Select all vertices with the label `person`.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT * WHERE {  ?person v:label "person" .}""")
-----
-
-[[select-specific-elements]]
-==== Select Specific Elements
-
-Select the values of the properties `name` and `age` for each `person` vertex.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT ?name ?age
-WHERE {
-  ?person v:label "person" .
-  ?person v:name ?name .
-  ?person v:age ?age . }""")
-----
-
-[[pattern-matching]]
-==== Pattern Matching
-
-Select only those persons who created a project.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT ?name ?age
-WHERE {
-  ?person v:label "person" .
-  ?person v:name ?name .
-  ?person v:age ?age .
-  ?person e:created ?project . }""")
-----
-
-[[filtering]]
-==== Filtering
-
-Select only those persons who are older than 30.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT ?name ?age
-WHERE {
-  ?person v:label "person" .
-  ?person v:name ?name .
-  ?person v:age ?age .
-    FILTER (?age > 30) }""")
-----
-
-[[deduplication]]
-==== Deduplication
-
-Select the distinct names of the created projects.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT DISTINCT ?name
-WHERE {
-  ?person v:label "person" .
-  ?person v:age ?age .
-  ?person e:created ?project .
-  ?project v:name ?name .
-    FILTER (?age > 30)}""")
-----
-
-[[multiple-filters]]
-==== Multiple Filters
-
-Select the distinct names of all Java projects.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT DISTINCT ?name
-WHERE {
-  ?person v:label "person" .
-  ?person v:age ?age .
-  ?person e:created ?project .
-  ?project v:name ?name .
-  ?project v:lang ?lang .
-    FILTER (?age > 30 && ?lang = "java") }""")
-----
-
-////
-[[pattern-filters]]
-==== Pattern Filter(s)
-
-A different way to filter all person who created a project.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT ?name
-WHERE {
-  ?person v:label "person" .
-  ?person v:name ?name .
-    FILTER EXISTS { ?person e:created ?project } }""")
-----
-
-Filter all person who did not create a project.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT ?name
-WHERE {
-  ?person v:label "person" .
-  ?person v:name ?name .
-    FILTER NOT EXISTS { ?person e:created ?project } }""")
-----
-////
-
-[[union]]
-==== Union
-
-Select all persons who have developed a software in java using union.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT * 
-WHERE {
-  {?person e:created ?software .}
-  UNION
-  {?software v:lang "java" .} }""")
-----
-
-[[optional]]
-==== Optional
-
-Return the names of the persons who have created a software in java and optionally python.
-
-[source,groovy]
-----
-g.sparql("""SELECT ?person 
-WHERE {
-  ?person v:label "person" .
-  ?person e:created ?software .
-  ?software v:lang "java" .
-  OPTIONAL {?software v:lang "python" . }}""")
-----
-
-[[order-by]]
-==== Order By
-
-Select all vertices with the label `person` and order them by their age.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT ?age ?name
-WHERE {
-  ?person v:label "person" .
-  ?person v:age ?age .
-  ?person v:name ?name .
-} ORDER BY (?age))
-----
-
-[[group-by]]
-==== Group By
-
-Select all vertices with the label `person` and group them by their age.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT ?age 
-WHERE {
-  ?person v:label "person" .
-  ?person v:age ?age .
-} GROUP BY (?age)""")
-----
-
-[[mixedcomplexaggregation-based-queries]]
-==== Mixed/complex/aggregation-based queries
-
-Count the number of projects which have been created by persons under the age of 30 and group them by age. Return only
-the top two.
-
-[source,groovy]
-----
-g.sparql("""SELECT (COUNT(?project) as ?p)
-WHERE {
-  ?person v:label "person" .
-  ?person v:age ?age . FILTER (?age < 30)
-  ?person e:created ?project .
-} GROUP BY (?age) LIMIT 2""")
-----
-
-[[meta-property-access]]
-==== Meta-Property Access
-
-Accessing the Meta-Property of a graph element. Meta-Property can be perceived as the reified statements in an RDF
-graph.
-
-[gremlin-groovy,theCrew]
-----
-g = graph.traversal(SparqlTraversalSource)
-g.sparql("""SELECT ?name ?startTime
-WHERE {
-  ?person v:name "daniel" .
-  ?person p:location ?location .
-  ?location v:value ?name .
-  ?location v:startTime ?startTime }""")
-----
-
-[[star-shaped-queries]]
-==== STAR-shaped queries
-
-STAR-shaped queries are the queries that form/follow a star-shaped execution plan. These in terms of graph traversals
-can be perceived as path queries or neighborhood queries. For instance, getting all the information about a specific
-`person` or `software`.
-
-[gremlin-groovy,existing]
-----
-g.sparql("""SELECT ?age ?software ?lang ?name
-WHERE {
-  ?person v:name "josh" .
-  ?person v:age ?age .
-  ?person e:created ?software .
-  ?software v:lang ?lang .
-  ?software v:name ?name . }""")
-----

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9d96a7f3/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompiler.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompiler.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompiler.java
new file mode 100644
index 0000000..b43de41
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompiler.java
@@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.sparql;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.jena.query.Query;
+import org.apache.jena.query.QueryFactory;
+import org.apache.jena.query.SortCondition;
+import org.apache.jena.query.Syntax;
+import org.apache.jena.sparql.algebra.Algebra;
+import org.apache.jena.sparql.algebra.Op;
+import org.apache.jena.sparql.algebra.OpVisitorBase;
+import org.apache.jena.sparql.algebra.OpWalker;
+import org.apache.jena.sparql.algebra.op.OpBGP;
+import org.apache.jena.sparql.algebra.op.OpFilter;
+import org.apache.jena.sparql.algebra.op.OpUnion;
+import org.apache.jena.sparql.core.Var;
+import org.apache.jena.sparql.core.VarExprList;
+import org.apache.jena.sparql.expr.Expr;
+import org.apache.jena.sparql.expr.ExprAggregator;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+/**
+ * The engine that transpiles SPARQL to Gremlin traversals thus enabling SPARQL to be executed on any TinkerPop-enabled
+ * graph system.
+ */
+public class SparqlToGremlinCompiler {
+
+    private GraphTraversal<Vertex, ?> traversal;
+
+    private List<Traversal> traversalList = new ArrayList<>();
+
+    private SparqlToGremlinCompiler(final GraphTraversal<Vertex, ?> traversal) {
+        this.traversal = traversal;
+    }
+
+    private SparqlToGremlinCompiler(final GraphTraversalSource g) {
+        this(g.V());
+    }
+
+    /**
+     * Converts SPARQL to a Gremlin traversal.
+     *
+     * @param graph       the {@link Graph} instance to execute the traversal from
+     * @param sparqlQuery the query to transpile to Gremlin
+     */
+    public static GraphTraversal<Vertex, ?> transpile(final Graph graph, final String sparqlQuery) {
+        return transpile(graph.traversal(), sparqlQuery);
+    }
+
+    /**
+     * Converts SPARQL to a Gremlin traversal.
+     *
+     * @param g           the {@link GraphTraversalSource} instance to execute the traversal from
+     * @param sparqlQuery the query to transpile to Gremlin
+     */
+    public static GraphTraversal<Vertex, ?> transpile(final GraphTraversalSource g, final String sparqlQuery) {
+        return transpile(g, QueryFactory.create(Prefixes.prepend(sparqlQuery), Syntax.syntaxSPARQL));
+    }
+
+    private GraphTraversal<Vertex, ?> transpile(final Query query) {
+        final Op op = Algebra.compile(query);
+        OpWalker.walk(op, new GremlinOpVisitor());
+
+        int traversalIndex = 0;
+        final int numberOfTraversal = traversalList.size();
+        final Traversal arrayOfAllTraversals[] = new Traversal[numberOfTraversal];
+
+        for (Traversal tempTrav : traversalList) {
+            arrayOfAllTraversals[traversalIndex++] = tempTrav;
+        }
+
+        // creates a map of ordering keys and their ordering direction
+        final Map<String, Order> orderingIndex = createOrderIndexFromQuery(query);
+
+        if (traversalList.size() > 0)
+            traversal = traversal.match(arrayOfAllTraversals);
+
+        final List<String> vars = query.getResultVars();
+        if (!query.isQueryResultStar() && !query.hasGroupBy()) {
+            final String[] all = new String[vars.size()];
+            vars.toArray(all);
+            if (query.isDistinct()) {
+                traversal = traversal.dedup(all);
+            }
+
+            // apply ordering from ORDER BY
+            orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
+
+            // the result sizes have special handling to get the right signatures of select() called.
+            switch (all.length) {
+                case 0:
+                    throw new IllegalStateException();
+                case 1:
+                    traversal = traversal.select(all[0]);
+                    break;
+                case 2:
+                    traversal = traversal.select(all[0], all[1]);
+                    break;
+                default:
+                    final String[] others = Arrays.copyOfRange(all, 2, vars.size());
+                    traversal = traversal.select(all[0], all[1], others);
+                    break;
+            }
+        }
+
+        if (query.hasGroupBy()) {
+            final VarExprList lstExpr = query.getGroupBy();
+            String grpVar = "";
+            for (Var expr : lstExpr.getVars()) {
+                grpVar = expr.getName();
+            }
+
+            if (!grpVar.isEmpty())
+                traversal = traversal.select(grpVar);
+            if (query.hasAggregators()) {
+                final List<ExprAggregator> exprAgg = query.getAggregators();
+                for (ExprAggregator expr : exprAgg) {
+                    if (expr.getAggregator().getName().contains("COUNT")) {
+                        if (!query.toString().contains("GROUP")) {
+                            if (expr.getAggregator().toString().contains("DISTINCT"))
+                                traversal = traversal.dedup(expr.getAggregator().getExprList().get(0).toString().substring(1));
+                            else
+                                traversal = traversal.select(expr.getAggregator().getExprList().get(0).toString().substring(1));
+
+                            traversal = traversal.count();
+                        } else {
+                            traversal = traversal.groupCount();
+                        }
+                    }
+
+                    if (expr.getAggregator().getName().contains("MAX")) {
+                        traversal = traversal.max();
+                    }
+                }
+            } else {
+                traversal = traversal.group();
+            }
+        }
+
+        if (query.hasOrderBy() && query.hasGroupBy())
+            orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
+
+        if (query.hasLimit()) {
+            long limit = query.getLimit(), offset = 0;
+
+            if (query.hasOffset())
+                offset = query.getOffset();
+
+            if (query.hasGroupBy() && query.hasOrderBy())
+                traversal = traversal.range(Scope.local, offset, offset + limit);
+            else
+                traversal = traversal.range(offset, offset + limit);
+        }
+
+        return traversal;
+    }
+
+    /**
+     * Extracts any {@code SortCondition} instances from the SPARQL query and holds them in an index of their keys
+     * where the value is that keys sorting direction.
+     */
+    private static Map<String, Order> createOrderIndexFromQuery(final Query query) {
+        final Map<String, Order> orderingIndex = new HashMap<>();
+        if (query.hasOrderBy()) {
+            final List<SortCondition> sortingConditions = query.getOrderBy();
+
+            for (SortCondition sortCondition : sortingConditions) {
+                final Expr expr = sortCondition.getExpression();
+
+                // by default, the sort will be ascending. getDirection() returns -2 if the DESC/ASC isn't
+                // supplied - weird
+                orderingIndex.put(expr.getVarName(), sortCondition.getDirection() == -1 ? Order.decr : Order.incr);
+            }
+        }
+
+        return orderingIndex;
+    }
+
+    private static GraphTraversal<Vertex, ?> transpile(final GraphTraversalSource g, final Query query) {
+        return new SparqlToGremlinCompiler(g).transpile(query);
+    }
+
+    /**
+     * An {@code OpVisitor} implementation that reads SPARQL algebra operations into Gremlin traversals.
+     */
+    private class GremlinOpVisitor extends OpVisitorBase {
+
+        /**
+         * Visiting triple patterns in SPARQL algebra.
+         */
+        @Override
+        public void visit(final OpBGP opBGP) {
+            opBGP.getPattern().getList().forEach(triple -> traversalList.add(TraversalBuilder.transform(triple)));
+        }
+
+        /**
+         * Visiting filters in SPARQL algebra.
+         */
+        @Override
+        public void visit(final OpFilter opFilter) {
+            Traversal traversal;
+            for (Expr expr : opFilter.getExprs().getList()) {
+                if (expr != null) {
+                    traversal = __.where(WhereTraversalBuilder.transform(expr));
+                    traversalList.add(traversal);
+                }
+            }
+        }
+
+        /**
+         * Visiting unions in SPARQL algebra.
+         */
+        @Override
+        public void visit(final OpUnion opUnion) {
+            final Traversal unionTemp[] = new Traversal[2];
+            final Traversal unionTemp1[] = new Traversal[traversalList.size() / 2];
+            final Traversal unionTemp2[] = new Traversal[traversalList.size() / 2];
+
+            int count = 0;
+
+            for (int i = 0; i < traversalList.size(); i++) {
+                if (i < traversalList.size() / 2)
+                    unionTemp1[i] = traversalList.get(i);
+                else
+                    unionTemp2[count++] = traversalList.get(i);
+            }
+
+            unionTemp[1] = __.match(unionTemp2);
+            unionTemp[0] = __.match(unionTemp1);
+
+            traversalList.clear();
+            traversal = (GraphTraversal<Vertex, ?>) traversal.union(unionTemp);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9d96a7f3/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinTranspiler.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinTranspiler.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinTranspiler.java
deleted file mode 100644
index 67ac1e1..0000000
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinTranspiler.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.sparql;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.jena.query.Query;
-import org.apache.jena.query.QueryFactory;
-import org.apache.jena.query.SortCondition;
-import org.apache.jena.query.Syntax;
-import org.apache.jena.sparql.algebra.Algebra;
-import org.apache.jena.sparql.algebra.Op;
-import org.apache.jena.sparql.algebra.OpVisitorBase;
-import org.apache.jena.sparql.algebra.OpWalker;
-import org.apache.jena.sparql.algebra.op.OpBGP;
-import org.apache.jena.sparql.algebra.op.OpFilter;
-import org.apache.jena.sparql.algebra.op.OpUnion;
-import org.apache.jena.sparql.core.Var;
-import org.apache.jena.sparql.core.VarExprList;
-import org.apache.jena.sparql.expr.Expr;
-import org.apache.jena.sparql.expr.ExprAggregator;
-import org.apache.tinkerpop.gremlin.process.traversal.Order;
-import org.apache.tinkerpop.gremlin.process.traversal.Scope;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-
-/**
- * The engine that transpiles SPARQL to Gremlin traversals thus enabling SPARQL to be executed on any TinkerPop-enabled
- * graph system.
- */
-public class SparqlToGremlinTranspiler {
-
-    private GraphTraversal<Vertex, ?> traversal;
-
-    private List<Traversal> traversalList = new ArrayList<>();
-
-    private SparqlToGremlinTranspiler(final GraphTraversal<Vertex, ?> traversal) {
-        this.traversal = traversal;
-    }
-
-    private SparqlToGremlinTranspiler(final GraphTraversalSource g) {
-        this(g.V());
-    }
-
-    /**
-     * Converts SPARQL to a Gremlin traversal.
-     *
-     * @param graph       the {@link Graph} instance to execute the traversal from
-     * @param sparqlQuery the query to transpile to Gremlin
-     */
-    public static GraphTraversal<Vertex, ?> transpile(final Graph graph, final String sparqlQuery) {
-        return transpile(graph.traversal(), sparqlQuery);
-    }
-
-    /**
-     * Converts SPARQL to a Gremlin traversal.
-     *
-     * @param g           the {@link GraphTraversalSource} instance to execute the traversal from
-     * @param sparqlQuery the query to transpile to Gremlin
-     */
-    public static GraphTraversal<Vertex, ?> transpile(final GraphTraversalSource g, final String sparqlQuery) {
-        return transpile(g, QueryFactory.create(Prefixes.prepend(sparqlQuery), Syntax.syntaxSPARQL));
-    }
-
-    private GraphTraversal<Vertex, ?> transpile(final Query query) {
-        final Op op = Algebra.compile(query);
-        OpWalker.walk(op, new GremlinOpVisitor());
-
-        int traversalIndex = 0;
-        final int numberOfTraversal = traversalList.size();
-        final Traversal arrayOfAllTraversals[] = new Traversal[numberOfTraversal];
-
-        for (Traversal tempTrav : traversalList) {
-            arrayOfAllTraversals[traversalIndex++] = tempTrav;
-        }
-
-        // creates a map of ordering keys and their ordering direction
-        final Map<String, Order> orderingIndex = createOrderIndexFromQuery(query);
-
-        if (traversalList.size() > 0)
-            traversal = traversal.match(arrayOfAllTraversals);
-
-        final List<String> vars = query.getResultVars();
-        if (!query.isQueryResultStar() && !query.hasGroupBy()) {
-            final String[] all = new String[vars.size()];
-            vars.toArray(all);
-            if (query.isDistinct()) {
-                traversal = traversal.dedup(all);
-            }
-
-            // apply ordering from ORDER BY
-            orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
-
-            // the result sizes have special handling to get the right signatures of select() called.
-            switch (all.length) {
-                case 0:
-                    throw new IllegalStateException();
-                case 1:
-                    traversal = traversal.select(all[0]);
-                    break;
-                case 2:
-                    traversal = traversal.select(all[0], all[1]);
-                    break;
-                default:
-                    final String[] others = Arrays.copyOfRange(all, 2, vars.size());
-                    traversal = traversal.select(all[0], all[1], others);
-                    break;
-            }
-        }
-
-        if (query.hasGroupBy()) {
-            final VarExprList lstExpr = query.getGroupBy();
-            String grpVar = "";
-            for (Var expr : lstExpr.getVars()) {
-                grpVar = expr.getName();
-            }
-
-            if (!grpVar.isEmpty())
-                traversal = traversal.select(grpVar);
-            if (query.hasAggregators()) {
-                final List<ExprAggregator> exprAgg = query.getAggregators();
-                for (ExprAggregator expr : exprAgg) {
-                    if (expr.getAggregator().getName().contains("COUNT")) {
-                        if (!query.toString().contains("GROUP")) {
-                            if (expr.getAggregator().toString().contains("DISTINCT"))
-                                traversal = traversal.dedup(expr.getAggregator().getExprList().get(0).toString().substring(1));
-                            else
-                                traversal = traversal.select(expr.getAggregator().getExprList().get(0).toString().substring(1));
-
-                            traversal = traversal.count();
-                        } else {
-                            traversal = traversal.groupCount();
-                        }
-                    }
-
-                    if (expr.getAggregator().getName().contains("MAX")) {
-                        traversal = traversal.max();
-                    }
-                }
-            } else {
-                traversal = traversal.group();
-            }
-        }
-
-        if (query.hasOrderBy() && query.hasGroupBy())
-            orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
-
-        if (query.hasLimit()) {
-            long limit = query.getLimit(), offset = 0;
-
-            if (query.hasOffset())
-                offset = query.getOffset();
-
-            if (query.hasGroupBy() && query.hasOrderBy())
-                traversal = traversal.range(Scope.local, offset, offset + limit);
-            else
-                traversal = traversal.range(offset, offset + limit);
-        }
-
-        return traversal;
-    }
-
-    /**
-     * Extracts any {@code SortCondition} instances from the SPARQL query and holds them in an index of their keys
-     * where the value is that keys sorting direction.
-     */
-    private static Map<String, Order> createOrderIndexFromQuery(final Query query) {
-        final Map<String, Order> orderingIndex = new HashMap<>();
-        if (query.hasOrderBy()) {
-            final List<SortCondition> sortingConditions = query.getOrderBy();
-
-            for (SortCondition sortCondition : sortingConditions) {
-                final Expr expr = sortCondition.getExpression();
-
-                // by default, the sort will be ascending. getDirection() returns -2 if the DESC/ASC isn't
-                // supplied - weird
-                orderingIndex.put(expr.getVarName(), sortCondition.getDirection() == -1 ? Order.decr : Order.incr);
-            }
-        }
-
-        return orderingIndex;
-    }
-
-    private static GraphTraversal<Vertex, ?> transpile(final GraphTraversalSource g, final Query query) {
-        return new SparqlToGremlinTranspiler(g).transpile(query);
-    }
-
-    /**
-     * An {@code OpVisitor} implementation that reads SPARQL algebra operations into Gremlin traversals.
-     */
-    private class GremlinOpVisitor extends OpVisitorBase {
-
-        /**
-         * Visiting triple patterns in SPARQL algebra.
-         */
-        @Override
-        public void visit(final OpBGP opBGP) {
-            opBGP.getPattern().getList().forEach(triple -> traversalList.add(TraversalBuilder.transform(triple)));
-        }
-
-        /**
-         * Visiting filters in SPARQL algebra.
-         */
-        @Override
-        public void visit(final OpFilter opFilter) {
-            Traversal traversal;
-            for (Expr expr : opFilter.getExprs().getList()) {
-                if (expr != null) {
-                    traversal = __.where(WhereTraversalBuilder.transform(expr));
-                    traversalList.add(traversal);
-                }
-            }
-        }
-
-        /**
-         * Visiting unions in SPARQL algebra.
-         */
-        @Override
-        public void visit(final OpUnion opUnion) {
-            final Traversal unionTemp[] = new Traversal[2];
-            final Traversal unionTemp1[] = new Traversal[traversalList.size() / 2];
-            final Traversal unionTemp2[] = new Traversal[traversalList.size() / 2];
-
-            int count = 0;
-
-            for (int i = 0; i < traversalList.size(); i++) {
-                if (i < traversalList.size() / 2)
-                    unionTemp1[i] = traversalList.get(i);
-                else
-                    unionTemp2[count++] = traversalList.get(i);
-            }
-
-            unionTemp[1] = __.match(unionTemp2);
-            unionTemp[0] = __.match(unionTemp1);
-
-            traversalList.clear();
-            traversal = (GraphTraversal<Vertex, ?>) traversal.union(unionTemp);
-        }
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9d96a7f3/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
index 4073ec2..b21c348 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
@@ -25,7 +25,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinTranspiler;
+import org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinCompiler;
 import org.apache.tinkerpop.gremlin.sparql.process.traversal.dsl.sparql.SparqlTraversalSource;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
@@ -68,7 +68,7 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
             final Object constant = stepWithSparql.getConstant();
             if (constant instanceof String) {
                 final String sparql = (String) constant;
-                final Traversal<Vertex, ?> sparqlTraversal = SparqlToGremlinTranspiler.transpile(
+                final Traversal<Vertex, ?> sparqlTraversal = SparqlToGremlinCompiler.transpile(
                         traversal.getGraph().get(), sparql);
                 TraversalHelper.removeAllSteps(traversal);
                 sparqlTraversal.asAdmin().getSteps().forEach(s -> traversal.addStep(s));