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/03/14 12:17:39 UTC

[1/8] tinkerpop git commit: TINKERPOP-1898 Can't seem to fix this in a consistent way given jython evaluation

Repository: tinkerpop
Updated Branches:
  refs/heads/master 3e00a6402 -> c0571dfd2


TINKERPOP-1898 Can't seem to fix this in a consistent way given jython evaluation

Jython seems to have problems with varargs that are not easily resolved. Nothing I've tried works consistently. Sometimes it works and other times not.


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

Branch: refs/heads/master
Commit: c82d06e05cfcc05607dd2d84c0c2d1475f0a0ddf
Parents: c677a21
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Mar 12 11:53:57 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Mar 12 11:56:16 2018 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java      | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c82d06e0/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
index 343819c..3165df3 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
@@ -29,6 +29,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.Read
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
 import org.apache.tinkerpop.gremlin.util.function.Lambda;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import java.util.ArrayList;
@@ -108,6 +109,7 @@ public class JythonTranslatorTest {
     }
 
     @Test
+    @Ignore("TINKERPOP-1898 - ultimately seems to be a problem with jython and varargs - doesn't act consistently")
     public void shouldTranslateToJythonWhenUsingLambdasAndStrategies() throws Exception {
         // the jython translation kicks in when you add a lambda so ensure that it translates when strategies are
         // present


[6/8] tinkerpop git commit: Merge branch 'TINKERPOP-1896' into tp32

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


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

Branch: refs/heads/master
Commit: 1ea01ad2e0748d400cc89d92d2dbfe07dd2cb6be
Parents: 5cf1cba 01ef6c1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 14 07:58:22 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Mar 14 07:58:22 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../jsr223/GremlinJythonScriptEngine.java       |  7 +--
 .../gremlin/python/jsr223/JythonTranslator.java | 28 +++++++++
 .../gremlin/python/jsr223/PythonTranslator.java | 33 ++++++----
 .../python/jsr223/JythonTranslatorTest.java     | 63 ++++++++++++--------
 5 files changed, 88 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1ea01ad2/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --cc CHANGELOG.asciidoc
index 97b90a5,a761003..94ee24f
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@@ -30,8 -29,8 +30,9 @@@ image::https://raw.githubusercontent.co
  * Added the "Kitchen Sink" test data set.
  * Fixed deserialization of `P.not()` for GraphSON.
  * Bumped to Jackson 2.9.4.
 +* Improved performance of `JavaTranslator` by caching reflected methods required for traversal construction.
  * Added `idleConnectionTimeout` and `keepAliveInterval` to Gremlin Server that enables a "ping" and auto-close for seemingly dead clients.
+ * Fixed a bug where lambdas in `gremlin-python` would trigger a failure if steps using python-only symbols were present (such as `as_()`).
  * Fixed a bug in `NumberHelper` that led to wrong min/max results if numbers exceeded the Integer limits.
  * Delayed setting of the request identifier until `RequestMessage` construction by the builder.
  * Improved error messaging for failed serialization and deserialization of request/response messages.


[8/8] 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/c0571dfd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/c0571dfd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/c0571dfd

Branch: refs/heads/master
Commit: c0571dfd2e87c8830b5c4bd27eea3dadbadba9b0
Parents: 3e00a64 0c6459d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 14 08:15:12 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Mar 14 08:15:12 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../jsr223/GremlinJythonScriptEngine.java       |  7 +--
 .../gremlin/python/jsr223/JythonTranslator.java | 28 +++++++++
 .../gremlin/python/jsr223/PythonTranslator.java | 35 ++++++-----
 .../python/jsr223/JythonTranslatorTest.java     | 63 ++++++++++++--------
 5 files changed, 89 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


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


[3/8] tinkerpop git commit: TINKERPOP-1895 Fixed jython based evaluations of withStrategies

Posted by sp...@apache.org.
TINKERPOP-1895 Fixed jython based evaluations of withStrategies

Similar to TINKERPOP-1896 in that a lambda would trigger a scriptengine evaluation with jython which would fail when withStrategies() was used as the JythonTranslator was actually producing Python valid code rather than Jython valid code.


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

Branch: refs/heads/master
Commit: f3172bc55ef3e8f298dccfeb18c9fe6b4c27767c
Parents: 5feadbd
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 9 09:38:35 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Mar 12 11:56:16 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                               |  1 +
 .../gremlin/python/jsr223/JythonTranslator.java  | 19 +++++++++++++++++++
 .../gremlin/python/jsr223/PythonTranslator.java  | 14 ++++++++------
 .../python/jsr223/JythonTranslatorTest.java      | 13 +++++++++++++
 4 files changed, 41 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f3172bc5/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index a761003..350fce8 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -31,6 +31,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Bumped to Jackson 2.9.4.
 * Added `idleConnectionTimeout` and `keepAliveInterval` to Gremlin Server that enables a "ping" and auto-close for seemingly dead clients.
 * Fixed a bug where lambdas in `gremlin-python` would trigger a failure if steps using python-only symbols were present (such as `as_()`).
+* Fixed a bug where lambdas in `gremlin-python` would trigger a failure if `withStrategies()` was evaluated.
 * Fixed a bug in `NumberHelper` that led to wrong min/max results if numbers exceeded the Integer limits.
 * Delayed setting of the request identifier until `RequestMessage` construction by the builder.
 * Improved error messaging for failed serialization and deserialization of request/response messages.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f3172bc5/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
index f8a5bc3..3d7d9fe 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
@@ -19,8 +19,17 @@
 
 package org.apache.tinkerpop.gremlin.python.jsr223;
 
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationConverter;
+import org.apache.commons.configuration.MapConfiguration;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.TraversalStrategyProxy;
 import org.apache.tinkerpop.gremlin.util.function.Lambda;
 
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
  * @author Stephen Mallette (http://stephen.genoprime.com)
@@ -63,4 +72,14 @@ public final class JythonTranslator extends PythonTranslator {
         // jython one can just pass them through.
         return methodName;
     }
+
+    @Override
+    protected String resolveTraversalStrategyProxy(final TraversalStrategyProxy proxy) {
+        // since this is jython we don't need a traversal proxy here - we need the actual JVM version of the strategy
+        // since this script will be executed in Jython. 
+        if (proxy.getConfiguration().isEmpty())
+            return proxy.getStrategyClass().getCanonicalName() + ".instance()";
+        else
+            return proxy.getStrategyClass().getCanonicalName() + ".create(new org.apache.commons.configuration.MapConfiguration(" + convertToString(ConfigurationConverter.getMap(proxy.getConfiguration())) + "))";
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f3172bc5/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
index 7c74b85..d8c73f0 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
@@ -139,7 +139,7 @@ public class PythonTranslator implements Translator.ScriptTranslator {
         return traversalScript.toString();
     }
 
-    private String convertToString(final Object object) {
+    protected String convertToString(final Object object) {
         if (object instanceof Bytecode.Binding)
             return ((Bytecode.Binding) object).variable();
         else if (object instanceof Bytecode)
@@ -172,11 +172,7 @@ public class PythonTranslator implements Translator.ScriptTranslator {
         } else if (object instanceof Long)
             return object + "L";
         else if (object instanceof TraversalStrategyProxy) {
-            final TraversalStrategyProxy proxy = (TraversalStrategyProxy) object;
-            if (proxy.getConfiguration().isEmpty())
-                return "TraversalStrategy(\"" + proxy.getStrategyClass().getSimpleName() + "\")";
-            else
-                return "TraversalStrategy(\"" + proxy.getStrategyClass().getSimpleName() + "\"," + convertToString(ConfigurationConverter.getMap(proxy.getConfiguration())) + ")";
+            return resolveTraversalStrategyProxy((TraversalStrategyProxy) object);
         } else if (object instanceof TraversalStrategy) {
             return convertToString(new TraversalStrategyProxy((TraversalStrategy) object));
         } else if (object instanceof Boolean)
@@ -242,4 +238,10 @@ public class PythonTranslator implements Translator.ScriptTranslator {
         return SymbolHelper.toPython(methodName);
     }
 
+    protected String resolveTraversalStrategyProxy(final TraversalStrategyProxy proxy) {
+        if (proxy.getConfiguration().isEmpty())
+            return "TraversalStrategy(\"" + proxy.getStrategyClass().getSimpleName() + "\")";
+        else
+            return "TraversalStrategy(\"" + proxy.getStrategyClass().getSimpleName() + "\"," + convertToString(ConfigurationConverter.getMap(proxy.getConfiguration())) + ")";
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f3172bc5/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
index 86e3b78..e35898b 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
@@ -24,6 +24,7 @@ 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.process.traversal.strategy.decoration.TranslationStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
 import org.apache.tinkerpop.gremlin.util.function.Lambda;
@@ -103,4 +104,16 @@ public class JythonTranslatorTest {
 
         assertEquals(6, o.size());
     }
+
+    @Test
+    public void shouldTranslateToJythonWhenUsingLambdasAndStrategies() throws Exception {
+        // the jython translation kicks in when you add a lambda so ensure that it translates when strategies are
+        // present
+        GraphTraversalSource g = TinkerFactory.createModern().traversal();
+        g = g.withStrategies(new TranslationStrategy(g, JythonTranslator.of("g")));
+        final List<Object> o = g.withStrategies(ReadOnlyStrategy.instance()).
+                V().has("name").map(Lambda.function("lambda x: type(x.get())")).toList();
+
+        assertEquals(6, o.size());
+    }
 }


[7/8] tinkerpop git commit: Merge branch 'tp32' into tp33

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

Conflicts:
	gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java


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

Branch: refs/heads/master
Commit: 0c6459d992f7c643e433e3482d676c7096288438
Parents: 9bd4d7f 1ea01ad
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 14 08:14:54 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Mar 14 08:14:54 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../jsr223/GremlinJythonScriptEngine.java       |  7 +--
 .../gremlin/python/jsr223/JythonTranslator.java | 28 +++++++++
 .../gremlin/python/jsr223/PythonTranslator.java | 35 ++++++-----
 .../python/jsr223/JythonTranslatorTest.java     | 63 ++++++++++++--------
 5 files changed, 89 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0c6459d9/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --cc CHANGELOG.asciidoc
index bbae529,94ee24f..a5aac3d
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@@ -283,9 -32,9 +283,10 @@@ image::https://raw.githubusercontent.co
  * Bumped to Jackson 2.9.4.
  * Improved performance of `JavaTranslator` by caching reflected methods required for traversal construction.
  * Added `idleConnectionTimeout` and `keepAliveInterval` to Gremlin Server that enables a "ping" and auto-close for seemingly dead clients.
+ * Fixed a bug where lambdas in `gremlin-python` would trigger a failure if steps using python-only symbols were present (such as `as_()`).
  * Fixed a bug in `NumberHelper` that led to wrong min/max results if numbers exceeded the Integer limits.
  * Delayed setting of the request identifier until `RequestMessage` construction by the builder.
 +* `ReferenceElement` avoids `UnsupportedOperationException` handling in construction thus improving performance.
  * Improved error messaging for failed serialization and deserialization of request/response messages.
  * Fixed handling of `Direction.BOTH` in `Messenger` implementations to pass the message to the opposite side of the `StarGraph`.
  * Removed hardcoded expectation in metrics serialization test suite as different providers may have different outputs.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0c6459d9/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0c6459d9/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
----------------------------------------------------------------------
diff --cc gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
index 568ca03,d8c73f0..b453cd7
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
@@@ -107,14 -110,15 +108,14 @@@ public class PythonTranslator implement
          for (final Bytecode.Instruction instruction : bytecode.getInstructions()) {
              final String methodName = instruction.getOperator();
              final Object[] arguments = instruction.getArguments();
 -            if (IS_TESTING &&
 -                    instruction.getOperator().equals(TraversalSource.Symbols.withStrategies) &&
 -                    instruction.getArguments()[0].toString().contains("TranslationStrategy"))
 -                continue;
 -            else if (0 == arguments.length)
 +            if (0 == arguments.length)
-                 traversalScript.append(".").append(SymbolHelper.toPython(methodName)).append("()");
-             else if (methodName.equals("range") && 2 == arguments.length && ((Number) arguments[0]).intValue() != 0) {
+                 traversalScript.append(".").append(resolveSymbol(methodName)).append("()");
+             else if (methodName.equals("range") && 2 == arguments.length)
 -                traversalScript.append("[").append(arguments[0]).append(":").append(arguments[1]).append("]");
 +                if (((Number) arguments[0]).longValue() + 1 == ((Number) arguments[1]).longValue())
 +                    traversalScript.append("[").append(arguments[0]).append("]");
 +                else
 +                    traversalScript.append("[").append(arguments[0]).append(":").append(arguments[1]).append("]");
-             } else if (methodName.equals("limit") && 1 == arguments.length)
+             else if (methodName.equals("limit") && 1 == arguments.length)
                  traversalScript.append("[0:").append(arguments[0]).append("]");
              else if (methodName.equals("values") && 1 == arguments.length && traversalScript.length() > 3 && !STEP_NAMES.contains(arguments[0].toString()))
                  traversalScript.append(".").append(arguments[0]);


[5/8] tinkerpop git commit: TINKERPOP-1896 Cleaned up changelog around TINKERPOP-1898/1895

Posted by sp...@apache.org.
TINKERPOP-1896 Cleaned up changelog around TINKERPOP-1898/1895


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

Branch: refs/heads/master
Commit: 01ef6c110cc323643653c716fbb85fcf433dc418
Parents: c82d06e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Mar 12 12:19:18 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Mar 12 12:19:18 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/01ef6c11/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 350fce8..a761003 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -31,7 +31,6 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Bumped to Jackson 2.9.4.
 * Added `idleConnectionTimeout` and `keepAliveInterval` to Gremlin Server that enables a "ping" and auto-close for seemingly dead clients.
 * Fixed a bug where lambdas in `gremlin-python` would trigger a failure if steps using python-only symbols were present (such as `as_()`).
-* Fixed a bug where lambdas in `gremlin-python` would trigger a failure if `withStrategies()` was evaluated.
 * Fixed a bug in `NumberHelper` that led to wrong min/max results if numbers exceeded the Integer limits.
 * Delayed setting of the request identifier until `RequestMessage` construction by the builder.
 * Improved error messaging for failed serialization and deserialization of request/response messages.


[2/8] tinkerpop git commit: TINKERPOP-1898 Specifically tested SubgraphStrategy for jython evaluation

Posted by sp...@apache.org.
TINKERPOP-1898 Specifically tested SubgraphStrategy for jython evaluation


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

Branch: refs/heads/master
Commit: c677a21d3fde73c496145915c66e7963c5290f69
Parents: f3172bc
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 9 10:17:09 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Mar 12 11:56:16 2018 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/python/jsr223/JythonTranslator.java   | 2 +-
 .../gremlin/python/jsr223/JythonTranslatorTest.java         | 9 ++++++---
 2 files changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c677a21d/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
index 3d7d9fe..e043278 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
@@ -80,6 +80,6 @@ public final class JythonTranslator extends PythonTranslator {
         if (proxy.getConfiguration().isEmpty())
             return proxy.getStrategyClass().getCanonicalName() + ".instance()";
         else
-            return proxy.getStrategyClass().getCanonicalName() + ".create(new org.apache.commons.configuration.MapConfiguration(" + convertToString(ConfigurationConverter.getMap(proxy.getConfiguration())) + "))";
+            return proxy.getStrategyClass().getCanonicalName() + ".create(org.apache.commons.configuration.MapConfiguration(" + convertToString(ConfigurationConverter.getMap(proxy.getConfiguration())) + "))";
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c677a21d/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
index e35898b..343819c 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 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.process.traversal.strategy.decoration.SubgraphStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -33,6 +34,7 @@ import org.junit.Test;
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.hasLabel;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
@@ -111,9 +113,10 @@ public class JythonTranslatorTest {
         // present
         GraphTraversalSource g = TinkerFactory.createModern().traversal();
         g = g.withStrategies(new TranslationStrategy(g, JythonTranslator.of("g")));
-        final List<Object> o = g.withStrategies(ReadOnlyStrategy.instance()).
-                V().has("name").map(Lambda.function("lambda x: type(x.get())")).toList();
+        final List<Object> o = g.withStrategies(ReadOnlyStrategy.instance(),
+                                                SubgraphStrategy.build().checkAdjacentVertices(false).vertices(hasLabel("person")).create()).
+                                 V().has("name").map(Lambda.function("lambda x: type(x.get())")).toList();
 
-        assertEquals(6, o.size());
+        assertEquals(4, o.size());
     }
 }


[4/8] tinkerpop git commit: TINKERPOP-1896 Fixed bug in lambda processing for python

Posted by sp...@apache.org.
TINKERPOP-1896 Fixed bug in lambda processing for python

When a lambda is in a traversal, the bytecode gets pushed to a scriptengine for evaluation. For python that means, using the JythonTranslator. Prior to this change the JythonTranslator largely relied on the PythonTranslator to convert bytecode to Jython-syntaxed Gremlin. The problem there is that in the JythonScriptEngine, the Traversal bindings are Java objects and so if translated to pure Python syntax, traversal steps like as() become as_() and thus not part of the Java API that is expected - and then errors. Not sure why this didn't come up sooner, but it really only ends up being an issue if you are using bytecode, use gremlin server, use jython in gremlin server and then submit a traversal with a lambda - so perhaps that hasn't been a common combination.


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

Branch: refs/heads/master
Commit: 5feadbddba308a6999649dffb193cf7d31b4645c
Parents: f80a542
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Mar 8 17:15:34 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Mar 12 11:56:16 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../jsr223/GremlinJythonScriptEngine.java       |  7 +--
 .../gremlin/python/jsr223/JythonTranslator.java |  9 ++++
 .../gremlin/python/jsr223/PythonTranslator.java | 19 +++++---
 .../python/jsr223/JythonTranslatorTest.java     | 47 +++++++++-----------
 5 files changed, 44 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5feadbdd/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 66fbbb2..a761003 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -30,6 +30,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Fixed deserialization of `P.not()` for GraphSON.
 * Bumped to Jackson 2.9.4.
 * Added `idleConnectionTimeout` and `keepAliveInterval` to Gremlin Server that enables a "ping" and auto-close for seemingly dead clients.
+* Fixed a bug where lambdas in `gremlin-python` would trigger a failure if steps using python-only symbols were present (such as `as_()`).
 * Fixed a bug in `NumberHelper` that led to wrong min/max results if numbers exceeded the Integer limits.
 * Delayed setting of the request identifier until `RequestMessage` construction by the builder.
 * Improved error messaging for failed serialization and deserialization of request/response messages.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5feadbdd/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java
index 10f4790..a28a58f 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java
@@ -41,11 +41,11 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class GremlinJythonScriptEngine implements GremlinScriptEngine {
 
@@ -123,10 +123,7 @@ public class GremlinJythonScriptEngine implements GremlinScriptEngine {
         // extract the named traversalsource prior to that happening so that bytecode bindings can share the same
         // namespace as global bindings (e.g. traversalsources and graphs).
         if (traversalSource.equals(HIDDEN_G))
-            throw new IllegalArgumentException("The traversalSource cannot have the name " + HIDDEN_G+ " - it is reserved");
-
-        if (bindings.containsKey(HIDDEN_G))
-            throw new IllegalArgumentException("Bindings cannot include " + HIDDEN_G + " - it is reserved");
+            throw new IllegalArgumentException("The traversalSource cannot have the name " + HIDDEN_G + " - it is reserved");
 
         if (!bindings.containsKey(traversalSource))
             throw new IllegalArgumentException("The bindings available to the ScriptEngine do not contain a traversalSource named: " + traversalSource);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5feadbdd/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
index 0eb8961..f8a5bc3 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslator.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.util.function.Lambda;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public final class JythonTranslator extends PythonTranslator {
 
@@ -54,4 +55,12 @@ public final class JythonTranslator extends PythonTranslator {
         else
             return "JythonUnknownArgLambda(" + lambdaString + ")";
     }
+
+    @Override
+    protected String resolveSymbol(final String methodName) {
+        // since this is Jython we should expect the Gremlin to conform to the java classes to which the engine is
+        // bound - therefore, unlike the python engine which converts java names to python friendly ones, this
+        // jython one can just pass them through.
+        return methodName;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5feadbdd/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
index 4af4578..7c74b85 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
@@ -56,6 +56,7 @@ import java.util.stream.Stream;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class PythonTranslator implements Translator.ScriptTranslator {
 
@@ -114,7 +115,7 @@ public class PythonTranslator implements Translator.ScriptTranslator {
                     instruction.getArguments()[0].toString().contains("TranslationStrategy"))
                 continue;
             else if (0 == arguments.length)
-                traversalScript.append(".").append(SymbolHelper.toPython(methodName)).append("()");
+                traversalScript.append(".").append(resolveSymbol(methodName)).append("()");
             else if (methodName.equals("range") && 2 == arguments.length)
                 traversalScript.append("[").append(arguments[0]).append(":").append(arguments[1]).append("]");
             else if (methodName.equals("limit") && 1 == arguments.length)
@@ -123,7 +124,7 @@ public class PythonTranslator implements Translator.ScriptTranslator {
                 traversalScript.append(".").append(arguments[0]);
             else {
                 traversalScript.append(".");
-                String temp = SymbolHelper.toPython(methodName) + "(";
+                String temp = resolveSymbol(methodName) + "(";
                 for (final Object object : arguments) {
                     temp = temp + convertToString(object) + ",";
                 }
@@ -131,7 +132,7 @@ public class PythonTranslator implements Translator.ScriptTranslator {
             }
             // clip off __.
             if (this.importStatics && traversalScript.substring(0, 3).startsWith("__.")
-                    && !NO_STATIC.stream().filter(name -> traversalScript.substring(3).startsWith(SymbolHelper.toPython(name))).findAny().isPresent()) {
+                    && !NO_STATIC.stream().filter(name -> traversalScript.substring(3).startsWith(resolveSymbol(name))).findAny().isPresent()) {
                 traversalScript.delete(0, 3);
             }
         }
@@ -183,13 +184,13 @@ public class PythonTranslator implements Translator.ScriptTranslator {
         else if (object instanceof Class)
             return ((Class) object).getCanonicalName();
         else if (object instanceof VertexProperty.Cardinality)
-            return "Cardinality." + SymbolHelper.toPython(object.toString());
+            return "Cardinality." + resolveSymbol(object.toString());
         else if (object instanceof SackFunctions.Barrier)
-            return "Barrier." + SymbolHelper.toPython(object.toString());
+            return "Barrier." + resolveSymbol(object.toString());
         else if (object instanceof TraversalOptionParent.Pick)
-            return "Pick." + SymbolHelper.toPython(object.toString());
+            return "Pick." + resolveSymbol(object.toString());
         else if (object instanceof Enum)
-            return convertStatic(((Enum) object).getDeclaringClass().getSimpleName() + ".") + SymbolHelper.toPython(object.toString());
+            return convertStatic(((Enum) object).getDeclaringClass().getSimpleName() + ".") + resolveSymbol(object.toString());
         else if (object instanceof P)
             return convertPToString((P) object, new StringBuilder()).toString();
         else if (object instanceof Element) {
@@ -237,4 +238,8 @@ public class PythonTranslator implements Translator.ScriptTranslator {
         return lambdaString.startsWith("lambda") ? lambdaString : "lambda " + lambdaString;
     }
 
+    protected String resolveSymbol(final String methodName) {
+        return SymbolHelper.toPython(methodName);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5feadbdd/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
index 5165120..86e3b78 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
@@ -22,11 +22,11 @@ package org.apache.tinkerpop.gremlin.python.jsr223;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 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.process.traversal.strategy.decoration.TranslationStrategy;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
 import org.apache.tinkerpop.gremlin.util.function.Lambda;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import java.util.ArrayList;
@@ -37,39 +37,15 @@ import static org.junit.Assert.assertFalse;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
  */
-@Ignore
 public class JythonTranslatorTest {
 
-    /*@Test
-    public void shouldHandleStrategies() throws Exception {
-        GraphTraversalSource g = TinkerFactory.createModern().traversal();
-        g = g.withStrategies(new HashMap<String, Object>() {{
-            put(SubgraphStrategy.STRATEGY, SubgraphStrategy.class.getCanonicalName());
-            put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
-        }});
-        final Bindings bindings = new SimpleBindings();
-        bindings.put("g", g);
-        //System.out.println(JythonTranslator.of("g").translate(g.V().values("name").asAdmin().getBytecode()));
-        Traversal.Admin<Vertex, String> traversal = ((GremlinScriptEngine) ScriptEngineCache.get("gremlin-jython")).eval(g.V().values("name").asAdmin().getBytecode(), bindings);
-        assertEquals("marko", traversal.next());
-        assertFalse(traversal.hasNext());
-        //
-        g = g.withStrategies(new HashMap<String, Object>() {{
-            put(SubgraphStrategy.STRATEGY, SubgraphStrategy.class.getCanonicalName());
-            put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
-        }}, Collections.singletonMap(ReadOnlyStrategy.STRATEGY, ReadOnlyStrategy.class.getCanonicalName()));
-        //System.out.println(JythonTranslator.of("g").translate(g.V().values("name").asAdmin().getBytecode()));
-        traversal = ((GremlinScriptEngine) ScriptEngineCache.get("gremlin-jython")).eval(g.V().values("name").asAdmin().getBytecode(), bindings);
-        assertEquals("marko", traversal.next());
-        assertFalse(traversal.hasNext());
-    }*/
-
     @Test
     public void shouldSupportStringSupplierLambdas() throws Exception {
         GraphTraversalSource g = TinkerFactory.createModern().traversal();
         g = g.withStrategies(new TranslationStrategy(g, JythonTranslator.of("g")));
-        GraphTraversal.Admin<Vertex, Integer> t = g.withSideEffect("lengthSum", 0).withSack(1)
+        final GraphTraversal.Admin<Vertex, Integer> t = g.withSideEffect("lengthSum", 0).withSack(1)
                 .V()
                 .filter(Lambda.predicate("x : x.get().label() == 'person'"))
                 .flatMap(Lambda.function("lambda x : x.get().vertices(Direction.OUT)"))
@@ -110,4 +86,21 @@ public class JythonTranslatorTest {
     public void shouldHaveValidToString() {
         assertEquals("translator[h:gremlin-jython]", JythonTranslator.of("h").toString());
     }
+
+    @Test
+    public void shouldTranslateToJythonAndNotPython() throws Exception {
+        // the jython translation bind "g" to java classes and thus does not require the strict python syntax which
+        // converts steps like as() to as_(). if those steps are converted then the traversal does not evaluate
+        // properly in the python engine. not much of an assertion here to worry about - just need to ensure that
+        // the traversal with such steps evaluates to success
+        GraphTraversalSource g = TinkerFactory.createModern().traversal();
+        g = g.withStrategies(new TranslationStrategy(g, JythonTranslator.of("g")));
+        final List<Object> o = g.V().has("name").
+                match(__.as("x").label().as("lbl"),
+                        __.as("x").id().as("id")).
+                select("lbl", "id").
+                                 map(Lambda.function("lambda x: type(x.get())")).toList();
+
+        assertEquals(6, o.size());
+    }
 }