tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject incubator-tinkerpop git commit: added support for Gremlin-Python [x:y] range/limit syntax. Added withSideEffects(), withBulk(), etc. stuff to VariantSource. The only tests that are failing now are ones where Double vs. Float is an issue (Python has no co
Date Wed, 01 Jun 2016 16:57:10 GMT
Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 88ba4b366 -> 5b0a7678f


added support for Gremlin-Python [x:y] range/limit syntax. Added withSideEffects(), withBulk(),
etc. stuff to VariantSource. The only tests that are failing now are ones where Double vs.
Float is an issue (Python has no concept of double). And where we do stuff like g.V(g.V(1).next()).
I think I will just generalize the Double tests to use Number.doubleValue().


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

Branch: refs/heads/TINKERPOP-1278
Commit: 5b0a7678f13448911f1690074c28a45ccb01a4b0
Parents: 88ba4b3
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Wed Jun 1 10:57:05 2016 -0600
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Wed Jun 1 10:57:05 2016 -0600

----------------------------------------------------------------------
 .../variant/VariantGraphTraversalSource.java    | 108 ++++++++++++++++++-
 .../variant/python/PythonVariantConverter.java  |  10 +-
 2 files changed, 113 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/5b0a7678/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversalSource.java
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversalSource.java
b/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversalSource.java
index 191c1bb..6bc689d 100644
--- a/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversalSource.java
+++ b/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversalSource.java
@@ -22,25 +22,127 @@ package org.apache.tinkerpop.gremlin.process.variant;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
 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.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
+import java.util.function.BinaryOperator;
+import java.util.function.Supplier;
+import java.util.function.UnaryOperator;
+
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
  */
 public class VariantGraphTraversalSource extends GraphTraversalSource {
 
     private VariantConverter variantConverter;
+    private StringBuilder sourceString = new StringBuilder("g");
 
     public VariantGraphTraversalSource(final VariantConverter variantConverter, final Graph
graph, final TraversalStrategies traversalStrategies) {
         super(graph, traversalStrategies);
         this.variantConverter = variantConverter;
     }
 
+    private static String getMethodName() {
+        return Thread.currentThread().getStackTrace()[2].getMethodName();
+    }
+
+    ///
+
+    @Override
+    public GraphTraversal<Edge, Edge> E(final Object... edgeIds) {
+        final StringBuilder temp = new StringBuilder(this.sourceString.toString());
+        this.variantConverter.step(temp, getMethodName(), edgeIds);
+        return new VariantGraphTraversal<>(this.getGraph(), temp, this.variantConverter);
+    }
+
+    @Override
     public GraphTraversal<Vertex, Vertex> V(final Object... vertexIds) {
-        final StringBuilder variantString = new StringBuilder("g");
-        this.variantConverter.step(variantString, "V", vertexIds);
-        return new VariantGraphTraversal<>(this.getGraph(), variantString, this.variantConverter);
+        final StringBuilder temp = new StringBuilder(this.sourceString.toString());
+        this.variantConverter.step(temp, getMethodName(), vertexIds);
+        return new VariantGraphTraversal<>(this.getGraph(), temp, this.variantConverter);
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSack(final Supplier<A> initialValue,
final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator) {
+        this.variantConverter.step(this.sourceString, getMethodName(), splitOperator, mergeOperator);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSack(final A initialValue, final UnaryOperator<A>
splitOperator, final BinaryOperator<A> mergeOperator) {
+        this.variantConverter.step(this.sourceString, getMethodName(), initialValue, splitOperator,
mergeOperator);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSack(final A initialValue) {
+        this.variantConverter.step(this.sourceString, getMethodName(), initialValue);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSack(final Supplier<A> initialValue)
{
+        this.variantConverter.step(this.sourceString, getMethodName(), initialValue);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSack(final Supplier<A> initialValue,
final UnaryOperator<A> splitOperator) {
+        this.variantConverter.step(this.sourceString, getMethodName(), initialValue, splitOperator);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSack(final A initialValue, final UnaryOperator<A>
splitOperator) {
+        this.variantConverter.step(this.sourceString, getMethodName(), initialValue, splitOperator);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSack(final Supplier<A> initialValue,
final BinaryOperator<A> mergeOperator) {
+        this.variantConverter.step(this.sourceString, getMethodName(), initialValue, mergeOperator);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSack(final A initialValue, final BinaryOperator<A>
mergeOperator) {
+        this.variantConverter.step(this.sourceString, getMethodName(), initialValue, mergeOperator);
+        return this;
+    }
+
+    /////
+
+    @Override
+    public <A> GraphTraversalSource withSideEffect(final String key, final Supplier<A>
initialValue, final BinaryOperator<A> reducer) {
+        this.variantConverter.step(this.sourceString, getMethodName(), key, initialValue,
reducer);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSideEffect(final String key, final A initialValue,
final BinaryOperator<A> reducer) {
+        this.variantConverter.step(this.sourceString, getMethodName(), key, initialValue,
reducer);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSideEffect(final String key, final A initialValue)
{
+        this.variantConverter.step(this.sourceString, getMethodName(), key, initialValue);
+        return this;
+    }
+
+    @Override
+    public <A> GraphTraversalSource withSideEffect(final String key, final Supplier<A>
initialValue) {
+        this.variantConverter.step(this.sourceString, getMethodName(), key, initialValue);
+        return this;
+    }
+
+    /////
+
+    @Override
+    public GraphTraversalSource withBulk(final boolean useBulk) {
+        this.variantConverter.step(this.sourceString, getMethodName(), useBulk);
+        return this;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/5b0a7678/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/python/PythonVariantConverter.java
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/python/PythonVariantConverter.java
b/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/python/PythonVariantConverter.java
index 2fa29a0..5f18bcb 100644
--- a/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/python/PythonVariantConverter.java
+++ b/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/process/variant/python/PythonVariantConverter.java
@@ -64,7 +64,7 @@ public class PythonVariantConverter implements VariantConverter {
 
     @Override
     public String compileVariant(final StringBuilder currentTraversal) throws ScriptException
{
-        if (currentTraversal.toString().contains("$"))
+        if (currentTraversal.toString().contains("$") || currentTraversal.toString().contains("@"))
             throw new VerificationException("Lambda: " + currentTraversal.toString(), EmptyTraversal.instance());
 
         final Bindings jythonBindings = new SimpleBindings();
@@ -78,6 +78,10 @@ public class PythonVariantConverter implements VariantConverter {
     public void step(final StringBuilder currentTraversal, final String stepName, final Object...
arguments) {
         if (arguments.length == 0)
             currentTraversal.append(".").append(convertStepName(stepName)).append("()");
+        else if (stepName.equals("range") && 2 == arguments.length)
+            currentTraversal.append("[").append(arguments[0]).append(":").append(arguments[1]).append("]");
+        else if (stepName.equals("limit") && 1 == arguments.length)
+            currentTraversal.append("[0:").append(arguments[0]).append("]");
         else {
             String temp = "." + convertStepName(stepName) + "(";
             for (final Object object : arguments) {
@@ -124,7 +128,9 @@ public class PythonVariantConverter implements VariantConverter {
         else if (object instanceof VariantGraphTraversal) {
             final String string = ((VariantGraphTraversal) object).variantString.toString();
             return string;
-        } else
+        } else if (object instanceof Boolean)
+            return object.equals(Boolean.TRUE) ? "True" : "False";
+        else
             return null == object ? "" : object.toString();
     }
 


Mime
View raw message