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/08 11:47:46 UTC

[01/50] tinkerpop git commit: Merge branch 'tp33' [Forced Update!]

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1878 e0261dc77 -> 7802de5b9 (forced update)


Merge branch 'tp33'


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

Branch: refs/heads/TINKERPOP-1878
Commit: 226ef6e4fbcecdc3a08b2ae55c15aca163efe412
Parents: b63bacf b779a2a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sat Aug 4 06:28:19 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Sat Aug 4 06:28:19 2018 -0400

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/driver/Client.java  | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/226ef6e4/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
----------------------------------------------------------------------


[22/50] tinkerpop git commit: TINKERPOP-1878 sparql() step works over remoting

Posted by sp...@apache.org.
TINKERPOP-1878 sparql() step works over remoting

At this point it is only tested to work with Gryo 3.0. Fixed a bug with how dynamic gryo registrations work - they failed if you didn't have a specific serializer specified. Introduced a bit of a hack to make SparqlTraversalSource behave like a GraphTraversalSource and thus more cleanly follow the DSL pattern. Not sure if that's a great approach yet or not, but it seems harmless at this point.


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

Branch: refs/heads/TINKERPOP-1878
Commit: 623ead87c0f58af33da87cbf5236acf395f9c9fc
Parents: 9cd7327
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 17:00:54 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java | 5 ++++-
 sparql-gremlin/pom.xml                                          | 4 ----
 .../process/traversal/dsl/sparql/SparqlTraversalSource.java     | 3 +++
 .../sparql/process/traversal/strategy/SparqlStrategy.java       | 5 +++--
 4 files changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/623ead87/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
index e7dfd93..45d2970 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
@@ -403,6 +403,9 @@ public enum GryoVersion {
                     "org.apache.tinkerpop.gremlin.driver.ser.RequestMessageGryoSerializer", 167);
             tryAddDynamicType(this, "org.apache.tinkerpop.gremlin.driver.message.ResponseMessage",
                     "org.apache.tinkerpop.gremlin.driver.ser.ResponseMessageGryoSerializer", 169);
+
+            tryAddDynamicType(this, "org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStrategy",
+                    null, 1690);
         }};
     }
 
