tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject tinkerpop git commit: Updated init-code-blocks.awk to use a derserialization of the JSON of Jython so you get the exact look and feel of the objects. Fixed a bug in P deserialization .. Added more Python GraphSON deseraialization tests.
Date Wed, 24 Aug 2016 18:41:16 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 275ba621e -> 58704a7c5


Updated init-code-blocks.awk to use a derserialization of the JSON of Jython so you get the
exact look and feel of the objects. Fixed a bug in P deserialization .. Added more Python
GraphSON deseraialization tests.


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

Branch: refs/heads/TINKERPOP-1278
Commit: 58704a7c5a6d334c2397176787fdc9e514502940
Parents: 275ba62
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Wed Aug 24 12:41:00 2016 -0600
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Wed Aug 24 12:41:11 2016 -0600

----------------------------------------------------------------------
 docs/preprocessor/awk/init-code-blocks.awk      | 12 ++++++---
 docs/src/reference/gremlin-variants.asciidoc    | 14 ++++++++++-
 .../GraphSONTraversalSerializersV2d0.java       | 26 +++++++++++---------
 .../io/graphson/GraphSONWriterTest.java         | 25 ++++++++++++++++---
 4 files changed, 56 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/58704a7c/docs/preprocessor/awk/init-code-blocks.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/init-code-blocks.awk b/docs/preprocessor/awk/init-code-blocks.awk
index e37af2e..2b66eaf 100644
--- a/docs/preprocessor/awk/init-code-blocks.awk
+++ b/docs/preprocessor/awk/init-code-blocks.awk
@@ -61,8 +61,9 @@ BEGIN {
     print "jython.eval('from gremlin_python import statics')"
     print "jython.eval('from gremlin_python.process.traversal import *')"
     print "jython.eval('from gremlin_python.structure.graph import Graph')"
-    print "jython.eval('from gremlin_python.process.graphson import GraphSONWriter')"
-    # print "jython.eval('from gremlin_python.process.graphson import serializers')"
+    print "jython.eval('from gremlin_python.structure.io.graphson import GraphSONWriter')"
+    print "jython.eval('from gremlin_python.structure.io.graphson import GraphSONReader')"
+    # print "jython.eval('from gremlin_python.structure.io.graphson import serializers')"
     # print "jython.eval('from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection')"
     print "jython.eval('statics.load_statics(globals())')"
     print "jythonBindings = jython.createBindings()"
@@ -77,9 +78,12 @@ BEGIN {
     print "def processTraversal(t, jython, groovy) {"
     print "  jython.getContext().getBindings(GLOBAL_SCOPE).put('j', jython.eval(t.replace('.toList()','')))"
     print "  if(jython.eval('isinstance(j, Traversal)')) {"
-    print "    bytecode = GraphSONReader.build().create().mapper.readValue(jython.eval('GraphSONWriter.writeObject(j)').toString(),
Bytecode.class)"
+    print "    mapper = GraphSONMapper.build().version(GraphSONVersion.V2_0).create().createMapper()"
+    print "    bytecode = mapper.readValue(jython.eval('GraphSONWriter.writeObject(j)').toString(),
Bytecode.class)"
     print "    language = BytecodeHelper.getLambdaLanguage(bytecode).orElse('gremlin-groovy')"
-    print "    return language.equals('gremlin-groovy') ? groovy.eval(GroovyTranslator.of(\"g\").translate(bytecode)
+ '.toList()').toString() : jython.eval(JythonTranslator.of(\"h\").translate(bytecode) + '.toList()').toString()"
+    print "    result = language.equals('gremlin-groovy') ? groovy.eval(GroovyTranslator.of(\"g\").translate(bytecode)
+ '.toList()').toString() : jython.eval(JythonTranslator.of(\"h\").translate(bytecode) + '.toList()').toString()"
+    print "    jython.getContext().getBindings(GLOBAL_SCOPE).put('json', mapper.writeValueAsString(result))"
+    print "    return jython.eval('GraphSONReader.readObject(json)').toString()"
     print "  } else {"
     print "    j = jython.getContext().getBindings(GLOBAL_SCOPE).get('j')"
     print "    return null == j ? 'null' : j.toString()"

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/58704a7c/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 1ed663f..ab4910a 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -54,7 +54,7 @@ prefixes `_` in front of these terms for their use with graph traversal.
For ins
 To install Gremlin-Python, use Python's link:https://en.wikipedia.org/wiki/Pip_(package_manager)[pip]
package manager.
 
 [source,bash]
-pip install gremlin_python
+pip install gremlinpython
 
 Gremlin-Python users will typically make use of the following classes.
 
@@ -134,6 +134,18 @@ Likewise, if it has lambdas represented in Python, it will use Gremlin-Python
(e
 IMPORTANT: Gremlin-Python's `Traversal` class supports the standard Gremlin methods such
as `next()`, `nextTraverser()`,
 `toSet()`, `toList()`, etc. Such "terminal" methods trigger the evaluation of the traversal.
 
+RemoteConnection Submission
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+There are various ways to submit a traversal to a `RemoteConnection`. Just as in Gremlin-Java,
there are various
+"action methods" off of `Traversal`.
+
+* `Traversal.next()`
+* `Traversal.nextTraverser()`
+* `Traversal.toList()`
+* `Traversal.toSet()`
+* `Traversal.iterate()`
+
 Gremlin-Python Sugar
 ~~~~~~~~~~~~~~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/58704a7c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
index d5c8de0..ff3a69d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
@@ -39,12 +39,10 @@ import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdScalarSerializer;
 import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
 
 import java.io.IOException;
-import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -281,16 +279,20 @@ final class GraphSONTraversalSerializersV2d0 {
             } else {
                 try {
                     if (value instanceof Collection) {
-                        final Optional<Method> method = Arrays.stream(P.class.getMethods()).filter(m
-> m.getName().equals(predicate)).findAny();
-                        if (method.isPresent()) {
-                            if (!Collection.class.isAssignableFrom(method.get().getParameterTypes()[0]))
-                                return (P) method.get().invoke(null, ((Collection) value).toArray());
-                            else
-                                return (P) method.get().invoke(null, value);
-                        } else
-                            throw new IllegalStateException("No such P method: " + predicate);
-                    }
-                    return (P) P.class.getMethod(predicate, Object.class).invoke(null, value);
+                        if (predicate.equals("between"))
+                            return P.between(((List) value).get(0), ((List) value).get(1));
+                        else if (predicate.equals("inside"))
+                            return P.between(((List) value).get(0), ((List) value).get(1));
+                        else if (predicate.equals("outside"))
+                            return P.outside(((List) value).get(0), ((List) value).get(1));
+                        else if (predicate.equals("within"))
+                            return P.within((Collection) value);
+                        else if (predicate.equals("without"))
+                            return P.without((Collection) value);
+                        else
+                            return (P) P.class.getMethod(predicate, Collection.class).invoke(null,
(Collection) value);
+                    } else
+                        return (P) P.class.getMethod(predicate, Object.class).invoke(null,
value);
                 } catch (final Exception e) {
                     throw new IllegalStateException(e.getMessage(), e);
                 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/58704a7c/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
index 51f4c53..1b438b6 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
@@ -20,18 +20,21 @@
 package org.apache.tinkerpop.gremlin.python.structure.io.graphson;
 
 import org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraverser;
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
 import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
 import org.apache.tinkerpop.gremlin.python.jsr223.JythonScriptEngineSetup;
+import org.apache.tinkerpop.gremlin.structure.Column;
+import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
-import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
 import org.apache.tinkerpop.gremlin.util.function.Lambda;
 import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
 import org.junit.Test;
 import org.python.jsr223.PyScriptEngine;
-import org.python.jsr223.PyScriptEngineFactory;
 
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
@@ -84,11 +87,25 @@ public class GraphSONWriterTest {
         assertEquals("hello", mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Traverser('hello',3L))").toString(),
Traverser.class).get());
     }
 
-    /*@Test
+    @Test
     public void shouldSerializeBytecode() throws Exception {
         assertEquals(P.eq(7L), mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(P.eq(7L))").toString(),
Object.class));
         // TODO: assertEquals(mapper.writeValueAsString(P.between(1, 2).and(P.eq(7L))), jythonEngine.eval("GraphSONWriter.writeObject(P.eq(7L)._and(P.between(1,2)))").toString().replace("
",""));
         assertEquals(AndP.class, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(P.eq(7L)._and(P.between(1,2)))").toString(),
Object.class).getClass());
+        //
+        assertEquals(new Bytecode.Binding<>("a", 5L), mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Binding('a',5L))").toString(),
Object.class));
+        //
+        for (final Column t : Column.values()) {
+            assertEquals(t, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Column."
+ t.name() + ")").toString(), Object.class));
+        }
+        for (final T t : T.values()) {
+            assertEquals(t, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(T."
+ t.name() + ")").toString(), Object.class));
+        }
+        for (final Pop t : Pop.values()) {
+            assertEquals(t, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Pop."
+ t.name() + ")").toString(), Object.class));
+        }
+        assertEquals(Scope.global, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Scope._global)").toString(),
Object.class));
+        assertEquals(Scope.local, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Scope.local)").toString(),
Object.class));
     }
 
     @Test
@@ -108,6 +125,6 @@ public class GraphSONWriterTest {
         assertEquals(
                 Lambda.biFunction("lambda z,y : z - y + 2", "gremlin-python"),
                 mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(lambda : 'lambda
z,y : z - y + 2')").toString(), Object.class));
-    }*/
+    }
 
 }


Mime
View raw message