@@ -591,7 +594,7 @@ public enum GryoVersion {
                                             final String serializer, final int registrationId) {
         try {
             final Class typeClass = Class.forName(type);
-            final Optional<SerializerShim<?>> serializerInstance = Optional.of(serializer)
+            final Optional<SerializerShim<?>> serializerInstance = Optional.ofNullable(serializer)
                     .map(FunctionUtils.wrapFunction(Class::forName))
                     .map(FunctionUtils.wrapFunction(c -> (SerializerShim<?>) c.getConstructor().newInstance()));
             if (serializerInstance.isPresent()) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/623ead87/sparql-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/sparql-gremlin/pom.xml b/sparql-gremlin/pom.xml
index 0dceb85..0e3da38 100644
--- a/sparql-gremlin/pom.xml
+++ b/sparql-gremlin/pom.xml
@@ -11,10 +11,6 @@
     <artifactId>sparql-gremlin</artifactId>
     <name>Apache TinkerPop :: SPARQL Gremlin</name>
 
-    <properties>
-        <query.dir>src/test/resources/sparql/queries</query.dir>
-    </properties>
-
     <dependencies>
         <dependency>
             <groupId>org.apache.jena</groupId>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/623ead87/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
index b156ed1..3889d95 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -27,6 +27,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.InjectStep;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Transaction;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
@@ -123,8 +124,10 @@ public class SparqlTraversalSource implements TraversalSource {
      */
     public <S> SparqlTraversal<S,String> sparql(final String query) {
         final SparqlTraversalSource clone = this.clone();
+        clone.bytecode.addStep(GraphTraversal.Symbols.inject);
         clone.bytecode.addStep(GraphTraversal.Symbols.constant, query);
         final SparqlTraversal.Admin<S, S> traversal = new DefaultSparqlTraversal<>(clone);
+        traversal.addStep(new InjectStep<S>(traversal));
         return traversal.addStep(new ConstantStep<S,String>(traversal, query));
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/623ead87/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 bb0b326..d74ac3e 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
@@ -19,6 +19,7 @@
 package org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy;
 
 import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
+import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.decoration.RemoteStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
@@ -44,7 +45,7 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
         implements TraversalStrategy.DecorationStrategy {
     private static final SparqlStrategy INSTANCE = new SparqlStrategy();
 
-    private static final Set<Class<? extends DecorationStrategy>> POSTS = Collections.singleton(VertexProgramStrategy.class);
+    private static final Set<Class<? extends DecorationStrategy>> POSTS = Collections.singleton(RemoteStrategy.class);
 
     private SparqlStrategy() {}
 
@@ -63,7 +64,7 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
         if (!(traversal.getParent() instanceof EmptyStep))
             return;
 
-        if (traversal.getSteps().size() == 1 && traversal.getEndStep() instanceof ConstantStep) {
+        if (traversal.getSteps().size() == 2 && traversal.getEndStep() instanceof ConstantStep) {
             final ConstantStep stepWithSparql = (ConstantStep) traversal.getEndStep();
             final Object constant = stepWithSparql.getConstant();
             if (constant instanceof String) {


[44/50] tinkerpop git commit: TINKERPOP-1878 Minor formatting/edits to compilers doc for sparql-gremlin

Posted by sp...@apache.org.
TINKERPOP-1878 Minor formatting/edits to compilers doc for sparql-gremlin


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

Branch: refs/heads/TINKERPOP-1878
Commit: b78031148db30988e4a35a95aa39d1b5b5dc1ac4
Parents: 8ffd63c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Aug 1 09:59:19 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/src/reference/compilers.asciidoc | 129 +++++++++++------------------
 1 file changed, 48 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b7803114/docs/src/reference/compilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/compilers.asciidoc b/docs/src/reference/compilers.asciidoc
index 5b6ab2e..2a8d561 100644
--- a/docs/src/reference/compilers.asciidoc
+++ b/docs/src/reference/compilers.asciidoc
@@ -18,9 +18,9 @@ limitations under the License.
 = 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
+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.
+Gremlin Compiler enables a particular query language to work on any TinkerPop-enabled graph system.
 
 [[sparql-gremlin]]
 == SPARQL-Gremlin
@@ -139,83 +139,90 @@ 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).
+SPARQL query cannot be mapped, 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" .} }""")
+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:
+* A non-Group key variable cannot be projected in a SPARQL query. This is a SPARQL language 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)""")
+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)""")
+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:
-
+* In a SPARQL query with an ORDER-BY clause, the ordering occurs with respect to the first projected variable in the
+query. It is possible to 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)""")
+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:
+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)""")
+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 *`):
+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)""")
+            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
-In the current implementation, `OPTIONAL` clause doesn't work under nesting with `UNION` clause (i.e. multiple optional clauses with in a union clause) and `ORDER-By` clause (i.e. declaring ordering over triple patterns within optional clauses). Everything else with SPARQL `OPTIONAL` works just fine.
+the the variable encountered first will be the ordering decider, i.e. since we have `?person` encountered first,
+the result set will be ordered according to the `?person` variable (which are vertex id).
 
+* In the current implementation, `OPTIONAL` clause doesn't work under nesting with `UNION` clause (i.e. multiple optional
+clauses with in a union clause) and `ORDER-By` clause (i.e. declaring ordering over triple patterns within optional
+clauses). Everything else with SPARQL `OPTIONAL` works just fine.
 
 [[examples]]
 === Examples
 
-The following section presents a comprehensive examples of SPARQL queries that are currently covered by the
-SPARQL-Gremlin compiler.
+The following section presents examples of SPARQL queries that are currently covered by the SPARQL-Gremlin compiler.
 
-[[select-all]]
 ==== Select All
 
 Select all vertices in the graph.
@@ -225,7 +232,6 @@ Select all vertices in the graph.
 g.sparql("""SELECT * WHERE { }""")
 ----
 
-[[match-constant-values]]
 ==== Match Constant Values
 
 Select all vertices with the label `person`.
@@ -235,7 +241,6 @@ Select all vertices with the label `person`.
 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.
@@ -249,7 +254,6 @@ WHERE {
   ?person v:age ?age . }""")
 ----
 
-[[pattern-matching]]
 ==== Pattern Matching
 
 Select only those persons who created a project.
@@ -264,7 +268,6 @@ WHERE {
   ?person e:created ?project . }""")
 ----
 
-[[filtering]]
 ==== Filtering
 
 Select only those persons who are older than 30.
@@ -279,7 +282,6 @@ WHERE {
     FILTER (?age > 30) }""")
 ----
 
-[[deduplication]]
 ==== Deduplication
 
 Select the distinct names of the created projects.
@@ -295,7 +297,6 @@ WHERE {
     FILTER (?age > 30)}""")
 ----
 
-[[multiple-filters]]
 ==== Multiple Filters
 
 Select the distinct names of all Java projects.
@@ -312,34 +313,6 @@ WHERE {
     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.
@@ -353,7 +326,6 @@ WHERE {
   {?software v:lang "java" .} }""")
 ----
 
-[[optional]]
 ==== Optional
 
 Return the names of the persons who have created a software in java and optionally python.
@@ -368,7 +340,6 @@ WHERE {
   OPTIONAL {?software v:lang "python" . }}""")
 ----
 
-[[order-by]]
 ==== Order By
 
 Select all vertices with the label `person` and order them by their age.
@@ -383,7 +354,6 @@ WHERE {
 } ORDER BY (?age))
 ----
 
-[[group-by]]
 ==== Group By
 
 Select all vertices with the label `person` and group them by their age.
@@ -397,7 +367,6 @@ WHERE {
 } 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
@@ -413,7 +382,6 @@ WHERE {
 } 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
@@ -430,7 +398,6 @@ WHERE {
   ?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


[25/50] tinkerpop git commit: TINKERPOP-1878 Major refactoring of sparql-gremlin classes

Posted by sp...@apache.org.
TINKERPOP-1878 Major refactoring of sparql-gremlin classes

Renamed the "compiler" to a "transpiler" since it's really transforming sparql to a language of a similar level of abstraction in Gremlin. Lots of code reformatting and dead code pruning.


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

Branch: refs/heads/TINKERPOP-1878
Commit: e364a9d4771a6c7bd0696fbcdf8b28602c326abe
Parents: 9b2fbc1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jan 26 13:36:29 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../gremlin/sparql/SparqlToGremlinCompiler.java | 381 -------------------
 .../sparql/SparqlToGremlinTranspiler.java       | 286 ++++++++++++++
 .../gremlin/sparql/TraversalBuilder.java        |   7 +-
 .../gremlin/sparql/WhereTraversalBuilder.java   |  66 ++--
 .../traversal/strategy/SparqlStrategy.java      |   5 +-
 5 files changed, 322 insertions(+), 423 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e364a9d4/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
deleted file mode 100644
index adb36e9..0000000
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompiler.java
+++ /dev/null
@@ -1,381 +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.List;
-
-import org.apache.jena.graph.Triple;
-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.OpLeftJoin;
-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;
-
-// TODO: implement OpVisitor, don't extend OpVisitorBase
-public class SparqlToGremlinCompiler extends OpVisitorBase {
-
-	private GraphTraversal<Vertex, ?> traversal;
-
-	List<Traversal> traversalList = new ArrayList<Traversal>();
-
-	String groupVariable = "";
-	int sortingDirection = 0;
-	long offsetLimit = 0;
-	String sortingVariable = "";
-
-	GraphTraversalSource temp;
-	Graph graph;
-
-	private SparqlToGremlinCompiler(final GraphTraversal<Vertex, ?> traversal) {
-		this.traversal = traversal;
-	}
-
-	private SparqlToGremlinCompiler(final GraphTraversalSource g) {
-		this(g.V());
-		temp = g;
-
-	}
-
-	private SparqlToGremlinCompiler(final Graph g) {
-		this.traversal = (GraphTraversal<Vertex, ?>) g.traversal();
-		graph = g;
-	}
-
-	public String createMatchStep(String step) {
-		String st = "";
-		step = step.substring(1, step.length() - 2);
-		String first = step.substring(0, step.indexOf(","));
-		String second = step.substring(step.indexOf(",") + 1);
-		//System.out.println("First : " + first);
-		//System.out.println("Second : " + second);
-		st = first.substring(first.indexOf("["), first.length() - 1);
-		st = "[" + st + "," + second + "]";
-		return st;
-	}
-
-	GraphTraversal<Vertex, ?> convertToGremlinTraversal(final Query query) {
-		
-		// long startTime = System.currentTimeMillis();
-		// long endTime;
-		final Op op = Algebra.compile(query); // SPARQL query compiles here to
-												// OP
-//		System.out.println("OP Tree: " + op.toString());
-
-		
-		OpWalker.walk(op, this); // OP is being walked here
-		
-		
-		
-		
-		//System.out.println("time taken for opWalker:"+ (endTime-startTime));
-		// startTime = System.currentTimeMillis();
-		int traversalIndex = 0;
-		int numberOfTraversal = traversalList.size();
-		Traversal arrayOfAllTraversals[] = new Traversal[numberOfTraversal];
-
-		if (query.hasOrderBy() && !query.hasGroupBy()) {
-			List<SortCondition> sortingConditions = query.getOrderBy();
-			int directionOfSort = 0;
-
-			for (SortCondition sortCondition : sortingConditions) {
-				Expr expr = sortCondition.getExpression();
-				directionOfSort = sortCondition.getDirection();
-				sortingVariable = expr.getVarName();
-
-			}
-
-			Order orderDirection = Order.incr;
-			if (directionOfSort == -1) {
-				orderDirection = Order.decr;
-			}
-		}
-		for (Traversal tempTrav : traversalList) {
-
-			arrayOfAllTraversals[traversalIndex++] = tempTrav;
-		}
-
-		int directionOfSort = 0;
-		Order orderDirection = Order.incr;
-		if (query.hasOrderBy()) {
-			List<SortCondition> sortingConditions = query.getOrderBy();
-
-			//
-			for (SortCondition sortCondition : sortingConditions) {
-				Expr expr = sortCondition.getExpression();
-				directionOfSort = sortCondition.getDirection();
-				sortingVariable = expr.getVarName();
-//				System.out.println("order by var: "+sortingDirection);
-			}
-			//
-
-			if (directionOfSort == -1) {
-				orderDirection = Order.decr;
-			}
-
-		}
-
-		if (traversalList.size() > 0)
-			traversal = traversal.match(arrayOfAllTraversals);
-
-		final List<String> vars = query.getResultVars();
-		List<ExprAggregator> lstexpr = query.getAggregators();
-		if (!query.isQueryResultStar() && !query.hasGroupBy()) {
-
-			switch (vars.size()) {
-			case 0:
-				throw new IllegalStateException();
-			case 1:
-				if (query.isDistinct()) {
-//					System.out.println("Inside ------------------- >Select 1------------------------> Distinct");
-					traversal = traversal.dedup(vars.get(0));
-				}
-				if (query.hasOrderBy()) {
-//					System.out.println("Inside ------------------- >Select 1");
-					traversal = traversal.order().by(sortingVariable, orderDirection);
-				} else {
-
-					traversal = traversal.select(vars.get(0));
-				}
-				break;
-			case 2:
-				if (query.isDistinct()) {
-					traversal = traversal.dedup(vars.get(0), vars.get(1));
-				}
-				if (query.hasOrderBy()) {
-//					System.out.println("Inside ------------------- >Select 1");
-					traversal = traversal.order().by(__.select(vars.get(0)), orderDirection).by(__.select(vars.get(1)));
-				} else
-					traversal = traversal.select(vars.get(0), vars.get(1));
-				break;
-			default:
-				final String[] all = new String[vars.size()];
-				vars.toArray(all);
-				if (query.isDistinct()) {
-
-					traversal = traversal.dedup(all);
-				}
-				final String[] others = Arrays.copyOfRange(all, 2, vars.size());
-				if (query.hasOrderBy()) {
-
-					traversal = traversal.order().by(__.select(vars.get(0)), orderDirection).by(__.select(vars.get(1)));
-
-				} else
-					traversal = traversal.select(vars.get(0), vars.get(1), others);
-
-				break;
-			}
-
-		}
-		
-		
-		if (query.hasGroupBy()) {
-			VarExprList lstExpr = query.getGroupBy();
-			String grpVar = "";
-			Traversal tempTrav;
-			for (Var expr : lstExpr.getVars()) {
-				grpVar = expr.getName();
-				// System.out.println("The Group by var: " + expr.getName());
-			}
-
-			if (query.hasLimit()) {
-				long limit = query.getLimit(), offset = 0;
-
-				if (query.hasOffset()) {
-					offset = query.getOffset();
-
-				}
-				// if (query.hasGroupBy() && query.hasOrderBy())
-				// traversal = traversal.range( offset, offset + limit);
-				// else
-				// traversal = traversal.range(offset, offset + limit);
-
-			}
-
-			if (!grpVar.isEmpty())
-				traversal = traversal.select(grpVar);
-			if (query.hasAggregators()) {
-				List<ExprAggregator> exprAgg = query.getAggregators();
-				for (ExprAggregator expr : exprAgg) {
-
-//					System.out.println("The Aggregator by var: " + expr.getAggregator().getExprList().toString()
-//							+ " is :" + expr.getAggregator().toString());
-					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()) {
-
-			traversal = traversal.order().by(sortingVariable, orderDirection);
-		}
-		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);
-
-		}
-		// endTime = System.currentTimeMillis();
-		// System.out.println("time taken for convertToGremlinTraversal Function : "+ (endTime-startTime)+" mili seconds");
-		
-		return traversal;
-	}
-
-	private static GraphTraversal<Vertex, ?> convertToGremlinTraversal(final GraphTraversalSource g,
-			final Query query) {
-		return new SparqlToGremlinCompiler(g).convertToGremlinTraversal(query);
-	}
-
-	public static GraphTraversal<Vertex, ?> convertToGremlinTraversal(final Graph graph, final String query) {
-		return convertToGremlinTraversal(graph.traversal(),	QueryFactory.create(Prefixes.prepend(query)));
-	}
-
-	public static GraphTraversal<Vertex, ?> convertToGremlinTraversal(final GraphTraversalSource g,
-			final String query) {
-		return convertToGremlinTraversal(g, QueryFactory.create(Prefixes.prepend(query), Syntax.syntaxSPARQL));
-	}
-
-	// VISITING SPARQL ALGEBRA OP BASIC TRIPLE PATTERNS - MAYBE
-	@Override
-	public void visit(final OpBGP opBGP) {
-		{
-			
-			// System.out.println("Inside opBGP ---------------------------------------------->");
-			final List<Triple> triples = opBGP.getPattern().getList();
-			final Traversal[] matchTraversals = new Traversal[triples.size()];
-			int i = 0;
-			for (final Triple triple : triples) {
-
-				matchTraversals[i++] = TraversalBuilder.transform(triple);
-				traversalList.add(matchTraversals[i - 1]);
-			}
-
-		}
-
-	}
-
-	// VISITING SPARQL ALGEBRA OP FILTER - MAYBE
-	@Override
-	public void visit(final OpFilter opFilter) {
-
-		// System.out.println("Inside opFilter ---------------------------------------------->");
-		Traversal traversal = null;
-
-		for (Expr expr : opFilter.getExprs().getList()) {
-			if (expr != null) {
-
-				traversal = __.where(WhereTraversalBuilder.transform(expr));
-				traversalList.add(traversal);
-			}
-		}
-
-	}
-	// TODO: add more functions for operators other than FILTER, such as
-	// OPTIONAL
-	// This can be done by understanding how Jena handles these other
-	// operators/filters inherently and then map them to Gremlin
-
-	public void visit(final OpLeftJoin opLeftJoin) {
-
-//		System.out.println("Inside opOptional ---------------------------------------------->");
-//		System.out.println(opLeftJoin.getRight().toString());
-
-	}
-
-	@Override
-	public void visit(final OpUnion opUnion) {
-
-		// System.out.println("Inside opUnion ---------------------------------------------->");
-		Traversal unionTemp[] = new Traversal[2];
-		Traversal unionTemp1[] = new Traversal[traversalList.size() / 2];
-		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);
-		// System.out.println("Getting out from Union -------------------> :
-		// "+traversal);
-		// traversalList.add(__.union(unionTemp));
-		// traversalList.clear();
-	}
-}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e364a9d4/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
new file mode 100644
index 0000000..9db7d82
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinTranspiler.java
@@ -0,0 +1,286 @@
+/*
+ * 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.List;
+
+import org.apache.jena.graph.Triple;
+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 String sortingVariable = "";
+
+	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];
+
+		if (query.hasOrderBy() && !query.hasGroupBy()) {
+            final List<SortCondition> sortingConditions = query.getOrderBy();
+
+			for (SortCondition sortCondition : sortingConditions) {
+                final Expr expr = sortCondition.getExpression();
+				sortingVariable = expr.getVarName();
+			}
+		}
+
+		for (Traversal tempTrav : traversalList) {
+			arrayOfAllTraversals[traversalIndex++] = tempTrav;
+		}
+
+		Order orderDirection = Order.incr;
+		if (query.hasOrderBy()) {
+            int directionOfSort = 0;
+            final List<SortCondition> sortingConditions = query.getOrderBy();
+
+			for (SortCondition sortCondition : sortingConditions) {
+                final Expr expr = sortCondition.getExpression();
+				directionOfSort = sortCondition.getDirection();
+				sortingVariable = expr.getVarName();
+			}
+
+			if (directionOfSort == -1) orderDirection = Order.decr;
+		}
+
+		if (traversalList.size() > 0)
+			traversal = traversal.match(arrayOfAllTraversals);
+
+		final List<String> vars = query.getResultVars();
+		if (!query.isQueryResultStar() && !query.hasGroupBy()) {
+            switch (vars.size()) {
+                case 0:
+                    throw new IllegalStateException();
+                case 1:
+                    if (query.isDistinct())
+                        traversal = traversal.dedup(vars.get(0));
+
+                    if (query.hasOrderBy())
+                        traversal = traversal.order().by(sortingVariable, orderDirection);
+                    else
+                        traversal = traversal.select(vars.get(0));
+
+                    break;
+                case 2:
+                    if (query.isDistinct())
+                        traversal = traversal.dedup(vars.get(0), vars.get(1));
+
+                    if (query.hasOrderBy())
+                        traversal = traversal.order().by(__.select(vars.get(0)), orderDirection).by(__.select(vars.get(1)));
+                    else
+                        traversal = traversal.select(vars.get(0), vars.get(1));
+
+                    break;
+                default:
+                    final String[] all = new String[vars.size()];
+                    vars.toArray(all);
+                    if (query.isDistinct())
+                        traversal = traversal.dedup(all);
+
+                    final String[] others = Arrays.copyOfRange(all, 2, vars.size());
+                    if (query.hasOrderBy())
+                        traversal = traversal.order().by(__.select(vars.get(0)), orderDirection).by(__.select(vars.get(1)));
+                    else
+                        traversal = traversal.select(vars.get(0), vars.get(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())
+			traversal = traversal.order().by(sortingVariable, orderDirection);
+
+		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;
+	}
+
+    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) {
+            final List<Triple> triples = opBGP.getPattern().getList();
+            final Traversal[] matchTraversals = new Traversal[triples.size()];
+            int i = 0;
+            for (final Triple triple : triples) {
+
+                matchTraversals[i++] = TraversalBuilder.transform(triple);
+                traversalList.add(matchTraversals[i - 1]);
+            }
+        }
+
+        /**
+         * 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/e364a9d4/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/TraversalBuilder.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/TraversalBuilder.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/TraversalBuilder.java
index 72a32a5..6d29442 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/TraversalBuilder.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/TraversalBuilder.java
@@ -26,10 +26,12 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.structure.PropertyType;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
-
+/**
+ * Converts triple patterns into {@link GraphTraversal} instances.
+ */
 class TraversalBuilder {
 
-    public static GraphTraversal<?, ?> transform(final Triple triple) {
+    static GraphTraversal<?, ?> transform(final Triple triple) {
         final GraphTraversal<Vertex, ?> matchTraversal = __.as(triple.getSubject().getName());
         
         final Node predicate = triple.getPredicate();
@@ -53,7 +55,6 @@ class TraversalBuilder {
                                                       final PropertyType type, final Node object) {
         switch (propertyName) {
             case "id":
-         
                 return object.isConcrete()
                         ? traversal.hasId(object.getLiteralValue())
                         : traversal.id().as(object.getName());

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e364a9d4/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/WhereTraversalBuilder.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/WhereTraversalBuilder.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/WhereTraversalBuilder.java
index f4d49b6..80da707 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/WhereTraversalBuilder.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/WhereTraversalBuilder.java
@@ -33,61 +33,77 @@ import org.apache.jena.sparql.expr.E_LogicalAnd;
 import org.apache.jena.sparql.expr.E_LogicalOr;
 import org.apache.jena.sparql.expr.E_NotEquals;
 import org.apache.jena.sparql.expr.E_NotExists;
-import org.apache.jena.sparql.expr.E_StrLength;
 import org.apache.jena.sparql.expr.Expr;
 import org.apache.tinkerpop.gremlin.process.traversal.P;
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 
+/**
+ * Converts SPARQL "where" expressions to Gremlin predicates.
+ */
 class WhereTraversalBuilder {
 
-    public static GraphTraversal<?, ?> transform(final E_Equals expression) {
-    //	System.out.println("The aggr one : "+expression.getArg1().getClass().getName() + "The aggr one :"+expression.getArg2().getClass().getName());
+    /**
+     * Converts a general {@code Expr} to an anonymous {@link GraphTraversal}.
+     */
+    static GraphTraversal<?, ?> transform(final Expr expression) {
+        if (expression instanceof E_Equals) return transform((E_Equals) expression);
+        if (expression instanceof E_NotEquals) return transform((E_NotEquals) expression);
+        if (expression instanceof E_LessThan) return transform((E_LessThan) expression);
+        if (expression instanceof E_LessThanOrEqual) return transform((E_LessThanOrEqual) expression);
+        if (expression instanceof E_GreaterThan) return transform((E_GreaterThan) expression);
+        if (expression instanceof E_GreaterThanOrEqual) return transform((E_GreaterThanOrEqual) expression);
+        if (expression instanceof E_LogicalAnd) return transform((E_LogicalAnd) expression);
+        if (expression instanceof E_LogicalOr) return transform((E_LogicalOr) expression);
+        if (expression instanceof E_Exists) return transform((E_Exists) expression);
+        if (expression instanceof E_NotExists) return transform((E_NotExists) expression);
+        throw new IllegalStateException(String.format("Unhandled expression: %s", expression));
+    }
+
+    private static GraphTraversal<?, ?> transform(final E_Equals expression) {
         final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
         return __.as(expression.getArg1().getVarName()).is(P.eq(value));
     }
 
-    public static GraphTraversal<?, ?> transform(final E_NotEquals expression) {
+    private static GraphTraversal<?, ?> transform(final E_NotEquals expression) {
         final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
         return __.as(expression.getArg1().getVarName()).is(P.neq(value));
     }
 
-    public static GraphTraversal<?, ?> transform(final E_LessThan expression) {
-    //	System.out.println("The aggr one : "+expression.getArg1().getClass().getName() + "The aggr one :"+expression.getArg2().getClass().getName());
+    private static GraphTraversal<?, ?> transform(final E_LessThan expression) {
     	final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
         return __.as(expression.getArg1().getVarName()).is(P.lt(value));
     }
 
-    public static GraphTraversal<?, ?> transform(final E_LessThanOrEqual expression) {
-    //	System.out.println("The aggr one : "+expression.getArg1().getClass().getName() + "The aggr one :"+expression.getArg2().getClass().getName());
+    private static GraphTraversal<?, ?> transform(final E_LessThanOrEqual expression) {
         final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
         return __.as(expression.getArg1().getVarName()).is(P.lte(value));
     }
 
-    public static GraphTraversal<?, ?> transform(final E_GreaterThan expression) {
+    private static GraphTraversal<?, ?> transform(final E_GreaterThan expression) {
         final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
         return __.as(expression.getArg1().getVarName()).is(P.gt(value));
     }
 
-    public static GraphTraversal<?, ?> transform(final E_GreaterThanOrEqual expression) {
+    private static GraphTraversal<?, ?> transform(final E_GreaterThanOrEqual expression) {
         final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
         return __.as(expression.getArg1().getVarName()).is(P.gte(value));
     }
 
-    public static GraphTraversal<?, ?> transform(final E_LogicalAnd expression) {
+    private static GraphTraversal<?, ?> transform(final E_LogicalAnd expression) {
         return __.and(
                 transform(expression.getArg1()),
                 transform(expression.getArg2()));
     }
 
-    public static GraphTraversal<?, ?> transform(final E_LogicalOr expression) {
+    private static GraphTraversal<?, ?> transform(final E_LogicalOr expression) {
         return __.or(
                 transform(expression.getArg1()),
                 transform(expression.getArg2()));
     }
 
-    public static GraphTraversal<?, ?> transform(final E_Exists expression) {
+    private static GraphTraversal<?, ?> transform(final E_Exists expression) {
         final OpBGP opBGP = (OpBGP) expression.getGraphPattern();
         final List<Triple> triples = opBGP.getPattern().getList();
         if (triples.size() != 1) throw new IllegalStateException("Unhandled EXISTS pattern");
@@ -99,7 +115,7 @@ class WhereTraversalBuilder {
     }
     
 
-    public static GraphTraversal<?, ?> transform(final E_NotExists expression) {
+    private static GraphTraversal<?, ?> transform(final E_NotExists expression) {
         final OpBGP opBGP = (OpBGP) expression.getGraphPattern();
         final List<Triple> triples = opBGP.getPattern().getList();
         if (triples.size() != 1) throw new IllegalStateException("Unhandled NOT EXISTS pattern");
@@ -109,26 +125,4 @@ class WhereTraversalBuilder {
         endStep.removeLabel(label);
         return __.not(traversal);
     }
-    
-    public static int getStrLength(final E_StrLength expression){
-    	
-    	return expression.getArg().toString().length();
-    	
-    }
-    
-    
-    //what does <?, ?> signify? possibly <S,E>
-    public static GraphTraversal<?, ?> transform(final Expr expression) {
-        if (expression instanceof E_Equals) return transform((E_Equals) expression);
-        if (expression instanceof E_NotEquals) return transform((E_NotEquals) expression);
-        if (expression instanceof E_LessThan) return transform((E_LessThan) expression);
-        if (expression instanceof E_LessThanOrEqual) return transform((E_LessThanOrEqual) expression);
-        if (expression instanceof E_GreaterThan) return transform((E_GreaterThan) expression);
-        if (expression instanceof E_GreaterThanOrEqual) return transform((E_GreaterThanOrEqual) expression);
-        if (expression instanceof E_LogicalAnd) return transform((E_LogicalAnd) expression);
-        if (expression instanceof E_LogicalOr) return transform((E_LogicalOr) expression);
-        if (expression instanceof E_Exists) return transform((E_Exists) expression);
-        if (expression instanceof E_NotExists) return transform((E_NotExists) expression);
-        throw new IllegalStateException(String.format("Unhandled expression: %s", expression));
-    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e364a9d4/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 d74ac3e..4073ec2 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
@@ -18,7 +18,6 @@
  */
 package org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy;
 
-import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
 import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.decoration.RemoteStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
@@ -26,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.SparqlToGremlinCompiler;
+import org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinTranspiler;
 import org.apache.tinkerpop.gremlin.sparql.process.traversal.dsl.sparql.SparqlTraversalSource;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
@@ -69,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 = SparqlToGremlinCompiler.convertToGremlinTraversal(
+                final Traversal<Vertex, ?> sparqlTraversal = SparqlToGremlinTranspiler.transpile(
                         traversal.getGraph().get(), sparql);
                 TraversalHelper.removeAllSteps(traversal);
                 sparqlTraversal.asAdmin().getSteps().forEach(s -> traversal.addStep(s));


[02/50] tinkerpop git commit: Merge branch 'TINKERPOP-2016' into tp32

Posted by sp...@apache.org.
Merge branch 'TINKERPOP-2016' into tp32


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

Branch: refs/heads/TINKERPOP-1878
Commit: b98ff5e150c2da037780737c571c34215fe6c151
Parents: ce94738 1829318
Author: Robert Dale <ro...@gmail.com>
Authored: Sat Aug 4 16:44:00 2018 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Sat Aug 4 16:44:00 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc     | 1 +
 gremlin-shaded/pom.xml | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[48/50] tinkerpop git commit: TINKERPOP-1878 Minor transpiler doc fixes

Posted by sp...@apache.org.
TINKERPOP-1878 Minor transpiler doc fixes


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

Branch: refs/heads/TINKERPOP-1878
Commit: 24fb38c0d5414b2260e6d2ba98c52faab63d33ae
Parents: 26ec6a8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jun 15 08:16:03 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/src/reference/transpilers.asciidoc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/24fb38c0/docs/src/reference/transpilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/transpilers.asciidoc b/docs/src/reference/transpilers.asciidoc
index 1bb7728..0483a5d 100644
--- a/docs/src/reference/transpilers.asciidoc
+++ b/docs/src/reference/transpilers.asciidoc
@@ -131,7 +131,7 @@ The current implementation of SPARQL-Gremlin transpiler (i.e. SPARQL-Gremlin) do
 * SPARQL queries with variables in the predicate position are not currently covered, with an exception of the following
 case:
 
-[source,text]
+[source,groovy]
 ----
 g.sparql("""SELECT * WHERE { ?x ?y ?z . }""")
 ----
@@ -141,7 +141,7 @@ SPARQL query has the same number of patterns on both the side of the union opera
 SPARQL query cannot be mapped using Gremlinator, since a union is executed between different number of graph patterns
 (two patterns `union` 1 pattern).
 
-[source,text]
+[source,groovy]
 ----
 g.sparql("""SELECT * WHERE {
 	{?person e:created ?software .
@@ -163,7 +163,7 @@ g.sparql("""SELECT ?age WHERE {
 
 Whereas, the following SPARQL query will be invalid:
 
-[source,text]
+[source,groovy]
 ----
 g.sparql("""SELECT ?person WHERE {
       ?person v:label "person" .


[04/50] tinkerpop git commit: Merge branch 'tp33'

Posted by sp...@apache.org.
Merge branch 'tp33'


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

Branch: refs/heads/TINKERPOP-1878
Commit: 891e7da50a3e6d3396e66a7a74c43934b325792d
Parents: 226ef6e 3e308f5
Author: Robert Dale <ro...@gmail.com>
Authored: Sat Aug 4 16:45:50 2018 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Sat Aug 4 16:45:50 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc     | 1 +
 gremlin-shaded/pom.xml | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/891e7da5/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/891e7da5/gremlin-shaded/pom.xml
----------------------------------------------------------------------


[34/50] tinkerpop git commit: testing logo

Posted by sp...@apache.org.
testing logo

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

Branch: refs/heads/TINKERPOP-1878
Commit: 703983c1048de66b93e7020ac87082243b1e3090
Parents: 36fa842
Author: Harsh Thakkar <ha...@gmail.com>
Authored: Wed Mar 28 10:29:43 2018 +0200
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/src/reference/transpilers.asciidoc | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/703983c1/docs/src/reference/transpilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/transpilers.asciidoc b/docs/src/reference/transpilers.asciidoc
index 305e3dc..9100f84 100644
--- a/docs/src/reference/transpilers.asciidoc
+++ b/docs/src/reference/transpilers.asciidoc
@@ -17,6 +17,10 @@ limitations under the License.
 [[transpilers]]
 = Gremlin Transpilers
 
+![gremlinator][SPARQL-Gremlin]
+
+[SPARQL-Gremlin]: https://raw.githubusercontent.com/LITMUS-Benchmark-Suite/sparql-to-gremlin/master/docs/images/sparql-gremlin-logo.png
+
 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


[45/50] tinkerpop git commit: TINKERPOP-1878 Added the plugin for sparql-gremlin

Posted by sp...@apache.org.
TINKERPOP-1878 Added the plugin for sparql-gremlin


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

Branch: refs/heads/TINKERPOP-1878
Commit: 005239f0ff9ef481e7902039f42376bfcdda34cb
Parents: 33626cb
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jan 29 09:37:15 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 .../sparql/jsr223/SparqlGremlinPlugin.java      | 63 ++++++++++++++++++++
 ...pache.tinkerpop.gremlin.jsr223.GremlinPlugin |  1 +
 2 files changed, 64 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/005239f0/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/jsr223/SparqlGremlinPlugin.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/jsr223/SparqlGremlinPlugin.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/jsr223/SparqlGremlinPlugin.java
new file mode 100644
index 0000000..8d0115b
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/jsr223/SparqlGremlinPlugin.java
@@ -0,0 +1,63 @@
+/*
+ * 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.jsr223;
+
+import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin;
+import org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer;
+import org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin;
+import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer;
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.dsl.sparql.DefaultSparqlTraversal;
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.dsl.sparql.SparqlTraversal;
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.dsl.sparql.SparqlTraversalSource;
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStrategy;
+
+/**
+ * {@link GremlinPlugin} implementation for {@code sparql-gremlin} that imports the key classes and interfaces required
+ * to use SPARQL in TinkerPop.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public final class SparqlGremlinPlugin extends AbstractGremlinPlugin {
+
+    private static final String NAME = "tinkerpop.sparql";
+
+    private static final ImportCustomizer imports;
+
+    static {
+        try {
+            imports = DefaultImportCustomizer.build().addClassImports(
+                    SparqlTraversalSource.class,
+                    SparqlTraversal.class,
+                    DefaultSparqlTraversal.class,
+                    SparqlStrategy.class).create();
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    private static final SparqlGremlinPlugin instance = new SparqlGremlinPlugin();
+
+    public SparqlGremlinPlugin() {
+        super(NAME, imports);
+    }
+
+    public static SparqlGremlinPlugin instance() {
+        return instance;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/005239f0/sparql-gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin b/sparql-gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin
new file mode 100644
index 0000000..882054c
--- /dev/null
+++ b/sparql-gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin
@@ -0,0 +1 @@
+org.apache.tinkerpop.gremlin.sparql.jsr223.SparqlGremlinPlugin
\ No newline at end of file


[47/50] tinkerpop git commit: TINKERPOP-1878 Bump sparql-gremlin to 3.4.0-SNAPSHOT

Posted by sp...@apache.org.
TINKERPOP-1878 Bump sparql-gremlin to 3.4.0-SNAPSHOT


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

Branch: refs/heads/TINKERPOP-1878
Commit: 7c5935491fd0284947a89f880643d0b20114900f
Parents: c4e21cf
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sun May 13 11:07:10 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 sparql-gremlin/pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7c593549/sparql-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/sparql-gremlin/pom.xml b/sparql-gremlin/pom.xml
index 731b822..8608cc6 100644
--- a/sparql-gremlin/pom.xml
+++ b/sparql-gremlin/pom.xml
@@ -6,7 +6,7 @@
     <parent>
         <artifactId>tinkerpop</artifactId>
         <groupId>org.apache.tinkerpop</groupId>
-        <version>3.3.2-SNAPSHOT</version>
+        <version>3.4.0-SNAPSHOT</version>
     </parent>
     <artifactId>sparql-gremlin</artifactId>
     <name>Apache TinkerPop :: SPARQL Gremlin</name>


[29/50] tinkerpop git commit: TINKERPOP-1878 Test for FILTER

Posted by sp...@apache.org.
TINKERPOP-1878 Test for FILTER

Also fixed how the SparqlStrategy was being added to the TraversalStrategies in SparqlTraversalSource...it was adding it globally and all spawned TraversalSource instances were getting that strategy.


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

Branch: refs/heads/TINKERPOP-1878
Commit: 808a047553b08d0a93644867f47f25f0ba678e1b
Parents: 9f84825
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jan 26 16:29:55 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../dsl/sparql/SparqlTraversalSource.java       |  2 +-
 .../dsl/sparql/SparqlTraversalSourceTest.java   | 23 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/808a0475/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
index cc54aa5..f78708b 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -47,7 +47,6 @@ public class SparqlTraversalSource implements TraversalSource {
     public SparqlTraversalSource(final Graph graph, final TraversalStrategies traversalStrategies) {
         this.graph = graph;
         this.strategies = traversalStrategies;
-        this.strategies.addStrategies(SparqlStrategy.instance());
     }
 
     public SparqlTraversalSource(final Graph graph) {
@@ -126,6 +125,7 @@ public class SparqlTraversalSource implements TraversalSource {
      */
     public <S> SparqlTraversal<S,?> sparql(final String query) {
         final SparqlTraversalSource clone = this.clone();
+        clone.getStrategies().addStrategies(SparqlStrategy.instance());
 
         // this is a bit of a hack to get remote traversals to work cleanly. on the remote side, we'd expect a
         // GraphTraversalSource not a SparqlTraversalSource (given that sparql-gremlin is to be implemented in the

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/808a0475/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
index 1b39813..4092e58 100644
--- a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
@@ -18,16 +18,21 @@
  */
 package org.apache.tinkerpop.gremlin.sparql.process.traversal.dsl.sparql;
 
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStrategy;
 import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
 import org.junit.Test;
 
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
 import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+import static org.junit.Assert.assertEquals;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
@@ -36,6 +41,7 @@ public class SparqlTraversalSourceTest {
 
     private static final Graph graph = TinkerFactory.createModern();
     private static final SparqlTraversalSource g = graph.traversal(SparqlTraversalSource.class);
+    private static final GraphTraversalSource _g = graph.traversal();
 
     @Test
     public void shouldFindAllPersonsNamesAndAges() {
@@ -88,4 +94,21 @@ public class SparqlTraversalSourceTest {
         final List<?> x = g.sparql("SELECT ?name WHERE { ?person v:name ?name } ORDER BY DESC(?name)").toList();
         assertThat(x, contains("vadas", "ripple", "peter", "marko", "lop", "josh"));
     }
+
+    @Test
+    public void shouldFilter() {
+        final Map<String,Vertex> x = (Map) g.sparql(  "SELECT ?a ?b ?c\n" +
+                                                            "WHERE {\n" +
+                                                            "  ?a v:label \"person\" .\n" +
+                                                            "  ?a e:knows ?b .\n" +
+                                                            "  ?a e:created ?c .\n" +
+                                                            "  ?b e:created ?c .\n" +
+                                                            "  ?a v:age ?d .\n" +
+                                                            "    FILTER (?d < 30)\n" +
+                                                            "}").next();
+
+        assertEquals(x.get("a"), _g.V(1).next());
+        assertEquals(x.get("b"), _g.V(4).next());
+        assertEquals(x.get("c"), _g.V(3).next());
+    }
 }


[42/50] tinkerpop git commit: updating the reference documentation

Posted by sp...@apache.org.
updating the reference documentation

added the following:
- fix the logo
- added prefixes
- added limitations
- added examples

todo:
- cover all limitations and special cases with examples

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

Branch: refs/heads/TINKERPOP-1878
Commit: e291867196312b2e694f397c1159281fbb6a8442
Parents: 703983c
Author: Harsh Thakkar <ha...@gmail.com>
Authored: Wed Mar 28 17:27:32 2018 +0200
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/src/reference/transpilers.asciidoc | 355 ++++++++++++++++++++++++++-
 1 file changed, 351 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2918671/docs/src/reference/transpilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/transpilers.asciidoc b/docs/src/reference/transpilers.asciidoc
index 9100f84..386b4a5 100644
--- a/docs/src/reference/transpilers.asciidoc
+++ b/docs/src/reference/transpilers.asciidoc
@@ -17,10 +17,6 @@ limitations under the License.
 [[transpilers]]
 = Gremlin Transpilers
 
-![gremlinator][SPARQL-Gremlin]
-
-[SPARQL-Gremlin]: https://raw.githubusercontent.com/LITMUS-Benchmark-Suite/sparql-to-gremlin/master/docs/images/sparql-gremlin-logo.png
-
 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
@@ -28,6 +24,24 @@ Gremlin Transpiler enables a particular query language to work on any TinkerPop-
 
 == SPARQL-Gremlin
 
+image:https://raw.githubusercontent.com/LITMUS-Benchmark-Suite/sparql-to-gremlin/master/docs/images/sparql-gremlin-logo.png[gremlinator]
+
+The SPARQL-Gremlin transpiler, transforms link:https://en.wikipedia.org/wiki/SPARQL[SPARQL] queries into Gremlin traversals. It is based on the  https://jena.apache.org/index.html[Apache Jena] SPARQL processor 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 from -
+https://arxiv.org/pdf/1801.02911.pdf[Gremlinator full paper]. In this
+paper, we present and discuss the notion of graph query language
+semantics of SPARQL and Gremlin, and a formal mapping between SPARQL
+pattern matching graph patterns and Gremlin traversals. Furthermore, we
+point the interested reader to the following resourcesfor a better
+understanding: (1) Gremlinator demonstration -
+(http://gremlinator.iai.uni-bonn.de:8080/Demo/[Public Demo Mirror 1])
+and (http://195.201.31.31:8080/Demo/[Public Demo Mirror 2]); (2) A short video tutorial on how to use the demonstration - https://www.youtube.com/watch?v=Z0ETx2IBamw[here]
+
 [source,xml]
 ----
 <dependency>
@@ -68,3 +82,336 @@ 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 is currently an on-going effort with an aim to cover the entire SPARQL 1.1 query feature spectrum, however we currently only support translation of the SPARQL 1.0 specification, especially _SELECT_ queries. 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:
+
+[gremlin-groovy,existing]
+----
+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 unput 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).
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT * 
+	WHERE {
+	{?person e:created ?software . 
+	?person v:name "daniel" .}
+	UNION
+	{?software v:lang "java" .} }""")
+----
+
+* order by
+....
+Adding more here...
+....
+
+* group by
+....
+Adding more here...
+....
+
+[[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 .
+  ?person e:created ?project .
+    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 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 } }""")
+----
+
+[[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,existing]
+----
+g.sparql("""SELECT ?name ?startTime
+WHERE {
+  ?person v:name "daniel" .
+  ?person p:location ?location .
+  ?location v:value ?name .
+  ?location v:startTime ?startTime }""")
+----
+
+[[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.
+
+[gremlin-groovy,existing]
+----
+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 * 
+WHERE {
+  ?person v:label "person" .
+  ?person v:age ?age .
+} 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 * 
+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.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT COUNT(?project) 
+WHERE {
+  ?person v:label "person" .
+  ?person v:age ?age . FILTER (?age < 30)
+  ?person e:created ?project .
+} GROUP BY (?age) LIMIT 2""")
+----
+
+[[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 neighbourhood queries. For instance, getting all the information about a specific `person` or `software`.
+
+[gremlin-groovy,existing]
+----
+g.sparql("""SELECT ?age ?software ?name ?location ?startTime 
+WHERE {
+  ?person v:name "daniel" .
+  ?person v:age ?age .
+  ?person e:created ?software .
+  ?person p:location ?location .
+  ?location v:value ?name .
+  ?location v:startTime ?startTime }""")
+----


[31/50] tinkerpop git commit: TINKERPOP-1878 Added a test for GROUP

Posted by sp...@apache.org.
TINKERPOP-1878 Added a test for GROUP


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

Branch: refs/heads/TINKERPOP-1878
Commit: 33626cb67b0ea4987792f71d346ba8f05f238f1d
Parents: c0efbef
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jan 29 09:09:07 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../dsl/sparql/SparqlTraversalSourceTest.java       | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/33626cb6/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
index 56d62c9..0e56347 100644
--- a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
@@ -110,6 +110,7 @@ public class SparqlTraversalSourceTest {
         assertEquals(x.get("a"), _g.V(1).next());
         assertEquals(x.get("b"), _g.V(4).next());
         assertEquals(x.get("c"), _g.V(3).next());
+        assertEquals(3, x.size());
     }
 
     @Test
@@ -134,4 +135,19 @@ public class SparqlTraversalSourceTest {
                         "ORDER BY ?name").toList();
         assertThat(x, contains("josh", "marko", "peter"));
     }
+
+    @Test
+    public void shouldGroup() {
+        final Map<String,Long> x = (Map) g.sparql(
+                "SELECT ?name (COUNT(?name) AS ?name_count)\n" +
+                        "WHERE {\n" +
+                        "    ?a e:created ?b .\n" +
+                        "    ?a v:name ?name .\n" +
+                        "}" +
+                        "GROUP BY ?name").next();
+        assertEquals(new Long(2), x.get("josh"));
+        assertEquals(new Long(1), x.get("peter"));
+        assertEquals(new Long(1), x.get("marko"));
+        assertEquals(3, x.size());
+    }
 }


[30/50] tinkerpop git commit: TINKERPOP-1878 Code reformatting - bad spacing/tabs or something

Posted by sp...@apache.org.
TINKERPOP-1878 Code reformatting - bad spacing/tabs or something


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

Branch: refs/heads/TINKERPOP-1878
Commit: 9f84825451385b51d4bdc38e96f5f038d700d48a
Parents: 326e35d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jan 26 16:03:49 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../sparql/SparqlToGremlinTranspiler.java       | 138 +++++++++----------
 1 file changed, 69 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9f848254/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
index c3bc907..1b28a1d 100644
--- 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
@@ -55,59 +55,59 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
  */
 public class SparqlToGremlinTranspiler {
 
-	private GraphTraversal<Vertex, ?> traversal;
+    private GraphTraversal<Vertex, ?> traversal;
 
     private List<Traversal> traversalList = new ArrayList<>();
 
-	private SparqlToGremlinTranspiler(final GraphTraversal<Vertex, ?> traversal) {
-		this.traversal = traversal;
-	}
+    private SparqlToGremlinTranspiler(final GraphTraversal<Vertex, ?> traversal) {
+        this.traversal = traversal;
+    }
 
-	private SparqlToGremlinTranspiler(final GraphTraversalSource g) {
-		this(g.V());
-	}
+    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 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);
+        return transpile(graph.traversal(), sparqlQuery);
     }
 
     /**
      * Converts SPARQL to a Gremlin traversal.
      *
-     * @param g the {@link GraphTraversalSource} instance to execute the traversal from
+     * @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());
+    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();
+        int traversalIndex = 0;
+        final int numberOfTraversal = traversalList.size();
         final Traversal arrayOfAllTraversals[] = new Traversal[numberOfTraversal];
 
-		for (Traversal tempTrav : traversalList) {
-			arrayOfAllTraversals[traversalIndex++] = tempTrav;
-		}
+        for (Traversal tempTrav : traversalList) {
+            arrayOfAllTraversals[traversalIndex++] = tempTrav;
+        }
 
-		// creates a map of ordering keys and their ordering direction
+        // 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);
+        if (traversalList.size() > 0)
+            traversal = traversal.match(arrayOfAllTraversals);
 
-		final List<String> vars = query.getResultVars();
-		if (!query.isQueryResultStar() && !query.hasGroupBy()) {
-		    // the result sizes have special handling to get the right signatures of select() called. perhaps this
+        final List<String> vars = query.getResultVars();
+        if (!query.isQueryResultStar() && !query.hasGroupBy()) {
+            // the result sizes have special handling to get the right signatures of select() called. perhaps this
             // could be refactored to work more nicely
             switch (vars.size()) {
                 case 0:
@@ -116,7 +116,7 @@ public class SparqlToGremlinTranspiler {
                     if (query.isDistinct())
                         traversal = traversal.dedup(vars.get(0));
 
-                    orderingIndex.forEach((k,v) -> traversal = traversal.order().by(__.select(k), v));
+                    orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
                     traversal = traversal.select(vars.get(0));
 
                     break;
@@ -124,7 +124,7 @@ public class SparqlToGremlinTranspiler {
                     if (query.isDistinct())
                         traversal = traversal.dedup(vars.get(0), vars.get(1));
 
-                    orderingIndex.forEach((k,v) -> traversal = traversal.order().by(__.select(k), v));
+                    orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
                     traversal = traversal.select(vars.get(0), vars.get(1));
 
                     break;
@@ -134,7 +134,7 @@ public class SparqlToGremlinTranspiler {
                     if (query.isDistinct())
                         traversal = traversal.dedup(all);
 
-                    orderingIndex.forEach((k,v) -> traversal = traversal.order().by(__.select(k), v));
+                    orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
 
                     // just some shenanigans to get the right signature of select() called
                     final String[] others = Arrays.copyOfRange(all, 2, vars.size());
@@ -142,59 +142,59 @@ public class SparqlToGremlinTranspiler {
 
                     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()) {
+        }
+
+        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 {
+                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 {
+                    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.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.hasLimit()) {
+            long limit = query.getLimit(), offset = 0;
 
-			if (query.hasOffset())
-				offset = query.getOffset();
+            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);
-		}
+            if (query.hasGroupBy() && query.hasOrderBy())
+                traversal = traversal.range(Scope.local, offset, offset + limit);
+            else
+                traversal = traversal.range(offset, offset + limit);
+        }
 
-		return traversal;
-	}
+        return traversal;
+    }
 
     /**
      * Extracts any {@code SortCondition} instances from the SPARQL query and holds them in an index of their keys


[19/50] tinkerpop git commit: TINKERPOP-1878 Updates to changelog and code comments

Posted by sp...@apache.org.
TINKERPOP-1878 Updates to changelog and code comments


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

Branch: refs/heads/TINKERPOP-1878
Commit: 60146b5405edf3e4fe5ca7734a0971d082b75a4f
Parents: 623ead8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 17:09:17 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                             | 1 +
 .../process/traversal/dsl/sparql/SparqlTraversalSource.java    | 6 ++++++
 2 files changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/60146b54/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 303d963..a175c99 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -111,6 +111,7 @@ This release also includes changes from <<release-3-2-8, 3.2.8>>.
 
 * Fixed regression issue where the HTTPChannelizer doesn't instantiate the specified AuthenticationHandler.
 * Defaulted GLV tests for gremlin-python to run for GraphSON 3.0.
+* Fixed a bug in dynamic Gryo registration where registrations that did not have serializers would fail.
 * Fixed a bug with `Tree` serialization in GraphSON 3.0.
 * In gremlin-python, the GraphSON 3.0 `g:Set` type is now deserialized to `List`.
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/60146b54/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
index 3889d95..deb16f7 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -124,6 +124,12 @@ public class SparqlTraversalSource implements TraversalSource {
      */
     public <S> SparqlTraversal<S,String> sparql(final String query) {
         final SparqlTraversalSource clone = this.clone();
+
+        // this is a bit of a hack to get remote traversals to work cleanly. on the remote side, we'd expect a
+        // GraphTraversalSource not a SparqlTraversalSource (given that sparql-gremlin is to be implemented in the
+        // DSL pattern). Instead of just sending the constant() step with the sparql query we also include an
+        // inject() step which will be recognized by a GraphTraversalSource on the remote side. Since SparqlStrategy
+        // wholly replaces both of these steps, the traversal bytecode can be read properly.
         clone.bytecode.addStep(GraphTraversal.Symbols.inject);
         clone.bytecode.addStep(GraphTraversal.Symbols.constant, query);
         final SparqlTraversal.Admin<S, S> traversal = new DefaultSparqlTraversal<>(clone);


[41/50] tinkerpop git commit: TINKERPOP-1878 Clean up docs a bit more.

Posted by sp...@apache.org.
TINKERPOP-1878 Clean up docs a bit more.


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

Branch: refs/heads/TINKERPOP-1878
Commit: 8f124764b6da8d6173b6abb793a5d31f7481fbc5
Parents: ea3e891
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sun May 13 10:53:56 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/src/reference/transpilers.asciidoc | 36 +++++++++++++---------------
 1 file changed, 16 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8f124764/docs/src/reference/transpilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/transpilers.asciidoc b/docs/src/reference/transpilers.asciidoc
index b05be68..390d4f4 100644
--- a/docs/src/reference/transpilers.asciidoc
+++ b/docs/src/reference/transpilers.asciidoc
@@ -24,23 +24,20 @@ Gremlin Transpiler enables a particular query language to work on any TinkerPop-
 
 == SPARQL-Gremlin
 
-image:https://raw.githubusercontent.com/LITMUS-Benchmark-Suite/sparql-to-gremlin/master/docs/images/sparql-gremlin-logo.png[gremlinator]
+image::gremlin-standing.png[]
 
-The SPARQL-Gremlin transpiler, transforms link:https://en.wikipedia.org/wiki/SPARQL[SPARQL] queries into Gremlin traversals. It is based on the  https://jena.apache.org/index.html[Apache Jena] SPARQL processor https://jena.apache.org/documentation/query/index.html[ARQ], which provides access to a syntax tree of a SPARQL query.
+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).
 
-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 from -
-https://arxiv.org/pdf/1801.02911.pdf[Gremlinator full paper]. In this
-paper, we present and discuss the notion of graph query language
-semantics of SPARQL and Gremlin, and a formal mapping between SPARQL
-pattern matching graph patterns and Gremlin traversals. Furthermore, we
-point the interested reader to the following resourcesfor a better
-understanding: (1) Gremlinator demonstration -
-(http://gremlinator.iai.uni-bonn.de:8080/Demo/[Public Demo Mirror 1])
-and (http://195.201.31.31:8080/Demo/[Public Demo Mirror 2]); (2) A short video tutorial on how to use the demonstration - https://www.youtube.com/watch?v=Z0ETx2IBamw[here]
+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]
 ----
@@ -111,9 +108,9 @@ g.sparql("""SELECT ?name ?id ?label
 [[supported-queries]]
 === Supported Queries
 
-The SPARQL-Gremlin transpiler is currently an on-going effort with an aim to cover the entire SPARQL 1.1 query feature
-spectrum, however we currently only support translation of the SPARQL 1.0 specification, especially _SELECT_ queries.
-The supported SPARQL query types are:
+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 
@@ -129,8 +126,7 @@ The supported SPARQL query types are:
 [[limitations]]
 === Limitations
 
-The current implementation of SPARQL-Gremlin transpiler (i.e. SPARQL-Gremlin) does
-not support the following cases: 
+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:
@@ -143,7 +139,7 @@ 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).
+(two patterns `union` 1 pattern).
 
 [source,groovy]
 ----


[50/50] tinkerpop git commit: TINKERPOP-1878 Added upgrade docs for sparql-gremlin

Posted by sp...@apache.org.
TINKERPOP-1878 Added upgrade docs for sparql-gremlin


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

Branch: refs/heads/TINKERPOP-1878
Commit: 7802de5b96ff2f1717787f2c9c288e83a4ed5e55
Parents: 37a38ae
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Aug 8 07:42:13 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:32 2018 -0400

----------------------------------------------------------------------
 docs/src/upgrade/release-3.4.x.asciidoc | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7802de5b/docs/src/upgrade/release-3.4.x.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.4.x.asciidoc b/docs/src/upgrade/release-3.4.x.asciidoc
index 587e761..8a7bfa1 100644
--- a/docs/src/upgrade/release-3.4.x.asciidoc
+++ b/docs/src/upgrade/release-3.4.x.asciidoc
@@ -29,6 +29,23 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.4.0/CHANGELOG.asc
 
 === Upgrading for Users
 
+==== sparql-gremlin
+
+The `sparql-gremlin` module is a link:https://en.wikipedia.org/wiki/SPARQL[SPARQL] to Gremlin compiler, which allows
+SPARQL to be executed over any TinkerPop-enabled graph system.
+
+[source,groovy]
+----
+graph = TinkerFactory.createModern()
+g = graph.traversal(SparqlTraversalSource)
+g.sparql("""SELECT ?name ?age
+            WHERE { ?person v:name ?name . ?person v:age ?age }
+            ORDER BY ASC(?age)""")
+----
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1878[TINKERPOP-1878],
+link:http://tinkerpop.apache.org/docs/3.4.0/reference/#sparql-gremlin[Reference Documentation]
+
 ==== with() Step
 
 This version of TinkerPop introduces the `with()`-step to Gremlin. It isn't really a step but is instead a step


[33/50] tinkerpop git commit: TINKERPOP-1878 Added a basics for sparql execution in a traversal

Posted by sp...@apache.org.
TINKERPOP-1878 Added a basics for sparql execution in a traversal


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

Branch: refs/heads/TINKERPOP-1878
Commit: 4926b20a75cd434702969479167209934560c111
Parents: 5533cdc
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 14:46:31 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../traversal/step/map/ConstantStep.java        |  4 ++
 .../traversal/strategy/SparqlStrategy.java      | 56 +++++++++++++++++++-
 .../dsl/sparql/SparqlTraversalSourceTest.java   | 39 ++++++++++++++
 .../src/test/resources/log4j-silent.properties  | 23 ++++++++
 .../src/test/resources/log4j-test.properties    | 23 ++++++++
 5 files changed, 144 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4926b20a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java
index 5d02e28..749de31 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java
@@ -36,6 +36,10 @@ public class ConstantStep<S, E> extends MapStep<S, E> {
         this.constant = constant;
     }
 
+    public E getConstant() {
+        return this.constant;
+    }
+
     @Override
     protected E map(final Traverser.Admin<S> traverser) {
         return this.constant;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4926b20a/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 6440127..07ac4cf 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
@@ -18,8 +18,62 @@
  */
 package org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy;
 
+import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.TraversalMapStep;
+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.SparqlToGremlinCompiler;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+import java.util.Collections;
+import java.util.Set;
+
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
-public class SparqlStrategy {
+public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.DecorationStrategy>
+        implements TraversalStrategy.DecorationStrategy {
+    private static final SparqlStrategy INSTANCE = new SparqlStrategy();
+
+    private static final Set<Class<? extends DecorationStrategy>> POSTS = Collections.singleton(VertexProgramStrategy.class);
+
+    private SparqlStrategy() {}
+
+    public static SparqlStrategy instance() {
+        return INSTANCE;
+    }
+
+    @Override
+    public Set<Class<? extends DecorationStrategy>> applyPost() {
+        return POSTS;
+    }
+
+
+    @Override
+    public void apply(final Traversal.Admin<?, ?> traversal) {
+        if (!(traversal.getParent() instanceof EmptyStep))
+            return;
+
+        if (traversal.getSteps().size() == 1 && traversal.getEndStep() instanceof ConstantStep) {
+            final ConstantStep stepWithSparql = (ConstantStep) traversal.getEndStep();
+            final Object constant = stepWithSparql.getConstant();
+            if (constant instanceof String) {
+                final String sparql = (String) constant;
+                final Traversal<Vertex, ?> sparqlTraversal = SparqlToGremlinCompiler.convertToGremlinTraversal(
+                        traversal.getGraph().get(), sparql);
+                TraversalHelper.removeAllSteps(traversal);
+                sparqlTraversal.asAdmin().getSteps().forEach(s -> traversal.addStep(s));
+            } else {
+                // The ConstantStep expects a string value
+                throw new IllegalStateException("SparqlStrategy cannot be applied to this traversal");
+            }
+        } else {
+            // SparqlStrategy requires that there be one step and it be a ConstantStep that contains some SPARQL
+            throw new IllegalStateException("SparqlStrategy cannot be applied to this traversal");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4926b20a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
new file mode 100644
index 0000000..9e5ffc0
--- /dev/null
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.process.traversal.dsl.sparql;
+
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStrategy;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.junit.Test;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class SparqlTraversalSourceTest {
+
+    @Test
+    public void shouldDoStuff() {
+        final Graph graph = TinkerFactory.createModern();
+        final SparqlTraversalSource g = graph.traversal(SparqlTraversalSource.class).
+                                                withStrategies(SparqlStrategy.instance());
+        final Object x = g.sparql("SELECT ?name ?age WHERE { ?person v:name ?name . ?person v:age ?age }").toList();
+        System.out.println(x);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4926b20a/sparql-gremlin/src/test/resources/log4j-silent.properties
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/resources/log4j-silent.properties b/sparql-gremlin/src/test/resources/log4j-silent.properties
new file mode 100644
index 0000000..1825bb0
--- /dev/null
+++ b/sparql-gremlin/src/test/resources/log4j-silent.properties
@@ -0,0 +1,23 @@
+# 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.
+
+# this file should always have logging set to OFF.  it seems, however, that an appender of some sort is
+# required or else some logs throw error and use other log4j.properties files on the path.
+log4j.rootLogger=OFF, stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4926b20a/sparql-gremlin/src/test/resources/log4j-test.properties
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/resources/log4j-test.properties b/sparql-gremlin/src/test/resources/log4j-test.properties
new file mode 100644
index 0000000..79038b1
--- /dev/null
+++ b/sparql-gremlin/src/test/resources/log4j-test.properties
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+log4j.rootLogger=WARN, stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n
\ No newline at end of file


[09/50] tinkerpop git commit: Merge branch 'tp32' into tp33

Posted by sp...@apache.org.
Merge branch 'tp32' into tp33


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

Branch: refs/heads/TINKERPOP-1878
Commit: 2cf551f089221f29e38627cf684fd89d6b3a3cea
Parents: 3e308f5 2d315e8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 7 06:30:22 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 7 06:30:22 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                                | 1 +
 .../tinkerpop/gremlin/server/util/GremlinServerInstall.java       | 3 +++
 2 files changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2cf551f0/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2cf551f0/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java
----------------------------------------------------------------------


[26/50] tinkerpop git commit: TINKERPOP-1878 General refactoring and javadoc on Prefixes class

Posted by sp...@apache.org.
TINKERPOP-1878 General refactoring and javadoc on Prefixes class


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

Branch: refs/heads/TINKERPOP-1878
Commit: 9b2fbc134856f139e38adc609b242bc818f9a33a
Parents: 8a8d2e1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jan 26 09:39:28 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/sparql/Prefixes.java      | 23 ++++++++++----------
 1 file changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9b2fbc13/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/Prefixes.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/Prefixes.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/Prefixes.java
index 452bf68..32768a7 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/Prefixes.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/Prefixes.java
@@ -22,15 +22,16 @@ package org.apache.tinkerpop.gremlin.sparql;
 import java.util.Arrays;
 import java.util.List;
 
+/**
+ * Helper methods for working with prefix lines in SPARQL queries.
+ */
+class Prefixes {
 
-public class Prefixes {
-
-	// public final static String BASE_URI = "http://northwind.com/model/";
-    public final static String BASE_URI = "http://www.tinkerpop.com/traversal/";
+    final static String BASE_URI = "http://tinkerpop.apache.org/traversal/";
 
-    final static List<String> PREFIXES = Arrays.asList("edge", "property", "value");
+    private final static List<String> PREFIXES = Arrays.asList("edge", "property", "value");
 
-    final static String PREFIX_DEFINITIONS;
+    private final static String PREFIX_DEFINITIONS;
 
     static {
         final StringBuilder builder = new StringBuilder();
@@ -41,24 +42,24 @@ public class Prefixes {
         PREFIX_DEFINITIONS = builder.toString();
     }
 
-    public static String getURI(final String prefix) {
+    static String getURI(final String prefix) {
         return BASE_URI + prefix + "#";
     }
 
-    public static String getURIValue(final String uri) {
+    static String getURIValue(final String uri) {
         return uri.substring(uri.indexOf("#") + 1);
     }
 
-    public static String getPrefix(final String uri) {
+    static String getPrefix(final String uri) {
         final String tmp = uri.substring(0, uri.indexOf("#"));
         return tmp.substring(tmp.lastIndexOf("/") + 1);
     }
 
-    public static String prepend(final String script) {
+    static String prepend(final String script) {
         return PREFIX_DEFINITIONS + script;
     }
 
-    public static StringBuilder prepend(final StringBuilder scriptBuilder) {
+    static StringBuilder prepend(final StringBuilder scriptBuilder) {
         return scriptBuilder.insert(0, PREFIX_DEFINITIONS);
     }
 }


[21/50] tinkerpop git commit: TINKERPOP-1878 Dropped the console app

Posted by sp...@apache.org.
TINKERPOP-1878 Dropped the console app

This allows TinkerGraph to remain a test dependency only and the console app was more of a test rig than something that a user of this library would use, so it seemed like something that could be dropped.


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

Branch: refs/heads/TINKERPOP-1878
Commit: 64b0a1eee07f8ca4c77f660680a07db0437cf43b
Parents: 4926b20
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 14:49:18 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 sparql-gremlin/pom.xml                          |   1 +
 .../gremlin/sparql/ConsoleCompiler.java         | 165 -------------------
 2 files changed, 1 insertion(+), 165 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/64b0a1ee/sparql-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/sparql-gremlin/pom.xml b/sparql-gremlin/pom.xml
index d38a85d..0dceb85 100644
--- a/sparql-gremlin/pom.xml
+++ b/sparql-gremlin/pom.xml
@@ -42,6 +42,7 @@
             <groupId>org.apache.tinkerpop</groupId>
             <artifactId>tinkergraph-gremlin</artifactId>
             <version>${project.version}</version>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.tinkerpop</groupId>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/64b0a1ee/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java
deleted file mode 100644
index 0d50475..0000000
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java
+++ /dev/null
@@ -1,165 +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.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.DefaultParser;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
-import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.io.IoCore;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
-
-import org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinCompiler;
-
-class ConsoleCompiler {
-
-    public static void main(final String[] args) throws IOException {
-    	//args = "/examples/modern1.sparql";
-        final Options options = new Options();
-        options.addOption("f", "file", true, "a file that contains a SPARQL query");
-        options.addOption("g", "graph", true, "the graph that's used to execute the query [classic|modern|crew|kryo file]");
-        // TODO: add an OLAP option (perhaps: "--olap spark"?)
-
-        final CommandLineParser parser = new DefaultParser();
-        final CommandLine commandLine;
-
-        try {
-            commandLine = parser.parse(options, args);
-        } catch (ParseException e) {
-            System.out.println(e.getMessage());
-            printHelp(1);
-            return;
-        }
-        
-        final InputStream inputStream = commandLine.hasOption("file")
-                ? new FileInputStream(commandLine.getOptionValue("file"))
-                : System.in;
-        final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-        final StringBuilder queryBuilder = new StringBuilder();
-
-        if (!reader.ready()) {
-            printHelp(1);
-        }
-
-        String line;
-        while (null != (line = reader.readLine())) {
-            queryBuilder.append(System.lineSeparator()).append(line);
-        }
-
-        final String queryString = queryBuilder.toString();
-        Graph graph;
-        
-        if (commandLine.hasOption("graph")) {
-            switch (commandLine.getOptionValue("graph").toLowerCase()) {
-                case "classic":
-                    graph = TinkerFactory.createClassic();
-                    break;
-                case "modern":
-                    graph = TinkerFactory.createModern();
-                    System.out.println("Modern Graph Created");
-                    break;
-                case "crew":
-                    graph = TinkerFactory.createTheCrew();
-                    break;
-                default:
-                    graph = TinkerGraph.open();
-                    System.out.println("Graph Created");
-                    String graphName = commandLine.getOptionValue("graph");
-                    long startTime= System.currentTimeMillis();
-                    if(graphName.endsWith(".graphml"))
-                    	graph.io(IoCore.graphml()).readGraph(graphName);
-                    else if(graphName.endsWith(".kryo")||graphName.endsWith("gryo"))
-                    	graph.io(IoCore.gryo()).readGraph(graphName);
-                    long endTime = System.currentTimeMillis();
-                    System.out.println("Time taken to load graph from kyro file: "+ (endTime-startTime)+" mili seconds");
-                    break;
-            }
-        } else {
- 
-            graph = TinkerFactory.createModern();
-        }
-
-        long startTime = System.currentTimeMillis();
-        final Traversal<Vertex, ?> traversal = SparqlToGremlinCompiler.convertToGremlinTraversal(graph, queryString);
-        long endTime = System.currentTimeMillis();
-        System.out.println("Time traken to convert SPARQL to Gremlin Traversal : "+ (endTime - startTime)+ " miliseconds");
-        
-        printWithHeadline("SPARQL Query", queryString);
-        // printWithHeadline("Traversal (prior execution)", traversal);
-  
-        
-        Bytecode traversalByteCode = traversal.asAdmin().getBytecode();
-        
-        
-//        JavaTranslator.of(graph.traversal()).translate(traversalByteCode);
-//        
-//        System.out.println("the Byte Code : "+ traversalByteCode.toString());
-        printWithHeadline("Result", String.join(System.lineSeparator(),JavaTranslator.of(graph.traversal()).translate(traversalByteCode).toStream().map(Object::toString).collect(Collectors.toList())));
-        // printWithHeadline("Traversal (after execution)", traversal);
-    }
-
-    private static void printHelp(final int exitCode) throws IOException {
-        final Map<String, String> env = System.getenv();
-        final String command = env.containsKey("LAST_COMMAND") ? env.get("LAST_COMMAND") : "sparql-gremlin.sh";
-        printWithHeadline("Usage Examples", String.join("\n",
-                command + " -f examples/modern1.sparql",
-                command + " < examples/modern2.sparql",
-                command + " <<< 'SELECT * WHERE { ?a e:knows ?b }'",
-                command + " -g crew < examples/crew1.sparql"));
-        if (exitCode >= 0) {
-            System.exit(exitCode);
-        }
-    }
-
-    private static void printWithHeadline(final String headline, final Object content) throws IOException {
-        final StringReader sr = new StringReader(content != null ? content.toString() : "null");
-        final BufferedReader br = new BufferedReader(sr);
-        String line;
-        System.out.println();
-        System.out.println( headline ); 
-        System.out.println();
-        boolean skip = true;
-        while (null != (line = br.readLine())) {
-            skip &= line.isEmpty();
-            if (!skip) {
-                System.out.println("  " + line);
-            }
-        }
-        System.out.println();
-        br.close();
-        sr.close();
-    }
-}


[38/50] tinkerpop git commit: TINKERPOP-1878 Minor formatting fix

Posted by sp...@apache.org.
TINKERPOP-1878 Minor formatting fix


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

Branch: refs/heads/TINKERPOP-1878
Commit: f46f677ea8661bdd95672054941f8c0bbc31db9b
Parents: b780311
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Aug 1 10:01:51 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompiler.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f46f677e/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
index e3b4ecb..4e00045 100644
--- 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
@@ -35,7 +35,7 @@ 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.OpLeftJoin;  
+import org.apache.jena.sparql.algebra.op.OpLeftJoin;
 import org.apache.jena.sparql.algebra.op.OpUnion;
 import org.apache.jena.sparql.core.Var;
 import org.apache.jena.sparql.core.VarExprList;


[18/50] tinkerpop git commit: Initial commit for sparql-gremlin changes

Posted by sp...@apache.org.
Initial commit for sparql-gremlin changes


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

Branch: refs/heads/TINKERPOP-1878
Commit: 523c7f00b5f827cbdab6a871b735393f4410bd0f
Parents: 9357d6a
Author: harsh9t <ha...@gmail.com>
Authored: Thu Jan 18 01:33:29 2018 +0100
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:29 2018 -0400

----------------------------------------------------------------------
 sparql-gremlin/pom.xml                          |  63 +++
 .../gremlin/sparql/ConsoleCompiler.java         | 165 ++++++++
 .../tinkerpop/gremlin/sparql/Prefixes.java      |  64 ++++
 .../gremlin/sparql/SparqlToGremlinCompiler.java | 381 +++++++++++++++++++
 .../gremlin/sparql/TraversalBuilder.java        |  82 ++++
 .../gremlin/sparql/WhereTraversalBuilder.java   | 134 +++++++
 .../tinkerpop/gremlin/sparql/PrefixesTest.java  |  67 ++++
 .../gremlin/sparql/ResourceHelper.java          |  37 ++
 .../sparql/SparqlToGremlinCompilerTest.java     | 223 +++++++++++
 9 files changed, 1216 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523c7f00/sparql-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/sparql-gremlin/pom.xml b/sparql-gremlin/pom.xml
new file mode 100644
index 0000000..e134d31
--- /dev/null
+++ b/sparql-gremlin/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>tinkerpop</artifactId>
+        <groupId>org.apache.tinkerpop</groupId>
+        <version>3.3.2-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>sparql-gremlin</artifactId>
+    <organization>
+        <name>WDAQUA-ITN</name>
+        <url>http://wdaqua.eu</url>
+    </organization>
+    <developers>
+        <developer>
+            <name>Harsh Thakkar</name>
+            <email>harsh9t@gmail.com</email>
+            <organization>University of Bonn</organization>
+            <organizationUrl>http://harshthakkar.in</organizationUrl>
+        </developer>
+        <developer>
+            <name>Dharmen Punjani</name>
+            <email>dharmen.punjani@gmail.com</email>
+            <organization>National and Kapodistrian University of Athens</organization>
+            <organizationUrl>http://wdaqua.eu/students/dharmen-punjani</organizationUrl>
+        </developer>
+    </developers>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <jena.version>3.0.0</jena.version>
+        <query.dir>src/test/resources/sparql/queries</query.dir>
+    </properties>
+
+    <dependencies>
+    <dependency>
+        <groupId>org.apache.jena</groupId>
+        <artifactId>apache-jena-libs</artifactId>
+        <type>pom</type>
+        <version>${jena.version}</version>
+    </dependency>
+        <dependency>
+            <groupId>org.apache.tinkerpop</groupId>
+            <artifactId>gremlin-core</artifactId>
+            <version>3.3.2-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tinkerpop</groupId>
+            <artifactId>tinkergraph-gremlin</artifactId>
+            <version>3.3.2-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tinkerpop</groupId>
+            <artifactId>gremlin-test</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523c7f00/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java
new file mode 100644
index 0000000..0d50475
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java
@@ -0,0 +1,165 @@
+/*
+ * 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.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.IoCore;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+
+import org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinCompiler;
+
+class ConsoleCompiler {
+
+    public static void main(final String[] args) throws IOException {
+    	//args = "/examples/modern1.sparql";
+        final Options options = new Options();
+        options.addOption("f", "file", true, "a file that contains a SPARQL query");
+        options.addOption("g", "graph", true, "the graph that's used to execute the query [classic|modern|crew|kryo file]");
+        // TODO: add an OLAP option (perhaps: "--olap spark"?)
+
+        final CommandLineParser parser = new DefaultParser();
+        final CommandLine commandLine;
+
+        try {
+            commandLine = parser.parse(options, args);
+        } catch (ParseException e) {
+            System.out.println(e.getMessage());
+            printHelp(1);
+            return;
+        }
+        
+        final InputStream inputStream = commandLine.hasOption("file")
+                ? new FileInputStream(commandLine.getOptionValue("file"))
+                : System.in;
+        final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+        final StringBuilder queryBuilder = new StringBuilder();
+
+        if (!reader.ready()) {
+            printHelp(1);
+        }
+
+        String line;
+        while (null != (line = reader.readLine())) {
+            queryBuilder.append(System.lineSeparator()).append(line);
+        }
+
+        final String queryString = queryBuilder.toString();
+        Graph graph;
+        
+        if (commandLine.hasOption("graph")) {
+            switch (commandLine.getOptionValue("graph").toLowerCase()) {
+                case "classic":
+                    graph = TinkerFactory.createClassic();
+                    break;
+                case "modern":
+                    graph = TinkerFactory.createModern();
+                    System.out.println("Modern Graph Created");
+                    break;
+                case "crew":
+                    graph = TinkerFactory.createTheCrew();
+                    break;
+                default:
+                    graph = TinkerGraph.open();
+                    System.out.println("Graph Created");
+                    String graphName = commandLine.getOptionValue("graph");
+                    long startTime= System.currentTimeMillis();
+                    if(graphName.endsWith(".graphml"))
+                    	graph.io(IoCore.graphml()).readGraph(graphName);
+                    else if(graphName.endsWith(".kryo")||graphName.endsWith("gryo"))
+                    	graph.io(IoCore.gryo()).readGraph(graphName);
+                    long endTime = System.currentTimeMillis();
+                    System.out.println("Time taken to load graph from kyro file: "+ (endTime-startTime)+" mili seconds");
+                    break;
+            }
+        } else {
+ 
+            graph = TinkerFactory.createModern();
+        }
+
+        long startTime = System.currentTimeMillis();
+        final Traversal<Vertex, ?> traversal = SparqlToGremlinCompiler.convertToGremlinTraversal(graph, queryString);
+        long endTime = System.currentTimeMillis();
+        System.out.println("Time traken to convert SPARQL to Gremlin Traversal : "+ (endTime - startTime)+ " miliseconds");
+        
+        printWithHeadline("SPARQL Query", queryString);
+        // printWithHeadline("Traversal (prior execution)", traversal);
+  
+        
+        Bytecode traversalByteCode = traversal.asAdmin().getBytecode();
+        
+        
+//        JavaTranslator.of(graph.traversal()).translate(traversalByteCode);
+//        
+//        System.out.println("the Byte Code : "+ traversalByteCode.toString());
+        printWithHeadline("Result", String.join(System.lineSeparator(),JavaTranslator.of(graph.traversal()).translate(traversalByteCode).toStream().map(Object::toString).collect(Collectors.toList())));
+        // printWithHeadline("Traversal (after execution)", traversal);
+    }
+
+    private static void printHelp(final int exitCode) throws IOException {
+        final Map<String, String> env = System.getenv();
+        final String command = env.containsKey("LAST_COMMAND") ? env.get("LAST_COMMAND") : "sparql-gremlin.sh";
+        printWithHeadline("Usage Examples", String.join("\n",
+                command + " -f examples/modern1.sparql",
+                command + " < examples/modern2.sparql",
+                command + " <<< 'SELECT * WHERE { ?a e:knows ?b }'",
+                command + " -g crew < examples/crew1.sparql"));
+        if (exitCode >= 0) {
+            System.exit(exitCode);
+        }
+    }
+
+    private static void printWithHeadline(final String headline, final Object content) throws IOException {
+        final StringReader sr = new StringReader(content != null ? content.toString() : "null");
+        final BufferedReader br = new BufferedReader(sr);
+        String line;
+        System.out.println();
+        System.out.println( headline ); 
+        System.out.println();
+        boolean skip = true;
+        while (null != (line = br.readLine())) {
+            skip &= line.isEmpty();
+            if (!skip) {
+                System.out.println("  " + line);
+            }
+        }
+        System.out.println();
+        br.close();
+        sr.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523c7f00/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/Prefixes.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/Prefixes.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/Prefixes.java
new file mode 100644
index 0000000..452bf68
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/Prefixes.java
@@ -0,0 +1,64 @@
+/*
+ * 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.Arrays;
+import java.util.List;
+
+
+public class Prefixes {
+
+	// public final static String BASE_URI = "http://northwind.com/model/";
+    public final static String BASE_URI = "http://www.tinkerpop.com/traversal/";
+
+    final static List<String> PREFIXES = Arrays.asList("edge", "property", "value");
+
+    final static String PREFIX_DEFINITIONS;
+
+    static {
+        final StringBuilder builder = new StringBuilder();
+        for (final String prefix : PREFIXES) {
+            builder.append("PREFIX ").append(prefix.substring(0, 1)).append(": <").append(getURI(prefix)).
+                    append(">").append(System.lineSeparator());
+        }
+        PREFIX_DEFINITIONS = builder.toString();
+    }
+
+    public static String getURI(final String prefix) {
+        return BASE_URI + prefix + "#";
+    }
+
+    public static String getURIValue(final String uri) {
+        return uri.substring(uri.indexOf("#") + 1);
+    }
+
+    public static String getPrefix(final String uri) {
+        final String tmp = uri.substring(0, uri.indexOf("#"));
+        return tmp.substring(tmp.lastIndexOf("/") + 1);
+    }
+
+    public static String prepend(final String script) {
+        return PREFIX_DEFINITIONS + script;
+    }
+
+    public static StringBuilder prepend(final StringBuilder scriptBuilder) {
+        return scriptBuilder.insert(0, PREFIX_DEFINITIONS);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523c7f00/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..adb36e9
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompiler.java
@@ -0,0 +1,381 @@
+/*
+ * 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.List;
+
+import org.apache.jena.graph.Triple;
+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.OpLeftJoin;
+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;
+
+// TODO: implement OpVisitor, don't extend OpVisitorBase
+public class SparqlToGremlinCompiler extends OpVisitorBase {
+
+	private GraphTraversal<Vertex, ?> traversal;
+
+	List<Traversal> traversalList = new ArrayList<Traversal>();
+
+	String groupVariable = "";
+	int sortingDirection = 0;
+	long offsetLimit = 0;
+	String sortingVariable = "";
+
+	GraphTraversalSource temp;
+	Graph graph;
+
+	private SparqlToGremlinCompiler(final GraphTraversal<Vertex, ?> traversal) {
+		this.traversal = traversal;
+	}
+
+	private SparqlToGremlinCompiler(final GraphTraversalSource g) {
+		this(g.V());
+		temp = g;
+
+	}
+
+	private SparqlToGremlinCompiler(final Graph g) {
+		this.traversal = (GraphTraversal<Vertex, ?>) g.traversal();
+		graph = g;
+	}
+
+	public String createMatchStep(String step) {
+		String st = "";
+		step = step.substring(1, step.length() - 2);
+		String first = step.substring(0, step.indexOf(","));
+		String second = step.substring(step.indexOf(",") + 1);
+		//System.out.println("First : " + first);
+		//System.out.println("Second : " + second);
+		st = first.substring(first.indexOf("["), first.length() - 1);
+		st = "[" + st + "," + second + "]";
+		return st;
+	}
+
+	GraphTraversal<Vertex, ?> convertToGremlinTraversal(final Query query) {
+		
+		// long startTime = System.currentTimeMillis();
+		// long endTime;
+		final Op op = Algebra.compile(query); // SPARQL query compiles here to
+												// OP
+//		System.out.println("OP Tree: " + op.toString());
+
+		
+		OpWalker.walk(op, this); // OP is being walked here
+		
+		
+		
+		
+		//System.out.println("time taken for opWalker:"+ (endTime-startTime));
+		// startTime = System.currentTimeMillis();
+		int traversalIndex = 0;
+		int numberOfTraversal = traversalList.size();
+		Traversal arrayOfAllTraversals[] = new Traversal[numberOfTraversal];
+
+		if (query.hasOrderBy() && !query.hasGroupBy()) {
+			List<SortCondition> sortingConditions = query.getOrderBy();
+			int directionOfSort = 0;
+
+			for (SortCondition sortCondition : sortingConditions) {
+				Expr expr = sortCondition.getExpression();
+				directionOfSort = sortCondition.getDirection();
+				sortingVariable = expr.getVarName();
+
+			}
+
+			Order orderDirection = Order.incr;
+			if (directionOfSort == -1) {
+				orderDirection = Order.decr;
+			}
+		}
+		for (Traversal tempTrav : traversalList) {
+
+			arrayOfAllTraversals[traversalIndex++] = tempTrav;
+		}
+
+		int directionOfSort = 0;
+		Order orderDirection = Order.incr;
+		if (query.hasOrderBy()) {
+			List<SortCondition> sortingConditions = query.getOrderBy();
+
+			//
+			for (SortCondition sortCondition : sortingConditions) {
+				Expr expr = sortCondition.getExpression();
+				directionOfSort = sortCondition.getDirection();
+				sortingVariable = expr.getVarName();
+//				System.out.println("order by var: "+sortingDirection);
+			}
+			//
+
+			if (directionOfSort == -1) {
+				orderDirection = Order.decr;
+			}
+
+		}
+
+		if (traversalList.size() > 0)
+			traversal = traversal.match(arrayOfAllTraversals);
+
+		final List<String> vars = query.getResultVars();
+		List<ExprAggregator> lstexpr = query.getAggregators();
+		if (!query.isQueryResultStar() && !query.hasGroupBy()) {
+
+			switch (vars.size()) {
+			case 0:
+				throw new IllegalStateException();
+			case 1:
+				if (query.isDistinct()) {
+//					System.out.println("Inside ------------------- >Select 1------------------------> Distinct");
+					traversal = traversal.dedup(vars.get(0));
+				}
+				if (query.hasOrderBy()) {
+//					System.out.println("Inside ------------------- >Select 1");
+					traversal = traversal.order().by(sortingVariable, orderDirection);
+				} else {
+
+					traversal = traversal.select(vars.get(0));
+				}
+				break;
+			case 2:
+				if (query.isDistinct()) {
+					traversal = traversal.dedup(vars.get(0), vars.get(1));
+				}
+				if (query.hasOrderBy()) {
+//					System.out.println("Inside ------------------- >Select 1");
+					traversal = traversal.order().by(__.select(vars.get(0)), orderDirection).by(__.select(vars.get(1)));
+				} else
+					traversal = traversal.select(vars.get(0), vars.get(1));
+				break;
+			default:
+				final String[] all = new String[vars.size()];
+				vars.toArray(all);
+				if (query.isDistinct()) {
+
+					traversal = traversal.dedup(all);
+				}
+				final String[] others = Arrays.copyOfRange(all, 2, vars.size());
+				if (query.hasOrderBy()) {
+
+					traversal = traversal.order().by(__.select(vars.get(0)), orderDirection).by(__.select(vars.get(1)));
+
+				} else
+					traversal = traversal.select(vars.get(0), vars.get(1), others);
+
+				break;
+			}
+
+		}
+		
+		
+		if (query.hasGroupBy()) {
+			VarExprList lstExpr = query.getGroupBy();
+			String grpVar = "";
+			Traversal tempTrav;
+			for (Var expr : lstExpr.getVars()) {
+				grpVar = expr.getName();
+				// System.out.println("The Group by var: " + expr.getName());
+			}
+
+			if (query.hasLimit()) {
+				long limit = query.getLimit(), offset = 0;
+
+				if (query.hasOffset()) {
+					offset = query.getOffset();
+
+				}
+				// if (query.hasGroupBy() && query.hasOrderBy())
+				// traversal = traversal.range( offset, offset + limit);
+				// else
+				// traversal = traversal.range(offset, offset + limit);
+
+			}
+
+			if (!grpVar.isEmpty())
+				traversal = traversal.select(grpVar);
+			if (query.hasAggregators()) {
+				List<ExprAggregator> exprAgg = query.getAggregators();
+				for (ExprAggregator expr : exprAgg) {
+
+//					System.out.println("The Aggregator by var: " + expr.getAggregator().getExprList().toString()
+//							+ " is :" + expr.getAggregator().toString());
+					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()) {
+
+			traversal = traversal.order().by(sortingVariable, orderDirection);
+		}
+		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);
+
+		}
+		// endTime = System.currentTimeMillis();
+		// System.out.println("time taken for convertToGremlinTraversal Function : "+ (endTime-startTime)+" mili seconds");
+		
+		return traversal;
+	}
+
+	private static GraphTraversal<Vertex, ?> convertToGremlinTraversal(final GraphTraversalSource g,
+			final Query query) {
+		return new SparqlToGremlinCompiler(g).convertToGremlinTraversal(query);
+	}
+
+	public static GraphTraversal<Vertex, ?> convertToGremlinTraversal(final Graph graph, final String query) {
+		return convertToGremlinTraversal(graph.traversal(),	QueryFactory.create(Prefixes.prepend(query)));
+	}
+
+	public static GraphTraversal<Vertex, ?> convertToGremlinTraversal(final GraphTraversalSource g,
+			final String query) {
+		return convertToGremlinTraversal(g, QueryFactory.create(Prefixes.prepend(query), Syntax.syntaxSPARQL));
+	}
+
+	// VISITING SPARQL ALGEBRA OP BASIC TRIPLE PATTERNS - MAYBE
+	@Override
+	public void visit(final OpBGP opBGP) {
+		{
+			
+			// System.out.println("Inside opBGP ---------------------------------------------->");
+			final List<Triple> triples = opBGP.getPattern().getList();
+			final Traversal[] matchTraversals = new Traversal[triples.size()];
+			int i = 0;
+			for (final Triple triple : triples) {
+
+				matchTraversals[i++] = TraversalBuilder.transform(triple);
+				traversalList.add(matchTraversals[i - 1]);
+			}
+
+		}
+
+	}
+
+	// VISITING SPARQL ALGEBRA OP FILTER - MAYBE
+	@Override
+	public void visit(final OpFilter opFilter) {
+
+		// System.out.println("Inside opFilter ---------------------------------------------->");
+		Traversal traversal = null;
+
+		for (Expr expr : opFilter.getExprs().getList()) {
+			if (expr != null) {
+
+				traversal = __.where(WhereTraversalBuilder.transform(expr));
+				traversalList.add(traversal);
+			}
+		}
+
+	}
+	// TODO: add more functions for operators other than FILTER, such as
+	// OPTIONAL
+	// This can be done by understanding how Jena handles these other
+	// operators/filters inherently and then map them to Gremlin
+
+	public void visit(final OpLeftJoin opLeftJoin) {
+
+//		System.out.println("Inside opOptional ---------------------------------------------->");
+//		System.out.println(opLeftJoin.getRight().toString());
+
+	}
+
+	@Override
+	public void visit(final OpUnion opUnion) {
+
+		// System.out.println("Inside opUnion ---------------------------------------------->");
+		Traversal unionTemp[] = new Traversal[2];
+		Traversal unionTemp1[] = new Traversal[traversalList.size() / 2];
+		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);
+		// System.out.println("Getting out from Union -------------------> :
+		// "+traversal);
+		// traversalList.add(__.union(unionTemp));
+		// traversalList.clear();
+	}
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523c7f00/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/TraversalBuilder.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/TraversalBuilder.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/TraversalBuilder.java
new file mode 100644
index 0000000..72a32a5
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/TraversalBuilder.java
@@ -0,0 +1,82 @@
+/*
+ * 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 org.apache.jena.graph.Node;
+import org.apache.jena.graph.Triple;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.PropertyType;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+
+class TraversalBuilder {
+
+    public static GraphTraversal<?, ?> transform(final Triple triple) {
+        final GraphTraversal<Vertex, ?> matchTraversal = __.as(triple.getSubject().getName());
+        
+        final Node predicate = triple.getPredicate();
+        final String uri = predicate.getURI();
+        final String uriValue = Prefixes.getURIValue(uri);
+        final String prefix = Prefixes.getPrefix(uri);
+
+        switch (prefix) {
+            case "edge":
+                return matchTraversal.out(uriValue).as(triple.getObject().getName());
+            case "property":
+                return matchProperty(matchTraversal, uriValue, PropertyType.PROPERTY, triple.getObject());
+            case "value":
+                return matchProperty(matchTraversal, uriValue, PropertyType.VALUE, triple.getObject());
+            default:
+                throw new IllegalStateException(String.format("Unexpected predicate: %s", predicate));
+        }
+    }
+
+    private static GraphTraversal<?, ?> matchProperty(final GraphTraversal<?, ?> traversal, final String propertyName,
+                                                      final PropertyType type, final Node object) {
+        switch (propertyName) {
+            case "id":
+         
+                return object.isConcrete()
+                        ? traversal.hasId(object.getLiteralValue())
+                        : traversal.id().as(object.getName());
+            case "label":
+                return object.isConcrete()
+                        ? traversal.hasLabel(object.getLiteralValue().toString())
+                        : traversal.label().as(object.getName());
+            case "key":
+                return object.isConcrete()
+                        ? traversal.hasKey(object.getLiteralValue().toString())
+                        : traversal.key().as(object.getName());
+            case "value":
+                return object.isConcrete()
+                        ? traversal.hasValue(object.getLiteralValue().toString())
+                        : traversal.value().as(object.getName());
+            default:
+                if (type.equals(PropertyType.PROPERTY)) {
+                    return traversal.properties(propertyName).as(object.getName());
+                } else {
+                    return object.isConcrete()
+                            ? traversal.values(propertyName).is(object.getLiteralValue())
+                            : traversal.values(propertyName).as(object.getName());
+                }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523c7f00/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/WhereTraversalBuilder.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/WhereTraversalBuilder.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/WhereTraversalBuilder.java
new file mode 100644
index 0000000..f4d49b6
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/WhereTraversalBuilder.java
@@ -0,0 +1,134 @@
+/*
+ * 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.List;
+
+import org.apache.jena.graph.Triple;
+import org.apache.jena.sparql.algebra.op.OpBGP;
+import org.apache.jena.sparql.expr.E_Equals;
+import org.apache.jena.sparql.expr.E_Exists;
+import org.apache.jena.sparql.expr.E_GreaterThan;
+import org.apache.jena.sparql.expr.E_GreaterThanOrEqual;
+import org.apache.jena.sparql.expr.E_LessThan;
+import org.apache.jena.sparql.expr.E_LessThanOrEqual;
+import org.apache.jena.sparql.expr.E_LogicalAnd;
+import org.apache.jena.sparql.expr.E_LogicalOr;
+import org.apache.jena.sparql.expr.E_NotEquals;
+import org.apache.jena.sparql.expr.E_NotExists;
+import org.apache.jena.sparql.expr.E_StrLength;
+import org.apache.jena.sparql.expr.Expr;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+
+class WhereTraversalBuilder {
+
+    public static GraphTraversal<?, ?> transform(final E_Equals expression) {
+    //	System.out.println("The aggr one : "+expression.getArg1().getClass().getName() + "The aggr one :"+expression.getArg2().getClass().getName());
+        final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
+        return __.as(expression.getArg1().getVarName()).is(P.eq(value));
+    }
+
+    public static GraphTraversal<?, ?> transform(final E_NotEquals expression) {
+        final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
+        return __.as(expression.getArg1().getVarName()).is(P.neq(value));
+    }
+
+    public static GraphTraversal<?, ?> transform(final E_LessThan expression) {
+    //	System.out.println("The aggr one : "+expression.getArg1().getClass().getName() + "The aggr one :"+expression.getArg2().getClass().getName());
+    	final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
+        return __.as(expression.getArg1().getVarName()).is(P.lt(value));
+    }
+
+    public static GraphTraversal<?, ?> transform(final E_LessThanOrEqual expression) {
+    //	System.out.println("The aggr one : "+expression.getArg1().getClass().getName() + "The aggr one :"+expression.getArg2().getClass().getName());
+        final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
+        return __.as(expression.getArg1().getVarName()).is(P.lte(value));
+    }
+
+    public static GraphTraversal<?, ?> transform(final E_GreaterThan expression) {
+        final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
+        return __.as(expression.getArg1().getVarName()).is(P.gt(value));
+    }
+
+    public static GraphTraversal<?, ?> transform(final E_GreaterThanOrEqual expression) {
+        final Object value = expression.getArg2().getConstant().getNode().getLiteralValue();
+        return __.as(expression.getArg1().getVarName()).is(P.gte(value));
+    }
+
+    public static GraphTraversal<?, ?> transform(final E_LogicalAnd expression) {
+        return __.and(
+                transform(expression.getArg1()),
+                transform(expression.getArg2()));
+    }
+
+    public static GraphTraversal<?, ?> transform(final E_LogicalOr expression) {
+        return __.or(
+                transform(expression.getArg1()),
+                transform(expression.getArg2()));
+    }
+
+    public static GraphTraversal<?, ?> transform(final E_Exists expression) {
+        final OpBGP opBGP = (OpBGP) expression.getGraphPattern();
+        final List<Triple> triples = opBGP.getPattern().getList();
+        if (triples.size() != 1) throw new IllegalStateException("Unhandled EXISTS pattern");
+        final GraphTraversal<?, ?> traversal = TraversalBuilder.transform(triples.get(0));
+        final Step endStep = traversal.asAdmin().getEndStep();
+        final String label = (String) endStep.getLabels().iterator().next();
+        endStep.removeLabel(label);
+        return traversal;
+    }
+    
+
+    public static GraphTraversal<?, ?> transform(final E_NotExists expression) {
+        final OpBGP opBGP = (OpBGP) expression.getGraphPattern();
+        final List<Triple> triples = opBGP.getPattern().getList();
+        if (triples.size() != 1) throw new IllegalStateException("Unhandled NOT EXISTS pattern");
+        final GraphTraversal<?, ?> traversal = TraversalBuilder.transform(triples.get(0));
+        final Step endStep = traversal.asAdmin().getEndStep();
+        final String label = (String) endStep.getLabels().iterator().next();
+        endStep.removeLabel(label);
+        return __.not(traversal);
+    }
+    
+    public static int getStrLength(final E_StrLength expression){
+    	
+    	return expression.getArg().toString().length();
+    	
+    }
+    
+    
+    //what does <?, ?> signify? possibly <S,E>
+    public static GraphTraversal<?, ?> transform(final Expr expression) {
+        if (expression instanceof E_Equals) return transform((E_Equals) expression);
+        if (expression instanceof E_NotEquals) return transform((E_NotEquals) expression);
+        if (expression instanceof E_LessThan) return transform((E_LessThan) expression);
+        if (expression instanceof E_LessThanOrEqual) return transform((E_LessThanOrEqual) expression);
+        if (expression instanceof E_GreaterThan) return transform((E_GreaterThan) expression);
+        if (expression instanceof E_GreaterThanOrEqual) return transform((E_GreaterThanOrEqual) expression);
+        if (expression instanceof E_LogicalAnd) return transform((E_LogicalAnd) expression);
+        if (expression instanceof E_LogicalOr) return transform((E_LogicalOr) expression);
+        if (expression instanceof E_Exists) return transform((E_Exists) expression);
+        if (expression instanceof E_NotExists) return transform((E_NotExists) expression);
+        throw new IllegalStateException(String.format("Unhandled expression: %s", expression));
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523c7f00/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/PrefixesTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/PrefixesTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/PrefixesTest.java
new file mode 100644
index 0000000..155680b
--- /dev/null
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/PrefixesTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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 org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class PrefixesTest {
+
+    final static String TEST_QUERY = String.join(System.lineSeparator(), "SELECT *", "WHERE {}");
+    final static String PREFIXED_QUERY = String.join(System.lineSeparator(),
+            "PREFIX e: <" + Prefixes.BASE_URI + "edge#>",
+            "PREFIX p: <" + Prefixes.BASE_URI + "property#>",
+            "PREFIX v: <" + Prefixes.BASE_URI + "value#>",
+            TEST_QUERY);
+
+    @Test
+    public void testGetURI() throws Exception {
+        final String prefix = "test";
+        final String uri = Prefixes.BASE_URI + prefix + "#";
+        assertEquals(uri, Prefixes.getURI(prefix));
+    }
+
+    @Test
+    public void testGetURIValue() throws Exception {
+        final String prefix = "test";
+        final String value = "value";
+        final String uri = Prefixes.getURI(prefix) + value;
+        assertEquals(value, Prefixes.getURIValue(uri));
+    }
+
+    @Test
+    public void testGetPrefix() throws Exception {
+        final String prefix = "test";
+        final String uri = Prefixes.getURI(prefix);
+        assertEquals(prefix, Prefixes.getPrefix(uri));
+    }
+
+    @Test
+    public void testPrependString() throws Exception {
+        assertEquals(PREFIXED_QUERY, Prefixes.prepend(TEST_QUERY));
+    }
+
+    @Test
+    public void testPrependStringBuilder() throws Exception {
+        final StringBuilder builder = new StringBuilder(TEST_QUERY);
+        assertEquals(PREFIXED_QUERY, Prefixes.prepend(builder).toString());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523c7f00/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/ResourceHelper.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/ResourceHelper.java
new file mode 100644
index 0000000..4f58e61
--- /dev/null
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/ResourceHelper.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.commons.io.IOUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+public class ResourceHelper {
+
+    public static String loadQuery(final String prefix, final int number) throws IOException {
+        final String path = "/queries/" + prefix + number + ".sparql";
+        final InputStream stream = ResourceHelper.class.getResourceAsStream(path);
+        return IOUtils.toString(stream, "UTF-8");
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523c7f00/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompilerTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompilerTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompilerTest.java
new file mode 100644
index 0000000..3fb49e8
--- /dev/null
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompilerTest.java
@@ -0,0 +1,223 @@
+/*
+ * 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 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.structure.Graph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.apache.tinkerpop.gremlin.process.computer.Computer;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import static org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinCompiler.convertToGremlinTraversal;
+import static org.junit.Assert.assertEquals;
+
+
+import java.io.IOException;
+
+import static org.apache.tinkerpop.gremlin.sparql.ResourceHelper.loadQuery;
+
+
+public class SparqlToGremlinCompilerTest {
+
+    private Graph modern, crew;
+    private GraphTraversalSource mg, cg;
+    private GraphTraversalSource mc, cc;
+/*
+    @Before
+    public void setUp() throws Exception {
+        modern = TinkerFactory.createModern();
+        mg = modern.traversal();
+        mc = modern.traversal(computer());
+        crew = TinkerFactory.createTheCrew();
+        cg = modern.traversal();
+        cc = modern.traversal(computer());
+    }
+
+    @Ignore
+    @Test
+    public void play() throws IOException {
+        final String query = loadQuery("modern", 11);
+        final Traversal traversal = convertToGremlinTraversal(modern, query);
+        System.out.println(traversal);
+        System.out.println(traversal.toList());
+        System.out.println(traversal);
+    }
+
+    /* Modern */
+
+ /*   @Test
+    public void testModern1() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("a").hasLabel("person"),
+                as("a").out("knows").as("b"),
+                as("a").out("created").as("c"),
+                as("b").out("created").as("c"),
+                as("a").values("age").as("d")).where(as("d").is(lt(30))).
+                select("a", "b", "c");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 1)));
+    }
+
+    @Test
+    public void testModern2() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("a").hasLabel("person"),
+                as("a").out("knows").as("b"),
+                as("a").out("created").as("c"),
+                as("b").out("created").as("c"),
+                as("a").values("age").as("d")).where(as("d").is(lt(30)));
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 2)));
+    }
+
+    @Test
+    public void testModern3() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("person").values("name").as("name"),
+                as("person").values("age").as("age")).select("name", "age");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 3)));
+    }
+
+    @Test
+    public void testModern4() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("person").values("name").as("name"),
+                as("person").values("age").as("age"),
+                as("person").out("created").as("project"),
+                as("project").values("name").is("lop")).select("name", "age");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 4)));
+    }
+
+    @Test
+    public void testModern5() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("person").values("name").as("name"),
+                as("person").values("age").is(29)).select("name");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 5)));
+    }
+
+    @Test
+    public void testModern6() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("person").values("name").as("name"),
+                as("person").values("age").as("age")).where(and(as("age").is(gt(30)), as("age").is(lt(40)))).
+                select("name", "age");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 6)));
+    }
+
+    @Test
+    public void testModern7() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("person").values("name").as("name"),
+                as("person").values("age").as("age")).where(or(as("age").is(lt(30)), as("age").is(gt(40)))).
+                select("name", "age");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 7)));
+    }
+
+    @Test
+    public void testModern8() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("person").values("name").as("name"),
+                as("person").values("age").as("age")).where(
+                or(and(as("age").is(gt(30)), as("age").is(lt(40))), as("name").is("marko"))).
+                select("name", "age");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 8)));
+    }
+
+    @Test
+    public void testModern9() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("a").values("name").as("name")).where(as("a").values("age")).
+                select("name");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 9)));
+    }
+
+    @Test
+    public void testModern10() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("a").values("name").as("name")).where(__.not(as("a").values("age"))).
+                select("name");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 10)));
+    }
+
+    @Test
+    public void testModern11() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("a").out("created").as("b"),
+                as("a").values("name").as("name")).dedup("name").select("name");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 11)));
+    }
+
+    @Test
+    public void testModern12() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("a").out("created").as("b"),
+                as("b").values("name").as("name")).dedup();
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 12)));
+    }
+
+    @Test
+    public void testModern13() throws Exception {
+        final GraphTraversal expected = mg.V().match(
+                as("a").out("created").as("b"),
+                as("a").values("name").as("c")).dedup("a", "b", "c").select("a", "b", "c");
+        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 13)));
+    }
+
+    /* The Crew */
+
+ /*   @Test
+    public void testCrew1() throws Exception {
+        final GraphTraversal expected = cg.V().match(
+                as("a").values("name").is("daniel"),
+                as("a").properties("location").as("b"),
+                as("b").value().as("c"),
+                as("b").values("startTime").as("d")).
+                select("c", "d");
+        assertEquals(expected, convertToGremlinTraversal(crew, loadQuery("crew", 1)));
+    }
+
+    /* Computer Mode */
+
+  /*  @Test
+    public void testModernInComputerMode() throws Exception {
+        final GraphTraversal expected = mc.V().match(
+                as("a").hasLabel("person"),
+                as("a").out("knows").as("b"),
+                as("a").out("created").as("c"),
+                as("b").out("created").as("c"),
+                as("a").values("age").as("d")).where(as("d").is(lt(30))).
+                select("a", "b", "c");
+        assertEquals(expected, convertToGremlinTraversal(mc, loadQuery("modern", 1)));
+    }
+
+    @Test
+    public void testCrewInComputerMode() throws Exception {
+        final GraphTraversal expected = cc.V().match(
+                as("a").values("name").is("daniel"),
+                as("a").properties("location").as("b"),
+                as("b").value().as("c"),
+                as("b").values("startTime").as("d")).
+                select("c", "d");
+        assertEquals(expected, convertToGremlinTraversal(crew, loadQuery("crew", 1)));
+    } */
+}
\ No newline at end of file


[37/50] tinkerpop git commit: Update transpilers.asciidoc

Posted by sp...@apache.org.
Update transpilers.asciidoc

Changes:
- fixed non-working queries (queries which returned no results)
- updated documentation with more examples in the limitations section
- updated execution tags for queries which are for reference only
- commented out the pattern filter examples for now

To Do:
- fix OPTIONAL queries 
- fix Pattern filter queries
- inspect and patch special cases in code

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

Branch: refs/heads/TINKERPOP-1878
Commit: 26ec6a88e6833eabde0ff1e4e13b00dd27ade984
Parents: 7c59354
Author: Harsh Thakkar <ha...@gmail.com>
Authored: Fri Jun 15 11:24:57 2018 +0200
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/src/reference/transpilers.asciidoc | 94 +++++++++++++++++++++-------
 1 file changed, 72 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26ec6a88/docs/src/reference/transpilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/transpilers.asciidoc b/docs/src/reference/transpilers.asciidoc
index 3211857..1bb7728 100644
--- a/docs/src/reference/transpilers.asciidoc
+++ b/docs/src/reference/transpilers.asciidoc
@@ -131,7 +131,7 @@ The current implementation of SPARQL-Gremlin transpiler (i.e. SPARQL-Gremlin) do
 * SPARQL queries with variables in the predicate position are not currently covered, with an exception of the following
 case:
 
-[source,groovy]
+[source,text]
 ----
 g.sparql("""SELECT * WHERE { ?x ?y ?z . }""")
 ----
@@ -141,24 +141,72 @@ SPARQL query has the same number of patterns on both the side of the union opera
 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]
+[source,text]
 ----
-g.sparql("""SELECT * 
-	WHERE {
-	{?person e:created ?software . 
-	?person v:name "daniel" .}
+g.sparql("""SELECT * WHERE {
+	{?person e:created ?software .
+	?person v:name "josh" .}
 	UNION
 	{?software v:lang "java" .} }""")
 ----
 
-* order by
-....
-Adding more here...
-....
+* 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,text]
+----
+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)""")
+----
 
-* group by
+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
 ....
-Adding more here...
+currently fixing this...
 ....
 
 [[examples]]
@@ -264,6 +312,7 @@ WHERE {
     FILTER (?age > 30 && ?lang = "java") }""")
 ----
 
+////
 [[pattern-filters]]
 ==== Pattern Filter(s)
 
@@ -288,6 +337,7 @@ WHERE {
   ?person v:name ?name .
     FILTER NOT EXISTS { ?person e:created ?project } }""")
 ----
+////
 
 [[union]]
 ==== Union
@@ -325,11 +375,12 @@ Select all vertices with the label `person` and order them by their age.
 
 [gremlin-groovy,existing]
 ----
-g.sparql("""SELECT * 
+g.sparql("""SELECT ?age ?name
 WHERE {
   ?person v:label "person" .
   ?person v:age ?age .
-} ORDER BY (?age)""")
+  ?person v:name ?name .
+} ORDER BY (?age))
 ----
 
 [[group-by]]
@@ -337,9 +388,9 @@ WHERE {
 
 Select all vertices with the label `person` and group them by their age.
 
-[source,groovy]
+[gremlin-groovy,existing]
 ----
-g.sparql("""SELECT * 
+g.sparql("""SELECT ?age 
 WHERE {
   ?person v:label "person" .
   ?person v:age ?age .
@@ -354,7 +405,7 @@ the top two.
 
 [source,groovy]
 ----
-g.sparql("""SELECT COUNT(?project) 
+g.sparql("""SELECT (COUNT(?project) as ?p)
 WHERE {
   ?person v:label "person" .
   ?person v:age ?age . FILTER (?age < 30)
@@ -388,12 +439,11 @@ can be perceived as path queries or neighborhood queries. For instance, getting
 
 [gremlin-groovy,existing]
 ----
-g.sparql("""SELECT ?age ?software ?name ?location ?startTime 
+g.sparql("""SELECT ?age ?software ?lang ?name
 WHERE {
-  ?person v:name "daniel" .
+  ?person v:name "josh" .
   ?person v:age ?age .
   ?person e:created ?software .
-  ?person p:location ?location .
-  ?location v:value ?name .
-  ?location v:startTime ?startTime }""")
+  ?software v:lang ?lang .
+  ?software v:name ?name . }""")
 ----


[08/50] tinkerpop git commit: Added a system error code for failed plugin installs to Gremlin Server CTR

Posted by sp...@apache.org.
Added a system error code for failed plugin installs to Gremlin Server CTR


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

Branch: refs/heads/TINKERPOP-1878
Commit: 2d315e828149a132ecabf406af91acc3caec064c
Parents: b98ff5e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 7 06:28:56 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 7 06:30:08 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                                | 1 +
 .../tinkerpop/gremlin/server/util/GremlinServerInstall.java       | 3 +++
 2 files changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d315e82/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 8137b45..495abd7 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-2-10]]
 === TinkerPop 3.2.10 (Release Date: NOT OFFICIALLY RELEASED YET)
 
+* Added an system error code for failed plugin installs for Gremlin Server `-i` option.
 * Match numbers in `choose()` options using `NumberHelper` (match values, ignore data type).
 * Added support for GraphSON serialization of `Date` in Javascript.
 * Fixed bug in Java driver where an disorderly shutdown of the server would cause the client to hang.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d315e82/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java
index 03317d3..58532a0 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java
@@ -23,6 +23,8 @@ import org.apache.tinkerpop.gremlin.groovy.util.DependencyGrabber;
 import groovy.lang.GroovyClassLoader;
 
 /**
+ * Command line installer for plugins to Gremlin Server.
+ *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class GremlinServerInstall {
@@ -39,6 +41,7 @@ public class GremlinServerInstall {
             } catch (Exception iae) {
                 System.out.println(String.format("Could not install the dependency: %s", iae.getMessage()));
                 iae.printStackTrace();
+                System.exit(1);
             }
 
         }


[13/50] tinkerpop git commit: Updated changelog CTR

Posted by sp...@apache.org.
Updated changelog CTR


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

Branch: refs/heads/TINKERPOP-1878
Commit: 37476a2b46467c2d704cbef977225d8da3cddd64
Parents: 387cf69
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 7 10:52:29 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 7 10:52:29 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37476a2b/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 495abd7..f6413e2 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-2-10]]
 === TinkerPop 3.2.10 (Release Date: NOT OFFICIALLY RELEASED YET)
 
+* Fixed problem with Gremlin Server sometimes returning an additional message after a failure.
 * Added an system error code for failed plugin installs for Gremlin Server `-i` option.
 * Match numbers in `choose()` options using `NumberHelper` (match values, ignore data type).
 * Added support for GraphSON serialization of `Date` in Javascript.


[46/50] tinkerpop git commit: TINKERPOP-1878 Fixed up formatting of sparql-gremlin image

Posted by sp...@apache.org.
TINKERPOP-1878 Fixed up formatting of sparql-gremlin image


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

Branch: refs/heads/TINKERPOP-1878
Commit: c4e21cffbbabd0d276e276b76a16aea07ce108e5
Parents: 8f12476
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sun May 13 11:02:26 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/src/reference/transpilers.asciidoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c4e21cff/docs/src/reference/transpilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/transpilers.asciidoc b/docs/src/reference/transpilers.asciidoc
index 390d4f4..3211857 100644
--- a/docs/src/reference/transpilers.asciidoc
+++ b/docs/src/reference/transpilers.asciidoc
@@ -24,7 +24,7 @@ Gremlin Transpiler enables a particular query language to work on any TinkerPop-
 
 == SPARQL-Gremlin
 
-image::gremlin-standing.png[]
+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


[32/50] tinkerpop git commit: TINKERPOP-1878 Testing for DISTINCT

Posted by sp...@apache.org.
TINKERPOP-1878 Testing for DISTINCT

Refactoring around the distinct and ordering - much less code there now.


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

Branch: refs/heads/TINKERPOP-1878
Commit: c0efbefb2207aa17c378c7709779cebc9d5b911b
Parents: 808a047
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jan 26 16:56:14 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../sparql/SparqlToGremlinTranspiler.java       | 44 ++++++++------------
 .../dsl/sparql/SparqlTraversalSourceTest.java   | 23 ++++++++++
 2 files changed, 41 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c0efbefb/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
index 1b28a1d..67ac1e1 100644
--- 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
@@ -107,39 +107,28 @@ public class SparqlToGremlinTranspiler {
 
         final List<String> vars = query.getResultVars();
         if (!query.isQueryResultStar() && !query.hasGroupBy()) {
-            // the result sizes have special handling to get the right signatures of select() called. perhaps this
-            // could be refactored to work more nicely
-            switch (vars.size()) {
+            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:
-                    if (query.isDistinct())
-                        traversal = traversal.dedup(vars.get(0));
-
-                    orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
-                    traversal = traversal.select(vars.get(0));
-
+                    traversal = traversal.select(all[0]);
                     break;
                 case 2:
-                    if (query.isDistinct())
-                        traversal = traversal.dedup(vars.get(0), vars.get(1));
-
-                    orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
-                    traversal = traversal.select(vars.get(0), vars.get(1));
-
+                    traversal = traversal.select(all[0], all[1]);
                     break;
                 default:
-                    final String[] all = new String[vars.size()];
-                    vars.toArray(all);
-                    if (query.isDistinct())
-                        traversal = traversal.dedup(all);
-
-                    orderingIndex.forEach((k, v) -> traversal = traversal.order().by(__.select(k), v));
-
-                    // just some shenanigans to get the right signature of select() called
                     final String[] others = Arrays.copyOfRange(all, 2, vars.size());
-                    traversal = traversal.select(vars.get(0), vars.get(1), others);
-
+                    traversal = traversal.select(all[0], all[1], others);
                     break;
             }
         }
@@ -207,7 +196,10 @@ public class SparqlToGremlinTranspiler {
 
             for (SortCondition sortCondition : sortingConditions) {
                 final Expr expr = sortCondition.getExpression();
-                orderingIndex.put(expr.getVarName(), sortCondition.getDirection() == 1 ? Order.incr : Order.decr);
+
+                // 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);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c0efbefb/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
index 4092e58..56d62c9 100644
--- a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
@@ -111,4 +111,27 @@ public class SparqlTraversalSourceTest {
         assertEquals(x.get("b"), _g.V(4).next());
         assertEquals(x.get("c"), _g.V(3).next());
     }
+
+    @Test
+    public void shouldDistinct() {
+        final List<?> x = g.sparql(
+                "SELECT DISTINCT ?name\n" +
+                "WHERE {\n" +
+                "    ?a e:created ?b .\n" +
+                "    ?a v:name ?name .\n" +
+                "}").toList();
+        assertThat(x, containsInAnyOrder("marko", "josh", "peter"));
+    }
+
+    @Test
+    public void shouldDistinctAndOrder() {
+        final List<?> x = g.sparql(
+                "SELECT DISTINCT ?name\n" +
+                        "WHERE {\n" +
+                        "    ?a e:created ?b .\n" +
+                        "    ?a v:name ?name .\n" +
+                        "}" +
+                        "ORDER BY ?name").toList();
+        assertThat(x, contains("josh", "marko", "peter"));
+    }
 }


[05/50] tinkerpop git commit: Added a note about versioning gremlin CTR

Posted by sp...@apache.org.
Added a note about versioning gremlin CTR


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

Branch: refs/heads/TINKERPOP-1878
Commit: 18db9b8159810d0d624944e169ccafdc868a3237
Parents: 891e7da
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Aug 6 07:15:52 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Aug 6 07:15:52 2018 -0400

----------------------------------------------------------------------
 docs/src/dev/future/index.asciidoc | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/18db9b81/docs/src/dev/future/index.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/dev/future/index.asciidoc b/docs/src/dev/future/index.asciidoc
index 6e41cf9..acf587e 100644
--- a/docs/src/dev/future/index.asciidoc
+++ b/docs/src/dev/future/index.asciidoc
@@ -53,6 +53,8 @@ TinkerPop 3.x. These items include:
 * The concept of `Traversal` as the sole means of interacting with the graph.
 ** The role of Blueprints should be significantly reduced.
 ** The role of Gremlin should be significantly increased.
+* Provide better methods of versioning Gremlin itself - being bound to JVM releases and forcing local and remote
+versions of Gremlin to be the same isn't ideal.
 
 == Hiding Blueprints
 


[03/50] tinkerpop git commit: Merge branch 'tp32' into tp33

Posted by sp...@apache.org.
Merge branch 'tp32' into tp33


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

Branch: refs/heads/TINKERPOP-1878
Commit: 3e308f5226e6254122f782cb55571e0103f9a9ff
Parents: b779a2a b98ff5e
Author: Robert Dale <ro...@gmail.com>
Authored: Sat Aug 4 16:44:41 2018 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Sat Aug 4 16:44:41 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc     | 1 +
 gremlin-shaded/pom.xml | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e308f52/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e308f52/gremlin-shaded/pom.xml
----------------------------------------------------------------------


[39/50] tinkerpop git commit: Update SparqlToGremlinCompiler.java

Posted by sp...@apache.org.
Update SparqlToGremlinCompiler.java

adding an updated file with SPARQL OPTIONAL clause:

- added optional
- added left-join with optional

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

Branch: refs/heads/TINKERPOP-1878
Commit: c95ce50c62e30887e8bbb40750f0f2e04d4c52f2
Parents: 0b1d6fa
Author: Harsh Thakkar <ha...@gmail.com>
Authored: Wed Aug 1 11:14:54 2018 +0200
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 .../gremlin/sparql/SparqlToGremlinCompiler.java | 64 ++++++++++++++++++--
 1 file changed, 60 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c95ce50c/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
index b43de41..e3b4ecb 100644
--- 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
@@ -35,6 +35,7 @@ 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.OpLeftJoin;  
 import org.apache.jena.sparql.algebra.op.OpUnion;
 import org.apache.jena.sparql.core.Var;
 import org.apache.jena.sparql.core.VarExprList;
@@ -58,6 +59,9 @@ public class SparqlToGremlinCompiler {
     private GraphTraversal<Vertex, ?> traversal;
 
     private List<Traversal> traversalList = new ArrayList<>();
+            List<Traversal> optionalTraversals = new ArrayList<Traversal>();
+            List<String> optionalVariable = new ArrayList<String>();
+            boolean optionalFlag = false;
 
     private SparqlToGremlinCompiler(final GraphTraversal<Vertex, ?> traversal) {
         this.traversal = traversal;
@@ -93,18 +97,38 @@ public class SparqlToGremlinCompiler {
 
         int traversalIndex = 0;
         final int numberOfTraversal = traversalList.size();
-        final Traversal arrayOfAllTraversals[] = new Traversal[numberOfTraversal];
+        final int numberOfOptionalTraversal = optionalTraversals.size();
+        Traversal arrayOfAllTraversals[] = null;
+
+        if (numberOfOptionalTraversal > 0) {
+            arrayOfAllTraversals = new Traversal[numberOfTraversal - numberOfOptionalTraversal +1];
+        } else {
+            arrayOfAllTraversals = new Traversal[numberOfTraversal - numberOfOptionalTraversal];
+        }
+        
+        Traversal arrayOfOptionalTraversals[] = new Traversal[numberOfOptionalTraversal];
 
         for (Traversal tempTrav : traversalList) {
             arrayOfAllTraversals[traversalIndex++] = tempTrav;
         }
 
-        // creates a map of ordering keys and their ordering direction
+        traversalIndex = 0;
+        for (Traversal tempTrav : optionalTraversals) 
+            arrayOfOptionalTraversals[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);
 
+        if (optionalTraversals.size() > 0) {
+            traversal = traversal.coalesce(__.match(arrayOfOptionalTraversals), (Traversal) __.constant("N/A"));
+            for (int i = 0; i < optionalVariable.size(); i++) {
+                traversal = traversal.as(optionalVariable.get(i).substring(1));
+            }
+        }
+
         final List<String> vars = query.getResultVars();
         if (!query.isQueryResultStar() && !query.hasGroupBy()) {
             final String[] all = new String[vars.size()];
@@ -157,7 +181,6 @@ public class SparqlToGremlinCompiler {
                             traversal = traversal.groupCount();
                         }
                     }
-
                     if (expr.getAggregator().getName().contains("MAX")) {
                         traversal = traversal.max();
                     }
@@ -220,7 +243,14 @@ public class SparqlToGremlinCompiler {
          */
         @Override
         public void visit(final OpBGP opBGP) {
-            opBGP.getPattern().getList().forEach(triple -> traversalList.add(TraversalBuilder.transform(triple)));
+        if(optionalFlag)
+            {
+                opBGP.getPattern().getList().forEach(triple -> optionalTraversals.add(TraversalBuilder.transform(triple)));
+                opBGP.getPattern().getList().forEach(triple -> optionalVariable.add(triple.getObject().toString()));
+                
+            }
+            else        
+                opBGP.getPattern().getList().forEach(triple -> traversalList.add(TraversalBuilder.transform(triple)));
         }
 
         /**
@@ -237,6 +267,32 @@ public class SparqlToGremlinCompiler {
             }
         }
 
+        
+        /**
+         * Visiting LeftJoin(Optional) in SPARQL algebra.
+         */
+        @Override
+        public void visit(final OpLeftJoin opLeftJoin) {
+            optionalFlag = true;
+            optionalVisit(opLeftJoin.getRight());
+            if (opLeftJoin.getExprs() != null) {
+                for (Expr expr : opLeftJoin.getExprs().getList()) {
+                    if (expr != null) {
+                        if (optionalFlag)
+                            optionalTraversals.add(__.where(WhereTraversalBuilder.transform(expr)));
+                    }
+                }
+            }
+        }
+        
+        /**
+         * Walking OP for Optional in SPARQL algebra.
+         */
+        private void optionalVisit(final Op op) {
+
+            OpWalker.walk(op, this);
+        }
+
         /**
          * Visiting unions in SPARQL algebra.
          */


[11/50] tinkerpop git commit: This closes #906

Posted by sp...@apache.org.
This closes #906


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

Branch: refs/heads/TINKERPOP-1878
Commit: 1e8baec975fa23be4c4e59566ab69dd803352215
Parents: 9b41f5a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 7 10:25:28 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 7 10:25:28 2018 -0400

----------------------------------------------------------------------

----------------------------------------------------------------------



[14/50] tinkerpop git commit: Merge branch 'tp32' into tp33

Posted by sp...@apache.org.
Merge branch 'tp32' into tp33

Conflicts:
	gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java


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

Branch: refs/heads/TINKERPOP-1878
Commit: fa7a7f61308acc675e4a4c4a6dc863cf9818c3f9
Parents: 2cf551f 37476a2
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 7 12:08:39 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 7 12:08:39 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   1 +
 .../driver/message/ResponseStatusCode.java      |   7 +
 .../driver/message/ResponseStatusCodeTest.java  |  36 +++++
 .../gremlin/server/ResponseHandlerContext.java  |  85 +++++++++++
 .../server/op/AbstractEvalOpProcessor.java      |  38 ++++-
 .../gremlin/server/op/AbstractOpProcessor.java  |  34 ++++-
 .../AbstractGremlinServerIntegrationTest.java   |  20 ++-
 .../server/GremlinServerIntegrateTest.java      |  51 +++++++
 .../server/ResponseHandlerContextTest.java      | 143 +++++++++++++++++++
 .../server/op/AbstractEvalOpProcessorTest.java  |  62 ++++++++
 .../server/op/AbstractOpProcessorTest.java      |  73 ++++++++++
 11 files changed, 535 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fa7a7f61/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fa7a7f61/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java
----------------------------------------------------------------------
diff --cc gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java
index 74e9478,ca1ee53..dbf7a44
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java
@@@ -242,14 -287,9 +266,14 @@@ public abstract class AbstractEvalOpPro
                      final Iterator itty = IteratorUtils.asIterator(o);
  
                      logger.debug("Preparing to iterate results from - {} - in thread [{}]", msg, Thread.currentThread().getName());
 +                    if (settings.authentication.enableAuditLog) {
 +                        String address = context.getChannelHandlerContext().channel().remoteAddress().toString();
 +                        if (address.startsWith("/") && address.length() > 1) address = address.substring(1);
 +                        auditLogger.info("User with address {} requested: {}", address, script);
 +                    }
  
                      try {
-                         handleIterator(context, itty);
+                         handleIterator(rhc, itty);
                      } catch (Exception ex) {
                          if (managedTransactionsForRequest) attemptRollback(msg, context.getGraphManager(), settings.strictTransactionManagement);
  
@@@ -271,9 -311,16 +295,9 @@@
                      // occurs when the TimedInterruptCustomizerProvider is in play
                      final String errorMessage = String.format("A timeout occurred within the script during evaluation of [%s] - consider increasing the limit given to TimedInterruptCustomizerProvider", msg);
                      logger.warn(errorMessage);
-                     ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT)
+                     rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT)
                              .statusMessage("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider")
                              .statusAttributeException(t).create());
 -                } else if (t instanceof org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) {
 -                    // occurs when the TimedInterruptCustomizerProvider is in play
 -                    final String errorMessage = String.format("A timeout occurred within the script during evaluation of [%s] - consider increasing the limit given to TimedInterruptCustomizerProvider", msg);
 -                    logger.warn(errorMessage);
 -                    rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT)
 -                            .statusMessage("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider")
 -                            .statusAttributeException(t).create());
                  } else if (t instanceof TimeoutException) {
                      final String errorMessage = String.format("Script evaluation exceeded the configured threshold for request [%s]", msg);
                      logger.warn(errorMessage, t);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fa7a7f61/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
----------------------------------------------------------------------
diff --cc gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
index a1689e9,eb5def9..67ad021
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
@@@ -71,7 -74,9 +72,8 @@@ import org.junit.Test
  import java.lang.reflect.Field;
  import java.nio.channels.ClosedChannelException;
  import java.util.ArrayList;
 -import java.util.Collections;
  import java.util.HashMap;
+ import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;


[06/50] tinkerpop git commit: Fix spelling mistake CTR

Posted by sp...@apache.org.
Fix spelling mistake CTR


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

Branch: refs/heads/TINKERPOP-1878
Commit: 72b264d0f5e4b8fca66ea77cde83982071f411b0
Parents: 18db9b8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Aug 6 07:40:30 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Aug 6 07:40:30 2018 -0400

----------------------------------------------------------------------
 docs/src/upgrade/release-3.4.x.asciidoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/72b264d0/docs/src/upgrade/release-3.4.x.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.4.x.asciidoc b/docs/src/upgrade/release-3.4.x.asciidoc
index 9951024..587e761 100644
--- a/docs/src/upgrade/release-3.4.x.asciidoc
+++ b/docs/src/upgrade/release-3.4.x.asciidoc
@@ -85,7 +85,7 @@ While `io()`-step is still single-threaded for OLTP style loading, it can be uti
 internally uses `CloneVertexProgram` and therefore any graph `InputFormat` or `OutputFormat` can be configured in
 conjunction with this step for parallel loads of large datasets.
 
-It is also worth noting that the `io()`-step may be overriden by graph providers to utilize their native bulk-loading
+It is also worth noting that the `io()`-step may be overridden by graph providers to utilize their native bulk-loading
 features, so consult the documentation of the implementation being used to determine if there are any improved
 efficiencies there.
 


[17/50] tinkerpop git commit: TINKERPOP-1878 sparql-gremlin is now building

Posted by sp...@apache.org.
TINKERPOP-1878 sparql-gremlin is now building

Fixed some basic pom.xml issues and resolved dependency conflicts.


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

Branch: refs/heads/TINKERPOP-1878
Commit: a12f5565bbd6f5722271f269459693a021d90108
Parents: 523c7f0
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jan 24 15:23:57 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:29 2018 -0400

----------------------------------------------------------------------
 pom.xml                | 18 ++++++++++++++++
 sparql-gremlin/pom.xml | 52 ++++++++++++++++++---------------------------
 2 files changed, 39 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a12f5565/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4badaa1..197d8dc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,6 +108,18 @@ limitations under the License.
             <email>twilmes@gmail.com</email>
             <url>https://github.com/twilmes</url>
         </contributor>
+        <contributor>
+            <name>Harsh Thakkar</name>
+            <email>harsh9t@gmail.com</email>
+            <organization>University of Bonn</organization>
+            <organizationUrl>http://harshthakkar.in</organizationUrl>
+        </contributor>
+        <contributor>
+            <name>Dharmen Punjani</name>
+            <email>dharmen.punjani@gmail.com</email>
+            <organization>National and Kapodistrian University of Athens</organization>
+            <organizationUrl>http://wdaqua.eu/students/dharmen-punjani</organizationUrl>
+        </contributor>
     </contributors>
     <prerequisites>
         <maven>3.1.0</maven>
@@ -124,6 +136,7 @@ limitations under the License.
         <module>hadoop-gremlin</module>
         <module>spark-gremlin</module>
         <module>neo4j-gremlin</module>
+        <module>sparql-gremlin</module>
         <module>gremlin-driver</module>
         <module>gremlin-console</module>
         <module>gremlin-server</module>
@@ -680,6 +693,11 @@ limitations under the License.
                 </exclusions>
             </dependency>
             <dependency>
+                <groupId>org.apache.httpcomponents</groupId>
+                <artifactId>httpclient</artifactId>
+                <version>4.5.1</version>
+            </dependency>
+            <dependency>
                 <groupId>commons-httpclient</groupId>
                 <artifactId>commons-httpclient</artifactId>
                 <version>3.1</version>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a12f5565/sparql-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/sparql-gremlin/pom.xml b/sparql-gremlin/pom.xml
index e134d31..d38a85d 100644
--- a/sparql-gremlin/pom.xml
+++ b/sparql-gremlin/pom.xml
@@ -2,55 +2,46 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
     <parent>
         <artifactId>tinkerpop</artifactId>
         <groupId>org.apache.tinkerpop</groupId>
         <version>3.3.2-SNAPSHOT</version>
     </parent>
-    <modelVersion>4.0.0</modelVersion>
-
     <artifactId>sparql-gremlin</artifactId>
-    <organization>
-        <name>WDAQUA-ITN</name>
-        <url>http://wdaqua.eu</url>
-    </organization>
-    <developers>
-        <developer>
-            <name>Harsh Thakkar</name>
-            <email>harsh9t@gmail.com</email>
-            <organization>University of Bonn</organization>
-            <organizationUrl>http://harshthakkar.in</organizationUrl>
-        </developer>
-        <developer>
-            <name>Dharmen Punjani</name>
-            <email>dharmen.punjani@gmail.com</email>
-            <organization>National and Kapodistrian University of Athens</organization>
-            <organizationUrl>http://wdaqua.eu/students/dharmen-punjani</organizationUrl>
-        </developer>
-    </developers>
+    <name>Apache TinkerPop :: SPARQL Gremlin</name>
 
     <properties>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <jena.version>3.0.0</jena.version>
         <query.dir>src/test/resources/sparql/queries</query.dir>
     </properties>
 
     <dependencies>
-    <dependency>
-        <groupId>org.apache.jena</groupId>
-        <artifactId>apache-jena-libs</artifactId>
-        <type>pom</type>
-        <version>${jena.version}</version>
-    </dependency>
+        <dependency>
+            <groupId>org.apache.jena</groupId>
+            <artifactId>apache-jena-libs</artifactId>
+            <type>pom</type>
+            <version>3.0.0</version>
+            <exclusions>
+                <!-- self-conflict -->
+                <exclusion>
+                    <groupId>org.apache.httpcomponents</groupId>
+                    <artifactId>httpclient</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.apache.tinkerpop</groupId>
             <artifactId>gremlin-core</artifactId>
-            <version>3.3.2-SNAPSHOT</version>
+            <version>${project.version}</version>
         </dependency>
         <dependency>
             <groupId>org.apache.tinkerpop</groupId>
             <artifactId>tinkergraph-gremlin</artifactId>
-            <version>3.3.2-SNAPSHOT</version>
+            <version>${project.version}</version>
         </dependency>
         <dependency>
             <groupId>org.apache.tinkerpop</groupId>
@@ -59,5 +50,4 @@
             <scope>test</scope>
         </dependency>
     </dependencies>
-
 </project>
\ No newline at end of file


[12/50] tinkerpop git commit: Merge branch 'pr-899' into tp32

Posted by sp...@apache.org.
Merge branch 'pr-899' into tp32


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

Branch: refs/heads/TINKERPOP-1878
Commit: 387cf69323b1ea0a7194033fe951db8f9e43b799
Parents: 2d315e8 fe9c26f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 7 10:51:23 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 7 10:51:23 2018 -0400

----------------------------------------------------------------------
 .../driver/message/ResponseStatusCode.java      |   7 +
 .../driver/message/ResponseStatusCodeTest.java  |  36 +++++
 .../gremlin/server/ResponseHandlerContext.java  |  85 +++++++++++
 .../server/op/AbstractEvalOpProcessor.java      |  40 ++++--
 .../gremlin/server/op/AbstractOpProcessor.java  |  34 ++++-
 .../AbstractGremlinServerIntegrationTest.java   |  20 ++-
 .../server/GremlinServerIntegrateTest.java      |  51 +++++++
 .../server/ResponseHandlerContextTest.java      | 143 +++++++++++++++++++
 .../server/op/AbstractEvalOpProcessorTest.java  |  62 ++++++++
 .../server/op/AbstractOpProcessorTest.java      |  73 ++++++++++
 10 files changed, 535 insertions(+), 16 deletions(-)
----------------------------------------------------------------------



[23/50] tinkerpop git commit: TINKERPOP-1878 Changed gryo version of SparqlStrategy

Posted by sp...@apache.org.
TINKERPOP-1878 Changed gryo version of SparqlStrategy

Was using some temporary nonsense before...


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

Branch: refs/heads/TINKERPOP-1878
Commit: 8a8d2e12759be30c0b52a58eea14fe7a70cfbdab
Parents: cba773a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jan 26 08:16:24 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8a8d2e12/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
index 45d2970..d87a9c5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
@@ -393,7 +393,7 @@ public enum GryoVersion {
             add(GryoTypeReg.of(LP_NL_O_OB_P_S_SE_SL_Traverser.class, 179));
             add(GryoTypeReg.of(LabelledCounter.class, 180));
             add(GryoTypeReg.of(Stack.class, 181));
-            add(GryoTypeReg.of(ReferenceMap.class, 182));                        // ***LAST ID***
+            add(GryoTypeReg.of(ReferenceMap.class, 182));
 
 
             // placeholder serializers for classes that don't live here in core. this will allow them to be used if
@@ -405,7 +405,7 @@ public enum GryoVersion {
                     "org.apache.tinkerpop.gremlin.driver.ser.ResponseMessageGryoSerializer", 169);
 
             tryAddDynamicType(this, "org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStrategy",
-                    null, 1690);
+                    null, 183);   // ***LAST ID***
         }};
     }
 


[35/50] tinkerpop git commit: TINKERPOP-1878 Added basic docs for sparql-gremlin

Posted by sp...@apache.org.
TINKERPOP-1878 Added basic docs for sparql-gremlin


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

Branch: refs/heads/TINKERPOP-1878
Commit: 36fa84282876e0f911446c38fcacc191b24af3d6
Parents: 005239f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jan 29 11:04:23 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/preprocessor/install-plugins.sh    |  2 +-
 docs/src/reference/index.asciidoc       |  2 +
 docs/src/reference/transpilers.asciidoc | 66 ++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36fa8428/docs/preprocessor/install-plugins.sh
----------------------------------------------------------------------
diff --git a/docs/preprocessor/install-plugins.sh b/docs/preprocessor/install-plugins.sh
index 0a7ca31..f1da197 100755
--- a/docs/preprocessor/install-plugins.sh
+++ b/docs/preprocessor/install-plugins.sh
@@ -25,7 +25,7 @@ TMP_DIR=$3
 INSTALL_TEMPLATE="docs/preprocessor/install-plugins.groovy"
 INSTALL_FILE="${TMP_DIR}/install-plugins.groovy"
 
-plugins=("hadoop-gremlin" "spark-gremlin" "neo4j-gremlin")
+plugins=("hadoop-gremlin" "spark-gremlin" "neo4j-gremlin", "sparql-gremlin")
 # plugins=()
 pluginsCount=${#plugins[@]}
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36fa8428/docs/src/reference/index.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/index.asciidoc b/docs/src/reference/index.asciidoc
index 6e81bf2..02a218b 100644
--- a/docs/src/reference/index.asciidoc
+++ b/docs/src/reference/index.asciidoc
@@ -45,6 +45,8 @@ include::implementations-hadoop-end.asciidoc[]
 
 include::gremlin-variants.asciidoc[]
 
+include::transpilers.asciidoc[]
+
 include::conclusion.asciidoc[]
 
 include::acknowledgements.asciidoc[]

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36fa8428/docs/src/reference/transpilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/transpilers.asciidoc b/docs/src/reference/transpilers.asciidoc
new file mode 100644
index 0000000..305e3dc
--- /dev/null
+++ b/docs/src/reference/transpilers.asciidoc
@@ -0,0 +1,66 @@
+////
+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
+
+[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.


[40/50] tinkerpop git commit: TINKERPOP-1878 Fixed up formatting of traspiler section

Posted by sp...@apache.org.
TINKERPOP-1878 Fixed up formatting of traspiler section

There were some examples that didn't return results or generated errors. These will need some review.


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

Branch: refs/heads/TINKERPOP-1878
Commit: ea3e89184645a4664283420dfb8c57e775897f23
Parents: e291867
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Apr 3 10:52:17 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/src/reference/transpilers.asciidoc | 156 ++++++++++++---------------
 1 file changed, 71 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ea3e8918/docs/src/reference/transpilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/transpilers.asciidoc b/docs/src/reference/transpilers.asciidoc
index 386b4a5..b05be68 100644
--- a/docs/src/reference/transpilers.asciidoc
+++ b/docs/src/reference/transpilers.asciidoc
@@ -84,8 +84,7 @@ start step.
 and then when finally iterated, executes that against the TinkerGraph.
 
 [[prefixes]]
-Prefixes
-~~~~~~~~~
+=== Prefixes
 
 The SPARQL-Gremlin transpiler supports the following prefixes to traverse the graph:
 
@@ -110,10 +109,11 @@ g.sparql("""SELECT ?name ?id ?label
 ----
 
 [[supported-queries]]
-Supported Queries
-~~~~~~~~~~~~~~~~~~
+=== Supported Queries
 
-The SPARQL-Gremlin transpiler is currently an on-going effort with an aim to cover the entire SPARQL 1.1 query feature spectrum, however we currently only support translation of the SPARQL 1.0 specification, especially _SELECT_ queries. The supported SPARQL query types are: 
+The SPARQL-Gremlin transpiler is currently an on-going effort with an aim to cover the entire SPARQL 1.1 query feature
+spectrum, however we currently only support translation of the SPARQL 1.0 specification, especially _SELECT_ queries.
+The supported SPARQL query types are:
 
 * Union 
 * Optional 
@@ -127,29 +127,25 @@ The SPARQL-Gremlin transpiler is currently an on-going effort with an aim to cov
 ** OFFSET
 
 [[limitations]]
-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:
+* SPARQL queries with variables in the predicate position are not currently covered, with an exception of the following
+case:
 
-[gremlin-groovy,existing]
+[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 unput 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).
+* 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).
 
-[gremlin-groovy,existing]
+[source,groovy]
 ----
 g.sparql("""SELECT * 
 	WHERE {
@@ -170,16 +166,15 @@ Adding more here...
 ....
 
 [[examples]]
-Examples
-~~~~~~~~~
+=== Examples
 
-The following section presents a comprehensive examples of SPARQL queries that are currently covered by the SPARQL-Gremlin transpiler.
+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
 
-.Select all vertices in the graph.
+Select all vertices in the graph.
 
 [gremlin-groovy,existing]
 ----
@@ -187,10 +182,9 @@ g.sparql("""SELECT * WHERE { }""")
 ----
 
 [[match-constant-values]]
-Match Constant Values
-^^^^^^^^^^^^^^^^^^^^^
+==== Match Constant Values
 
-.Select all vertices with the label `person`.
+Select all vertices with the label `person`.
 
 [gremlin-groovy,existing]
 ----
@@ -198,10 +192,9 @@ g.sparql("""SELECT * WHERE {  ?person v:label "person" .}""")
 ----
 
 [[select-specific-elements]]
-Select Specific Elements
-^^^^^^^^^^^^^^^^^^^^^^^^
+==== Select Specific Elements
 
-.Select the values of the properties `name` and `age` for each `person` vertex.
+Select the values of the properties `name` and `age` for each `person` vertex.
 
 [gremlin-groovy,existing]
 ----
@@ -213,10 +206,9 @@ WHERE {
 ----
 
 [[pattern-matching]]
-Pattern Matching
-^^^^^^^^^^^^^^^^
+==== Pattern Matching
 
-.Select only those persons who created a project.
+Select only those persons who created a project.
 
 [gremlin-groovy,existing]
 ----
@@ -229,10 +221,9 @@ WHERE {
 ----
 
 [[filtering]]
-Filtering
-^^^^^^^^^
+==== Filtering
 
-.Select only those persons who are older than 30.
+Select only those persons who are older than 30.
 
 [gremlin-groovy,existing]
 ----
@@ -241,31 +232,29 @@ WHERE {
   ?person v:label "person" .
   ?person v:name ?name .
   ?person v:age ?age .
-  ?person e:created ?project .
     FILTER (?age > 30) }""")
 ----
 
 [[deduplication]]
-Deduplication
-^^^^^^^^^^^^^
+==== Deduplication
 
-.Select the distinct names of the created projects.
+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
-^^^^^^^^^^^^^^^^
+==== Multiple Filters
 
-.Select the distinct names of all Java projects.
+Select the distinct names of all Java projects.
 
 [gremlin-groovy,existing]
 ----
@@ -276,14 +265,13 @@ WHERE {
   ?person e:created ?project .
   ?project v:name ?name .
   ?project v:lang ?lang .
-    FILTER (?age > 30 && ?lang == "java") }""")
+    FILTER (?age > 30 && ?lang = "java") }""")
 ----
 
 [[pattern-filters]]
-Pattern Filter(s)
-^^^^^^^^^^^^^^^^^
+==== Pattern Filter(s)
 
-.A different way to filter all person who created a project.
+A different way to filter all person who created a project.
 
 [gremlin-groovy,existing]
 ----
@@ -294,7 +282,7 @@ WHERE {
     FILTER EXISTS { ?person e:created ?project } }""")
 ----
 
-.Filter all person who did not create a project.
+Filter all person who did not create a project.
 
 [gremlin-groovy,existing]
 ----
@@ -305,27 +293,10 @@ WHERE {
     FILTER NOT EXISTS { ?person e:created ?project } }""")
 ----
 
-[[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,existing]
-----
-g.sparql("""SELECT ?name ?startTime
-WHERE {
-  ?person v:name "daniel" .
-  ?person p:location ?location .
-  ?location v:value ?name .
-  ?location v:startTime ?startTime }""")
-----
-
 [[union]]
-Union
-^^^^^
+==== Union
 
-.Select all persons who have developed a software in java using union.
+Select all persons who have developed a software in java using union.
 
 [gremlin-groovy,existing]
 ----
@@ -337,12 +308,11 @@ WHERE {
 ----
 
 [[optional]]
-Optional
-^^^^^^^^
+==== Optional
 
-.Return the names of the persons who have created a software in java and optionally python.
+Return the names of the persons who have created a software in java and optionally python.
 
-[gremlin-groovy,existing]
+[source,groovy]
 ----
 g.sparql("""SELECT ?person 
 WHERE {
@@ -353,10 +323,9 @@ WHERE {
 ----
 
 [[order-by]]
-Order By
-^^^^^^^^
+==== Order By
 
-.Select all vertices with the label `person` and order them by their age.
+Select all vertices with the label `person` and order them by their age.
 
 [gremlin-groovy,existing]
 ----
@@ -368,12 +337,11 @@ WHERE {
 ----
 
 [[group-by]]
-Group By
-^^^^^^^^
+==== Group By
 
-.Select all vertices with the label `person` and group them by their age.
+Select all vertices with the label `person` and group them by their age.
 
-[gremlin-groovy,existing]
+[source,groovy]
 ----
 g.sparql("""SELECT * 
 WHERE {
@@ -383,12 +351,12 @@ WHERE {
 ----
 
 [[mixedcomplexaggregation-based-queries]]
-Mixed/complex/aggregation-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.
+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.
 
-[gremlin-groovy,existing]
+[source,groovy]
 ----
 g.sparql("""SELECT COUNT(?project) 
 WHERE {
@@ -398,11 +366,29 @@ WHERE {
 } 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
 
-.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 neighbourhood queries. For instance, getting all the information about a specific `person` or `software`.
+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]
 ----


[10/50] tinkerpop git commit: Merge branch 'tp33'

Posted by sp...@apache.org.
Merge branch 'tp33'


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

Branch: refs/heads/TINKERPOP-1878
Commit: 9b41f5a7f4b2b8bef226f5a62685bfdfd17c0feb
Parents: a5d1aa6 2cf551f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 7 06:30:35 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 7 06:30:35 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                                | 1 +
 .../tinkerpop/gremlin/server/util/GremlinServerInstall.java       | 3 +++
 2 files changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9b41f5a7/CHANGELOG.asciidoc
----------------------------------------------------------------------


[43/50] tinkerpop git commit: Update compilers.asciidoc

Posted by sp...@apache.org.
Update compilers.asciidoc

Updating documentation:
- fixed optional clause 
- updated optional clause limitation while in nesting with union & order-by
- went through other examples and limitations

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

Branch: refs/heads/TINKERPOP-1878
Commit: 8ffd63cd09a55f1d0e5dd4a85720de485a653242
Parents: c95ce50
Author: Harsh Thakkar <ha...@gmail.com>
Authored: Wed Aug 1 11:27:59 2018 +0200
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 2018 -0400

----------------------------------------------------------------------
 docs/src/reference/compilers.asciidoc | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8ffd63cd/docs/src/reference/compilers.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/compilers.asciidoc b/docs/src/reference/compilers.asciidoc
index e015cc8..5b6ab2e 100644
--- a/docs/src/reference/compilers.asciidoc
+++ b/docs/src/reference/compilers.asciidoc
@@ -206,9 +206,8 @@ WHERE { ?person v:label "person" . ?person v:age ?age . ?person v:name ?name . }
 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...
-....
+In the current implementation, `OPTIONAL` clause doesn't work under nesting with `UNION` clause (i.e. multiple optional clauses with in a union clause) and `ORDER-By` clause (i.e. declaring ordering over triple patterns within optional clauses). Everything else with SPARQL `OPTIONAL` works just fine.
+
 
 [[examples]]
 === Examples


[20/50] tinkerpop git commit: TINKERPOP-1878 Minor javadoc and code cleanup

Posted by sp...@apache.org.
TINKERPOP-1878 Minor javadoc and code cleanup


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

Branch: refs/heads/TINKERPOP-1878
Commit: 9cd732756c1d5455460547035062a3d91502069d
Parents: 64b0a1e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 15:36:53 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../process/traversal/dsl/sparql/SparqlTraversal.java   | 12 +++---------
 .../traversal/dsl/sparql/SparqlTraversalSource.java     |  8 +++++++-
 .../process/traversal/strategy/SparqlStrategy.java      | 11 ++++++++---
 3 files changed, 18 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9cd73275/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
index efa9489..843267d 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
@@ -22,6 +22,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 
 /**
+ * The {@code SparqlTraversal} has no additional traversal steps. The only step available for "SPARQL" is the
+ * {@link SparqlTraversalSource#sparql(String)} start step.
+ *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public interface SparqlTraversal<S, E> extends Traversal<S, E> {
@@ -56,13 +59,4 @@ public interface SparqlTraversal<S, E> extends Traversal<S, E> {
         Traversal.super.iterate();
         return this;
     }
-
-    public static final class Symbols {
-
-        private Symbols() {
-            // static fields only
-        }
-
-        public static final String sparql = "sparql";
-    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9cd73275/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
index 3596716..b156ed1 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -25,12 +25,15 @@ import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Transaction;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
 /**
+ * A {@link TraversalSource} implementation that spawns {@link SparqlTraversal} instances.
+ *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class SparqlTraversalSource implements TraversalSource {
@@ -115,9 +118,12 @@ public class SparqlTraversalSource implements TraversalSource {
         return (SparqlTraversalSource) clone;
     }
 
+    /**
+     * The start step for a SPARQL based traversal that accepts a string representation of the query to execute.
+     */
     public <S> SparqlTraversal<S,String> sparql(final String query) {
         final SparqlTraversalSource clone = this.clone();
-        clone.bytecode.addStep(SparqlTraversal.Symbols.sparql, query);
+        clone.bytecode.addStep(GraphTraversal.Symbols.constant, query);
         final SparqlTraversal.Admin<S, S> traversal = new DefaultSparqlTraversal<>(clone);
         return traversal.addStep(new ConstantStep<S,String>(traversal, query));
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9cd73275/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 07ac4cf..bb0b326 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
@@ -22,17 +22,22 @@ import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decorati
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.map.TraversalMapStep;
 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.SparqlToGremlinCompiler;
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.dsl.sparql.SparqlTraversalSource;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
 import java.util.Collections;
 import java.util.Set;
 
 /**
+ * This {@link TraversalStrategy} is used in conjunction with the {@link SparqlTraversalSource} which has a single
+ * {@code sparql()} start step. That step adds a {@link ConstantStep} to the traversal with the SPARQL query within
+ * it as a string value. This strategy finds that step and transpiles it to a Gremlin traversal which then replaces
+ * the {@link ConstantStep}.
+ *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.DecorationStrategy>
@@ -69,11 +74,11 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
                 sparqlTraversal.asAdmin().getSteps().forEach(s -> traversal.addStep(s));
             } else {
                 // The ConstantStep expects a string value
-                throw new IllegalStateException("SparqlStrategy cannot be applied to this traversal");
+                throw new IllegalStateException("SparqlStrategy cannot be applied to a traversal that does not consist of a single ConstantStep<?,String>");
             }
         } else {
             // SparqlStrategy requires that there be one step and it be a ConstantStep that contains some SPARQL
-            throw new IllegalStateException("SparqlStrategy cannot be applied to this traversal");
+            throw new IllegalStateException("SparqlStrategy cannot be applied to a traversal that does not consist of a single ConstantStep<?,String>");
         }
     }
 }


[24/50] tinkerpop git commit: TINKERPOP-1878 Test cleanup for sparql-gremlin

Posted by sp...@apache.org.
TINKERPOP-1878 Test cleanup for sparql-gremlin


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

Branch: refs/heads/TINKERPOP-1878
Commit: cba773abf803f3e4c4a6e3a1598b153263bd2979
Parents: 60146b5
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jan 26 08:10:48 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 sparql-gremlin/pom.xml                          |  10 +-
 .../dsl/sparql/SparqlTraversalSource.java       |   4 +-
 .../gremlin/sparql/ResourceHelper.java          |  37 ---
 .../sparql/SparqlToGremlinCompilerTest.java     | 223 -------------------
 .../dsl/sparql/SparqlTraversalSourceTest.java   |  31 ++-
 5 files changed, 36 insertions(+), 269 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cba773ab/sparql-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/sparql-gremlin/pom.xml b/sparql-gremlin/pom.xml
index 0e3da38..731b822 100644
--- a/sparql-gremlin/pom.xml
+++ b/sparql-gremlin/pom.xml
@@ -41,9 +41,13 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.tinkerpop</groupId>
-            <artifactId>gremlin-test</artifactId>
-            <version>${project.version}</version>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-all</artifactId>
             <scope>test</scope>
         </dependency>
     </dependencies>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cba773ab/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
index deb16f7..cc54aa5 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.InjectStep;
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStrategy;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Transaction;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
@@ -46,6 +47,7 @@ public class SparqlTraversalSource implements TraversalSource {
     public SparqlTraversalSource(final Graph graph, final TraversalStrategies traversalStrategies) {
         this.graph = graph;
         this.strategies = traversalStrategies;
+        this.strategies.addStrategies(SparqlStrategy.instance());
     }
 
     public SparqlTraversalSource(final Graph graph) {
@@ -122,7 +124,7 @@ public class SparqlTraversalSource implements TraversalSource {
     /**
      * The start step for a SPARQL based traversal that accepts a string representation of the query to execute.
      */
-    public <S> SparqlTraversal<S,String> sparql(final String query) {
+    public <S> SparqlTraversal<S,?> sparql(final String query) {
         final SparqlTraversalSource clone = this.clone();
 
         // this is a bit of a hack to get remote traversals to work cleanly. on the remote side, we'd expect a

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cba773ab/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/ResourceHelper.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/ResourceHelper.java
deleted file mode 100644
index 4f58e61..0000000
--- a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/ResourceHelper.java
+++ /dev/null
@@ -1,37 +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 org.apache.commons.io.IOUtils;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * @author Daniel Kuppitz (http://gremlin.guru)
- */
-public class ResourceHelper {
-
-    public static String loadQuery(final String prefix, final int number) throws IOException {
-        final String path = "/queries/" + prefix + number + ".sparql";
-        final InputStream stream = ResourceHelper.class.getResourceAsStream(path);
-        return IOUtils.toString(stream, "UTF-8");
-    }
-}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cba773ab/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompilerTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompilerTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompilerTest.java
deleted file mode 100644
index 3fb49e8..0000000
--- a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/SparqlToGremlinCompilerTest.java
+++ /dev/null
@@ -1,223 +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 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.structure.Graph;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.apache.tinkerpop.gremlin.process.computer.Computer;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import static org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinCompiler.convertToGremlinTraversal;
-import static org.junit.Assert.assertEquals;
-
-
-import java.io.IOException;
-
-import static org.apache.tinkerpop.gremlin.sparql.ResourceHelper.loadQuery;
-
-
-public class SparqlToGremlinCompilerTest {
-
-    private Graph modern, crew;
-    private GraphTraversalSource mg, cg;
-    private GraphTraversalSource mc, cc;
-/*
-    @Before
-    public void setUp() throws Exception {
-        modern = TinkerFactory.createModern();
-        mg = modern.traversal();
-        mc = modern.traversal(computer());
-        crew = TinkerFactory.createTheCrew();
-        cg = modern.traversal();
-        cc = modern.traversal(computer());
-    }
-
-    @Ignore
-    @Test
-    public void play() throws IOException {
-        final String query = loadQuery("modern", 11);
-        final Traversal traversal = convertToGremlinTraversal(modern, query);
-        System.out.println(traversal);
-        System.out.println(traversal.toList());
-        System.out.println(traversal);
-    }
-
-    /* Modern */
-
- /*   @Test
-    public void testModern1() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("a").hasLabel("person"),
-                as("a").out("knows").as("b"),
-                as("a").out("created").as("c"),
-                as("b").out("created").as("c"),
-                as("a").values("age").as("d")).where(as("d").is(lt(30))).
-                select("a", "b", "c");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 1)));
-    }
-
-    @Test
-    public void testModern2() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("a").hasLabel("person"),
-                as("a").out("knows").as("b"),
-                as("a").out("created").as("c"),
-                as("b").out("created").as("c"),
-                as("a").values("age").as("d")).where(as("d").is(lt(30)));
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 2)));
-    }
-
-    @Test
-    public void testModern3() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("person").values("name").as("name"),
-                as("person").values("age").as("age")).select("name", "age");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 3)));
-    }
-
-    @Test
-    public void testModern4() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("person").values("name").as("name"),
-                as("person").values("age").as("age"),
-                as("person").out("created").as("project"),
-                as("project").values("name").is("lop")).select("name", "age");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 4)));
-    }
-
-    @Test
-    public void testModern5() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("person").values("name").as("name"),
-                as("person").values("age").is(29)).select("name");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 5)));
-    }
-
-    @Test
-    public void testModern6() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("person").values("name").as("name"),
-                as("person").values("age").as("age")).where(and(as("age").is(gt(30)), as("age").is(lt(40)))).
-                select("name", "age");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 6)));
-    }
-
-    @Test
-    public void testModern7() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("person").values("name").as("name"),
-                as("person").values("age").as("age")).where(or(as("age").is(lt(30)), as("age").is(gt(40)))).
-                select("name", "age");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 7)));
-    }
-
-    @Test
-    public void testModern8() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("person").values("name").as("name"),
-                as("person").values("age").as("age")).where(
-                or(and(as("age").is(gt(30)), as("age").is(lt(40))), as("name").is("marko"))).
-                select("name", "age");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 8)));
-    }
-
-    @Test
-    public void testModern9() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("a").values("name").as("name")).where(as("a").values("age")).
-                select("name");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 9)));
-    }
-
-    @Test
-    public void testModern10() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("a").values("name").as("name")).where(__.not(as("a").values("age"))).
-                select("name");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 10)));
-    }
-
-    @Test
-    public void testModern11() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("a").out("created").as("b"),
-                as("a").values("name").as("name")).dedup("name").select("name");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 11)));
-    }
-
-    @Test
-    public void testModern12() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("a").out("created").as("b"),
-                as("b").values("name").as("name")).dedup();
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 12)));
-    }
-
-    @Test
-    public void testModern13() throws Exception {
-        final GraphTraversal expected = mg.V().match(
-                as("a").out("created").as("b"),
-                as("a").values("name").as("c")).dedup("a", "b", "c").select("a", "b", "c");
-        assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 13)));
-    }
-
-    /* The Crew */
-
- /*   @Test
-    public void testCrew1() throws Exception {
-        final GraphTraversal expected = cg.V().match(
-                as("a").values("name").is("daniel"),
-                as("a").properties("location").as("b"),
-                as("b").value().as("c"),
-                as("b").values("startTime").as("d")).
-                select("c", "d");
-        assertEquals(expected, convertToGremlinTraversal(crew, loadQuery("crew", 1)));
-    }
-
-    /* Computer Mode */
-
-  /*  @Test
-    public void testModernInComputerMode() throws Exception {
-        final GraphTraversal expected = mc.V().match(
-                as("a").hasLabel("person"),
-                as("a").out("knows").as("b"),
-                as("a").out("created").as("c"),
-                as("b").out("created").as("c"),
-                as("a").values("age").as("d")).where(as("d").is(lt(30))).
-                select("a", "b", "c");
-        assertEquals(expected, convertToGremlinTraversal(mc, loadQuery("modern", 1)));
-    }
-
-    @Test
-    public void testCrewInComputerMode() throws Exception {
-        final GraphTraversal expected = cc.V().match(
-                as("a").values("name").is("daniel"),
-                as("a").properties("location").as("b"),
-                as("b").value().as("c"),
-                as("b").values("startTime").as("d")).
-                select("c", "d");
-        assertEquals(expected, convertToGremlinTraversal(crew, loadQuery("crew", 1)));
-    } */
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cba773ab/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
index 9e5ffc0..9bb6025 100644
--- a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
@@ -18,11 +18,16 @@
  */
 package org.apache.tinkerpop.gremlin.sparql.process.traversal.dsl.sparql;
 
-import org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStrategy;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
 import org.junit.Test;
 
+import java.util.HashMap;
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
+
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
@@ -31,9 +36,25 @@ public class SparqlTraversalSourceTest {
     @Test
     public void shouldDoStuff() {
         final Graph graph = TinkerFactory.createModern();
-        final SparqlTraversalSource g = graph.traversal(SparqlTraversalSource.class).
-                                                withStrategies(SparqlStrategy.instance());
-        final Object x = g.sparql("SELECT ?name ?age WHERE { ?person v:name ?name . ?person v:age ?age }").toList();
-        System.out.println(x);
+        final SparqlTraversalSource g = graph.traversal(SparqlTraversalSource.class);
+        final List<?> x = g.sparql("SELECT ?name ?age WHERE { ?person v:name ?name . ?person v:age ?age }").toList();
+        assertThat(x, containsInAnyOrder(
+                new HashMap<String,Object>(){{
+                    put("name", "marko");
+                    put("age", 29);
+                }},
+                new HashMap<String,Object>(){{
+                    put("name", "vadas");
+                    put("age", 27);
+                }},
+                new HashMap<String,Object>(){{
+                    put("name", "josh");
+                    put("age", 32);
+                }},
+                new HashMap<String,Object>(){{
+                    put("name", "peter");
+                    put("age", 35);
+                }}
+        ));
     }
 }


[27/50] tinkerpop git commit: TINKERPOP-1878 Added a test for ordering and corrected some problems in logic

Posted by sp...@apache.org.
TINKERPOP-1878 Added a test for ordering and corrected some problems in logic

Ordering didn't work - at least not completely. The test, as it is written in this commit, that failed to sort properly. Changed the logic for ordering to track all of the keys specified to ORDER with their appropriate ASC/DESC operators and added all of them to the traversal.


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

Branch: refs/heads/TINKERPOP-1878
Commit: bb21a3df342d620405085a5434a655a2b4b4a3cb
Parents: e364a9d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jan 26 15:41:10 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../sparql/SparqlToGremlinTranspiler.java       | 55 ++++++--------------
 .../dsl/sparql/SparqlTraversalSourceTest.java   | 31 +++++++++--
 2 files changed, 44 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bb21a3df/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
index 9db7d82..ea3f828 100644
--- 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
@@ -21,9 +21,10 @@ 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.graph.Triple;
 import org.apache.jena.query.Query;
 import org.apache.jena.query.QueryFactory;
 import org.apache.jena.query.SortCondition;
@@ -58,8 +59,6 @@ public class SparqlToGremlinTranspiler {
 
     private List<Traversal> traversalList = new ArrayList<>();
 
-    private String sortingVariable = "";
-
 	private SparqlToGremlinTranspiler(final GraphTraversal<Vertex, ?> traversal) {
 		this.traversal = traversal;
 	}
@@ -96,31 +95,18 @@ public class SparqlToGremlinTranspiler {
 		final int numberOfTraversal = traversalList.size();
         final Traversal arrayOfAllTraversals[] = new Traversal[numberOfTraversal];
 
-		if (query.hasOrderBy() && !query.hasGroupBy()) {
-            final List<SortCondition> sortingConditions = query.getOrderBy();
-
-			for (SortCondition sortCondition : sortingConditions) {
-                final Expr expr = sortCondition.getExpression();
-				sortingVariable = expr.getVarName();
-			}
-		}
-
 		for (Traversal tempTrav : traversalList) {
 			arrayOfAllTraversals[traversalIndex++] = tempTrav;
 		}
 
-		Order orderDirection = Order.incr;
+		final Map<String, Order> orderingIndex = new HashMap<>();
 		if (query.hasOrderBy()) {
-            int directionOfSort = 0;
             final List<SortCondition> sortingConditions = query.getOrderBy();
 
 			for (SortCondition sortCondition : sortingConditions) {
                 final Expr expr = sortCondition.getExpression();
-				directionOfSort = sortCondition.getDirection();
-				sortingVariable = expr.getVarName();
+                orderingIndex.put(expr.getVarName(), sortCondition.getDirection() == 1 ? Order.incr : Order.decr);
 			}
-
-			if (directionOfSort == -1) orderDirection = Order.decr;
 		}
 
 		if (traversalList.size() > 0)
@@ -128,6 +114,8 @@ public class SparqlToGremlinTranspiler {
 
 		final List<String> vars = query.getResultVars();
 		if (!query.isQueryResultStar() && !query.hasGroupBy()) {
+		    // the result sizes have special handling to get the right signatures of select() called. perhaps this
+            // could be refactored to work more nicely
             switch (vars.size()) {
                 case 0:
                     throw new IllegalStateException();
@@ -135,20 +123,16 @@ public class SparqlToGremlinTranspiler {
                     if (query.isDistinct())
                         traversal = traversal.dedup(vars.get(0));
 
-                    if (query.hasOrderBy())
-                        traversal = traversal.order().by(sortingVariable, orderDirection);
-                    else
-                        traversal = traversal.select(vars.get(0));
+                    orderingIndex.forEach((k,v) -> traversal = traversal.order().by(__.select(k), v));
+                    traversal = traversal.select(vars.get(0));
 
                     break;
                 case 2:
                     if (query.isDistinct())
                         traversal = traversal.dedup(vars.get(0), vars.get(1));
 
-                    if (query.hasOrderBy())
-                        traversal = traversal.order().by(__.select(vars.get(0)), orderDirection).by(__.select(vars.get(1)));
-                    else
-                        traversal = traversal.select(vars.get(0), vars.get(1));
+                    orderingIndex.forEach((k,v) -> traversal = traversal.order().by(__.select(k), v));
+                    traversal = traversal.select(vars.get(0), vars.get(1));
 
                     break;
                 default:
@@ -157,11 +141,11 @@ public class SparqlToGremlinTranspiler {
                     if (query.isDistinct())
                         traversal = traversal.dedup(all);
 
+                    orderingIndex.forEach((k,v) -> traversal = traversal.order().by(__.select(k), v));
+
+                    // just some shenanigans to get the right signature of select() called
                     final String[] others = Arrays.copyOfRange(all, 2, vars.size());
-                    if (query.hasOrderBy())
-                        traversal = traversal.order().by(__.select(vars.get(0)), orderDirection).by(__.select(vars.get(1)));
-                    else
-                        traversal = traversal.select(vars.get(0), vars.get(1), others);
+                    traversal = traversal.select(vars.get(0), vars.get(1), others);
 
                     break;
             }
@@ -202,7 +186,7 @@ public class SparqlToGremlinTranspiler {
 		}
 
 		if (query.hasOrderBy() && query.hasGroupBy())
-			traversal = traversal.order().by(sortingVariable, orderDirection);
+            orderingIndex.forEach((k,v) -> traversal = traversal.order().by(__.select(k), v));
 
 		if (query.hasLimit()) {
 			long limit = query.getLimit(), offset = 0;
@@ -233,14 +217,7 @@ public class SparqlToGremlinTranspiler {
          */
         @Override
         public void visit(final OpBGP opBGP) {
-            final List<Triple> triples = opBGP.getPattern().getList();
-            final Traversal[] matchTraversals = new Traversal[triples.size()];
-            int i = 0;
-            for (final Triple triple : triples) {
-
-                matchTraversals[i++] = TraversalBuilder.transform(triple);
-                traversalList.add(matchTraversals[i - 1]);
-            }
+            opBGP.getPattern().getList().forEach(triple -> traversalList.add(TraversalBuilder.transform(triple)));
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bb21a3df/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
index 9bb6025..2743255 100644
--- a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
@@ -27,16 +27,18 @@ import java.util.List;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class SparqlTraversalSourceTest {
 
+    private static final Graph graph = TinkerFactory.createModern();
+    private static final SparqlTraversalSource g = graph.traversal(SparqlTraversalSource.class);
+
     @Test
-    public void shouldDoStuff() {
-        final Graph graph = TinkerFactory.createModern();
-        final SparqlTraversalSource g = graph.traversal(SparqlTraversalSource.class);
+    public void shouldFindAllPersonsNamesAndAges() {
         final List<?> x = g.sparql("SELECT ?name ?age WHERE { ?person v:name ?name . ?person v:age ?age }").toList();
         assertThat(x, containsInAnyOrder(
                 new HashMap<String,Object>(){{
@@ -57,4 +59,27 @@ public class SparqlTraversalSourceTest {
                 }}
         ));
     }
+
+    @Test
+    public void shouldFindAllPersonsNamesAndAgesOrdered() {
+        final List<?> x = g.sparql("SELECT ?name ?age WHERE { ?person v:name ?name . ?person v:age ?age } ORDER BY ASC(?age)").toList();
+        assertThat(x, contains(
+                new HashMap<String,Object>(){{
+                    put("name", "vadas");
+                    put("age", 27);
+                }},
+                new HashMap<String,Object>(){{
+                    put("name", "marko");
+                    put("age", 29);
+                }},
+                new HashMap<String,Object>(){{
+                    put("name", "josh");
+                    put("age", 32);
+                }},
+                new HashMap<String,Object>(){{
+                    put("name", "peter");
+                    put("age", 35);
+                }}
+        ));
+    }
 }


[16/50] tinkerpop git commit: TINKERPOP-1878 Added some Traversal infrastructure

Posted by sp...@apache.org.
TINKERPOP-1878 Added some Traversal infrastructure

This is the start of getting Sparql working as a DSL in TinkerPop


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

Branch: refs/heads/TINKERPOP-1878
Commit: 5533cdcbfba411a8421167e7b93f48ba7f57cdec
Parents: a12f556
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jan 24 17:04:27 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:29 2018 -0400

----------------------------------------------------------------------
 .../dsl/sparql/DefaultSparqlTraversal.java      |  55 ++++++++
 .../traversal/dsl/sparql/SparqlTraversal.java   |  68 +++++++++
 .../dsl/sparql/SparqlTraversalSource.java       | 138 +++++++++++++++++++
 .../traversal/strategy/SparqlStrategy.java      |  25 ++++
 4 files changed, 286 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5533cdcb/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/DefaultSparqlTraversal.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/DefaultSparqlTraversal.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/DefaultSparqlTraversal.java
new file mode 100644
index 0000000..133d4be
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/DefaultSparqlTraversal.java
@@ -0,0 +1,55 @@
+/*
+ * 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.process.traversal.dsl.sparql;
+
+import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class DefaultSparqlTraversal<S, E> extends DefaultTraversal<S, E> implements SparqlTraversal.Admin<S, E> {
+
+    public DefaultSparqlTraversal() {
+        super();
+    }
+
+    public DefaultSparqlTraversal(final SparqlTraversalSource sparqlTraversalSource) {
+        super(sparqlTraversalSource);
+    }
+
+    public DefaultSparqlTraversal(final Graph graph) {
+        super(graph);
+    }
+
+    @Override
+    public SparqlTraversal.Admin<S, E> asAdmin() {
+        return this;
+    }
+
+    @Override
+    public SparqlTraversal<S, E> iterate() {
+        return SparqlTraversal.Admin.super.iterate();
+    }
+
+    @Override
+    public DefaultSparqlTraversal<S, E> clone() {
+        return (DefaultSparqlTraversal<S, E>) super.clone();
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5533cdcb/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
new file mode 100644
index 0000000..efa9489
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
@@ -0,0 +1,68 @@
+/*
+ * 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.process.traversal.dsl.sparql;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public interface SparqlTraversal<S, E> extends Traversal<S, E> {
+    public interface Admin<S, E> extends Traversal.Admin<S, E>, SparqlTraversal<S, E> {
+
+        @Override
+        public default <E2> SparqlTraversal.Admin<S, E2> addStep(final Step<?, E2> step) {
+            return (SparqlTraversal.Admin<S, E2>) Traversal.Admin.super.addStep((Step) step);
+        }
+
+        @Override
+        public default SparqlTraversal<S, E> iterate() {
+            return SparqlTraversal.super.iterate();
+        }
+
+        @Override
+        public SparqlTraversal.Admin<S, E> clone();
+    }
+
+    @Override
+    public default SparqlTraversal.Admin<S, E> asAdmin() {
+        return (SparqlTraversal.Admin<S, E>) this;
+    }
+
+    ////
+
+    /**
+     * Iterates the traversal presumably for the generation of side-effects.
+     */
+    @Override
+    public default SparqlTraversal<S, E> iterate() {
+        Traversal.super.iterate();
+        return this;
+    }
+
+    public static final class Symbols {
+
+        private Symbols() {
+            // static fields only
+        }
+
+        public static final String sparql = "sparql";
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5533cdcb/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
new file mode 100644
index 0000000..3596716
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -0,0 +1,138 @@
+/*
+ * 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.process.traversal.dsl.sparql;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.process.remote.RemoteConnection;
+import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.decoration.RemoteStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Transaction;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class SparqlTraversalSource implements TraversalSource {
+    protected transient RemoteConnection connection;
+    protected final Graph graph;
+    protected TraversalStrategies strategies;
+    protected Bytecode bytecode = new Bytecode();
+
+    public SparqlTraversalSource(final Graph graph, final TraversalStrategies traversalStrategies) {
+        this.graph = graph;
+        this.strategies = traversalStrategies;
+    }
+
+    public SparqlTraversalSource(final Graph graph) {
+        this(graph, TraversalStrategies.GlobalCache.getStrategies(graph.getClass()));
+    }
+
+    @Override
+    public TraversalStrategies getStrategies() {
+        return this.strategies;
+    }
+
+    @Override
+    public Graph getGraph() {
+        return this.graph;
+    }
+
+    @Override
+    public Bytecode getBytecode() {
+        return this.bytecode;
+    }
+
+    @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
+    public SparqlTraversalSource clone() {
+        try {
+            final SparqlTraversalSource clone = (SparqlTraversalSource) super.clone();
+            clone.strategies = this.strategies.clone();
+            clone.bytecode = this.bytecode.clone();
+            return clone;
+        } catch (final CloneNotSupportedException e) {
+            throw new IllegalStateException(e.getMessage(), e);
+        }
+    }
+
+    //// CONFIGURATIONS
+
+    @Override
+    public SparqlTraversalSource withStrategies(final TraversalStrategy... traversalStrategies) {
+        return (SparqlTraversalSource) TraversalSource.super.withStrategies(traversalStrategies);
+    }
+
+    @Override
+    @SuppressWarnings({"unchecked"})
+    public SparqlTraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses) {
+        return (SparqlTraversalSource) TraversalSource.super.withoutStrategies(traversalStrategyClasses);
+    }
+
+    @Override
+    public SparqlTraversalSource withRemote(final Configuration conf) {
+        return (SparqlTraversalSource) TraversalSource.super.withRemote(conf);
+    }
+
+    @Override
+    public SparqlTraversalSource withRemote(final String configFile) throws Exception {
+        return (SparqlTraversalSource) TraversalSource.super.withRemote(configFile);
+    }
+
+    @Override
+    public SparqlTraversalSource withRemote(final RemoteConnection connection) {
+        try {
+            // check if someone called withRemote() more than once, so just release resources on the initial
+            // connection as you can't have more than one. maybe better to toss IllegalStateException??
+            if (this.connection != null)
+                this.connection.close();
+        } catch (Exception ignored) {
+            // not sure there's anything to do here
+        }
+
+        this.connection = connection;
+        final TraversalSource clone = this.clone();
+        clone.getStrategies().addStrategies(new RemoteStrategy(connection));
+        return (SparqlTraversalSource) clone;
+    }
+
+    public <S> SparqlTraversal<S,String> sparql(final String query) {
+        final SparqlTraversalSource clone = this.clone();
+        clone.bytecode.addStep(SparqlTraversal.Symbols.sparql, query);
+        final SparqlTraversal.Admin<S, S> traversal = new DefaultSparqlTraversal<>(clone);
+        return traversal.addStep(new ConstantStep<S,String>(traversal, query));
+    }
+
+    public Transaction tx() {
+        return this.graph.tx();
+    }
+
+    @Override
+    public void close() throws Exception {
+        if (connection != null) connection.close();
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.traversalSourceString(this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5533cdcb/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
new file mode 100644
index 0000000..6440127
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
@@ -0,0 +1,25 @@
+/*
+ * 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.process.traversal.strategy;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class SparqlStrategy {
+}


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

Posted by sp...@apache.org.
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/0b1d6fa4
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/0b1d6fa4
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/0b1d6fa4

Branch: refs/heads/TINKERPOP-1878
Commit: 0b1d6fa483a45cbfb202293f1493bb0e0e7779f6
Parents: 24fb38c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jun 20 07:25:17 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:31 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/0b1d6fa4/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/0b1d6fa4/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/0b1d6fa4/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/0b1d6fa4/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/0b1d6fa4/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/0b1d6fa4/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/0b1d6fa4/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));


[15/50] tinkerpop git commit: Merge branch 'tp33'

Posted by sp...@apache.org.
Merge branch 'tp33'

Conflicts:
	gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractOpProcessor.java


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

Branch: refs/heads/TINKERPOP-1878
Commit: 9357d6a1fd91cac4bd7149b94ed757399aa810a4
Parents: 1e8baec fa7a7f6
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 7 12:54:18 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 7 12:54:18 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   1 +
 .../driver/message/ResponseStatusCode.java      |   7 +
 .../driver/message/ResponseStatusCodeTest.java  |  36 +++++
 .../gremlin/server/ResponseHandlerContext.java  |  85 +++++++++++
 .../server/op/AbstractEvalOpProcessor.java      |  38 ++++-
 .../gremlin/server/op/AbstractOpProcessor.java  |  34 ++++-
 .../AbstractGremlinServerIntegrationTest.java   |  20 ++-
 .../server/GremlinServerIntegrateTest.java      |  51 +++++++
 .../server/ResponseHandlerContextTest.java      | 143 +++++++++++++++++++
 .../server/op/AbstractEvalOpProcessorTest.java  |  62 ++++++++
 .../server/op/AbstractOpProcessorTest.java      |  53 +++++++
 11 files changed, 515 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9357d6a1/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9357d6a1/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractOpProcessor.java
----------------------------------------------------------------------
diff --cc gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractOpProcessor.java
index bb368c5,38ca3e1..331b762
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractOpProcessor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractOpProcessor.java
@@@ -66,8 -72,20 +67,20 @@@ public abstract class AbstractOpProcess
       *
       * @param context The Gremlin Server {@link Context} object containing settings, request message, etc.
       * @param itty The result to iterator
+      * @throws TimeoutException if the time taken to serialize the entire result set exceeds the allowable time.
+      * @see #handleIterator(ResponseHandlerContext, Iterator)
       */
 -    protected void handleIterator(final Context context, final Iterator itty) throws TimeoutException, InterruptedException {
 +    protected void handleIterator(final Context context, final Iterator itty) throws InterruptedException {
+         handleIterator(new ResponseHandlerContext(context), itty);
+     }
+ 
+     /**
+      * A variant of {@link #handleIterator(Context, Iterator)} that is suitable for use in situations when multiple
+      * threads may produce {@link ResponseStatusCode#isFinalResponse() final} response messages concurrently.
+      * @see #handleIterator(Context, Iterator)
+      */
 -    protected void handleIterator(final ResponseHandlerContext rhc, final Iterator itty) throws TimeoutException, InterruptedException {
++    protected void handleIterator(final ResponseHandlerContext rhc, final Iterator itty) throws InterruptedException {
+         final Context context = rhc.getContext();
          final ChannelHandlerContext ctx = context.getChannelHandlerContext();
          final RequestMessage msg = context.getRequestMessage();
          final Settings settings = context.getSettings();
@@@ -228,9 -261,32 +241,22 @@@
          return Collections.emptyMap();
      }
  
+     /**
 -     * @deprecated As of release 3.2.2, replaced by {@link #makeFrame(ChannelHandlerContext, RequestMessage, MessageSerializer, boolean, List, ResponseStatusCode, Map)}.
 -     */
 -    @Deprecated
 -    protected static Frame makeFrame(final ChannelHandlerContext ctx, final RequestMessage msg,
 -                                     final MessageSerializer serializer, final boolean useBinary, final List<Object> aggregate,
 -                                     final ResponseStatusCode code) throws Exception {
 -        return makeFrame(ctx, msg, serializer, useBinary, aggregate, code, Collections.emptyMap());
 -    }
 -
 -    /**
+      * Caution: {@link #makeFrame(ResponseHandlerContext, RequestMessage, MessageSerializer, boolean, List, ResponseStatusCode, Map)}
+      * should be used instead of this method whenever a {@link ResponseHandlerContext} is available.
+      */
      protected static Frame makeFrame(final ChannelHandlerContext ctx, final RequestMessage msg,
 -                                   final MessageSerializer serializer, final boolean useBinary, final List<Object> aggregate,
 -                                   final ResponseStatusCode code, final Map<String,Object> responseMetaData) throws Exception {
 +                                     final MessageSerializer serializer, final boolean useBinary, final List<Object> aggregate,
 +                                     final ResponseStatusCode code, final Map<String,Object> responseMetaData) throws Exception {
+         final Context context = new Context(msg, ctx, null, null, null, null); // dummy context, good only for writing response messages to the channel
+         final ResponseHandlerContext rhc = new ResponseHandlerContext(context);
+         return makeFrame(rhc, msg, serializer, useBinary, aggregate, code, responseMetaData);
+     }
+ 
+     protected static Frame makeFrame(final ResponseHandlerContext rhc, final RequestMessage msg,
 -                                   final MessageSerializer serializer, final boolean useBinary, final List<Object> aggregate,
 -                                   final ResponseStatusCode code, final Map<String,Object> responseMetaData) throws Exception {
++                                     final MessageSerializer serializer, final boolean useBinary, final List<Object> aggregate,
++                                     final ResponseStatusCode code, final Map<String,Object> responseMetaData) throws Exception {
+         final ChannelHandlerContext ctx = rhc.getContext().getChannelHandlerContext();
          try {
              if (useBinary) {
                  return new Frame(serializer.serializeResponseAsBinary(ResponseMessage.build(msg)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9357d6a1/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
----------------------------------------------------------------------
diff --cc gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
index 08b8526,67ad021..f97fb1f
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
@@@ -69,7 -71,9 +70,8 @@@ import org.junit.Test
  
  import java.lang.reflect.Field;
  import java.nio.channels.ClosedChannelException;
 -import java.util.ArrayList;
  import java.util.HashMap;
+ import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9357d6a1/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/op/AbstractOpProcessorTest.java
----------------------------------------------------------------------
diff --cc gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/op/AbstractOpProcessorTest.java
index 0000000,a7cee1a..aba1603
mode 000000,100644..100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/op/AbstractOpProcessorTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/op/AbstractOpProcessorTest.java
@@@ -1,0 -1,73 +1,53 @@@
+ /*
+  * 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.server.op;
+ 
+ import io.netty.channel.ChannelHandlerContext;
+ import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
+ import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
+ import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
+ import org.junit.Test;
+ import org.mockito.ArgumentCaptor;
+ import org.mockito.Mockito;
+ 
+ import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.fail;
+ 
+ public class AbstractOpProcessorTest {
+ 
+     @Test
 -    public void deprecatedMakeFrameMethodShouldRedirectCorrectly() throws Exception {
 -        final ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
 -        final RequestMessage request = RequestMessage.build("test").create();
 -        final ArgumentCaptor<ResponseMessage> responseCaptor = ArgumentCaptor.forClass(ResponseMessage.class);
 -
 -        try {
 -            // Induce a NullPointerException to validate error response message writing
 -            //noinspection deprecation
 -            AbstractOpProcessor.makeFrame(ctx, request, null, true, null, ResponseStatusCode.PARTIAL_CONTENT);
 -            fail("Expected a NullPointerException");
 -        } catch (NullPointerException expected) {
 -            // nop
 -        }
 -
 -        Mockito.verify(ctx, Mockito.times(1)).writeAndFlush(responseCaptor.capture());
 -        assertEquals(ResponseStatusCode.SERVER_ERROR_SERIALIZATION, responseCaptor.getValue().getStatus().getCode());
 -        assertEquals(request.getRequestId(), responseCaptor.getValue().getRequestId());
 -    }
 -
 -    @Test
+     public void alternativeMakeFrameMethodShouldRedirectCorrectly() throws Exception {
+         final ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
+         final RequestMessage request = RequestMessage.build("test").create();
+         final ArgumentCaptor<ResponseMessage> responseCaptor = ArgumentCaptor.forClass(ResponseMessage.class);
+ 
+         try {
+             // Induce a NullPointerException to validate error response message writing
+             AbstractOpProcessor.makeFrame(ctx, request, null, true, null, ResponseStatusCode.PARTIAL_CONTENT, null);
+             fail("Expected a NullPointerException");
+         } catch (NullPointerException expected) {
+             // nop
+         }
+ 
+         Mockito.verify(ctx, Mockito.times(1)).writeAndFlush(responseCaptor.capture());
+         assertEquals(ResponseStatusCode.SERVER_ERROR_SERIALIZATION, responseCaptor.getValue().getStatus().getCode());
+         assertEquals(request.getRequestId(), responseCaptor.getValue().getRequestId());
+     }
+ 
+ }


[07/50] tinkerpop git commit: Update bulk import/export section for graph providers given g.io() CTR

Posted by sp...@apache.org.
Update bulk import/export section for graph providers given g.io() CTR


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

Branch: refs/heads/TINKERPOP-1878
Commit: a5d1aa660b28a5c126b3f7dec945f8558d42816c
Parents: 72b264d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Aug 6 07:46:58 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Aug 6 07:46:58 2018 -0400

----------------------------------------------------------------------
 docs/src/dev/provider/index.asciidoc | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a5d1aa66/docs/src/dev/provider/index.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/dev/provider/index.asciidoc b/docs/src/dev/provider/index.asciidoc
index ab57020..49bc7c7 100644
--- a/docs/src/dev/provider/index.asciidoc
+++ b/docs/src/dev/provider/index.asciidoc
@@ -620,12 +620,17 @@ reason to implement this interface.
 ==== Bulk Import Export
 
 When it comes to doing "bulk" operations, the diverse nature of the available graph databases and their specific
-capabilities, prevents TinkerPop from doing a good job of generalizing that capability well. TinkerPop refers users to
-the bulk import/export facilities of specific graph providers as they tend to be more efficient and easier to use than
-the options TinkerPop has tried to generalize in the past.
+capabilities, prevents TinkerPop from doing a good job of generalizing that capability well. TinkerPop thus maintains
+two positions on the concept of import and export:
 
-That said, for graph providers that don't have a special bulk loading feature, they can get a basic bulk loader from
-TinkerPop using the link:http://tinkerpop.apache.org/docs/x.y.z/reference/#clonevertexprogram[CloneVertexProgram].
+1. TinkerPop refers users to the bulk import/export facilities of specific graph providers as they tend to be more
+efficient and easier to use than the options TinkerPop has tried to generalize in the past.
+2. TinkerPop encourages graph providers to expose those capabilities via `g.io()` and the `IoStep` by way of a
+`TraversalStrategy`.
+
+That said, for graph providers that don't have a special bulk loading feature, they can either rely on the default
+OLTP (single-threaded) `GraphReader` and `GraphWriter` options that are embedded in `IoStep` or get a basic bulk loader
+from TinkerPop using the link:http://tinkerpop.apache.org/docs/x.y.z/reference/#clonevertexprogram[CloneVertexProgram].
 Simply provide a `InputFormat` and `OutputFormat` that can be referenced by a `HadoopGraph` instance as discussed
 in the link:http://tinkerpop.apache.org/docs/x.y.z/reference/#clonevertexprogram[Reference Documentation].
 


[28/50] tinkerpop git commit: TINKERPOP-1878 More tests for ordering

Posted by sp...@apache.org.
TINKERPOP-1878 More tests for ordering

Factored the order index creation into its own method to tidy up a bit.


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

Branch: refs/heads/TINKERPOP-1878
Commit: 326e35d052f7d6aa011b022c503f1ff38d844bc9
Parents: bb21a3d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jan 26 15:56:55 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:30 2018 -0400

----------------------------------------------------------------------
 .../sparql/SparqlToGremlinTranspiler.java       | 29 ++++++++++++++------
 .../dsl/sparql/SparqlTraversalSourceTest.java   |  6 ++++
 2 files changed, 26 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/326e35d0/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
index ea3f828..c3bc907 100644
--- 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
@@ -99,15 +99,8 @@ public class SparqlToGremlinTranspiler {
 			arrayOfAllTraversals[traversalIndex++] = tempTrav;
 		}
 
-		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();
-                orderingIndex.put(expr.getVarName(), sortCondition.getDirection() == 1 ? Order.incr : Order.decr);
-			}
-		}
+		// 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);
@@ -203,6 +196,24 @@ public class SparqlToGremlinTranspiler {
 		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();
+                orderingIndex.put(expr.getVarName(), sortCondition.getDirection() == 1 ? Order.incr : Order.decr);
+            }
+        }
+
+        return orderingIndex;
+    }
+
     private static GraphTraversal<Vertex, ?> transpile(final GraphTraversalSource g, final Query query) {
         return new SparqlToGremlinTranspiler(g).transpile(query);
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/326e35d0/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
index 2743255..1b39813 100644
--- a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
@@ -82,4 +82,10 @@ public class SparqlTraversalSourceTest {
                 }}
         ));
     }
+
+    @Test
+    public void shouldFindAllNamesOrdered() {
+        final List<?> x = g.sparql("SELECT ?name WHERE { ?person v:name ?name } ORDER BY DESC(?name)").toList();
+        assertThat(x, contains("vadas", "ripple", "peter", "marko", "lop", "josh"));
+    }
 }


[49/50] tinkerpop git commit: TINKERPOP-1878 Updated changelog

Posted by sp...@apache.org.
TINKERPOP-1878 Updated changelog


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

Branch: refs/heads/TINKERPOP-1878
Commit: 37a38ae85d26826fb3aff985f1e428885c23da7c
Parents: f46f677
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Aug 8 07:28:11 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Aug 8 07:47:32 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a38ae8/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index a175c99..950131a 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -31,6 +31,8 @@ This release also includes changes from <<release-3-3-3, 3.3.3>>.
 * Deprecated `Graph.io()` and related infrastructure.
 * Bumped to Netty 4.1.25.
 * Bumped to Spark 2.3.1.
+* Added sparql-gremlin.
+* Fixed a bug in dynamic Gryo registration where registrations that did not have serializers would fail.
 * Moved `Parameterizing` interface to the `org.apache.tinkerpop.gremlin.process.traversal.step` package with other marker interfaces of its type.
 * Replaced `Parameterizing.addPropertyMutations()` with `Configuring.configure()`.
 * Changed interface hierarchy for `Parameterizing` and `Mutating` interfaces as they are tightly related.
@@ -111,7 +113,6 @@ This release also includes changes from <<release-3-2-8, 3.2.8>>.
 
 * Fixed regression issue where the HTTPChannelizer doesn't instantiate the specified AuthenticationHandler.
 * Defaulted GLV tests for gremlin-python to run for GraphSON 3.0.
-* Fixed a bug in dynamic Gryo registration where registrations that did not have serializers would fail.
 * Fixed a bug with `Tree` serialization in GraphSON 3.0.
 * In gremlin-python, the GraphSON 3.0 `g:Set` type is now deserialized to `List`.