You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/08/23 18:00:44 UTC

tinkerpop git commit: Python's graphson.py now uses GraphSON 2.0 representation for Bytecode. All test cases pass save those that use Operator (still trying to undertsand why that breaks).

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 7b8bcdb12 -> 8e04a6529


Python's graphson.py now uses GraphSON 2.0 representation for Bytecode. All test cases pass save those that use Operator (still trying to undertsand why that breaks).


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

Branch: refs/heads/TINKERPOP-1278
Commit: 8e04a652943ef770fc0f05a7cda31ad59b68480c
Parents: 7b8bcdb
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Aug 23 12:00:41 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Aug 23 12:00:41 2016 -0600

----------------------------------------------------------------------
 .../jython/gremlin_python/process/graphson.py   | 28 ++++++++++----------
 .../jsr223/PythonGraphSONJavaTranslator.java    |  5 +++-
 2 files changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e04a652/gremlin-python/src/main/jython/gremlin_python/process/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graphson.py b/gremlin-python/src/main/jython/gremlin_python/process/graphson.py
index 2b5ff5c..7949ca9 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/graphson.py
@@ -28,13 +28,6 @@ from .traversal import P
 from .traversal import Traversal
 from .. import statics
 
-'''
-Symbol Table
-'''
-
-_TYPE = "@type"
-_VALUE = "@value"
-
 class GraphSONWriter(object):
     @staticmethod
     def _dictify(object):
@@ -80,14 +73,14 @@ class BytecodeSerializer(GraphSONSerializer):
             dict["source"] = sources
         if len(steps) > 0:
             dict["step"] = steps
-        return {_TYPE: "bytecode", _VALUE: dict}
+        return {_SymbolHelper._TYPE: _SymbolHelper.prefix("bytecode"), _SymbolHelper._VALUE: dict}
 
 
 class EnumSerializer(GraphSONSerializer):
     def _dictify(self, enum):
         dict = {}
-        dict[_TYPE] = _SymbolHelper.toGremlin(type(enum).__name__)
-        dict[_VALUE] = _SymbolHelper.toGremlin(str(enum.name))
+        dict[_SymbolHelper._TYPE] = _SymbolHelper.prefix(_SymbolHelper.toGremlin(type(enum).__name__))
+        dict[_SymbolHelper._VALUE] = _SymbolHelper.toGremlin(str(enum.name))
         return dict
 
 
@@ -99,7 +92,7 @@ class PSerializer(GraphSONSerializer):
             dict["value"] = GraphSONWriter._dictify(p.value)
         else:
             dict["value"] = [GraphSONWriter._dictify(p.value), GraphSONWriter._dictify(p.other)]
-        return {_TYPE: "P", _VALUE: dict}
+        return {_SymbolHelper._TYPE: _SymbolHelper.prefix("P"), _SymbolHelper._VALUE: dict}
 
 
 class BindingSerializer(GraphSONSerializer):
@@ -107,7 +100,7 @@ class BindingSerializer(GraphSONSerializer):
         dict = {}
         dict["key"] = binding.variable
         dict["value"] = GraphSONWriter._dictify(binding.value)
-        return {_TYPE: "binding", _VALUE: dict}
+        return {_SymbolHelper._TYPE: _SymbolHelper.prefix("binding"), _SymbolHelper._VALUE: dict}
 
 
 class LambdaSerializer(GraphSONSerializer):
@@ -116,7 +109,7 @@ class LambdaSerializer(GraphSONSerializer):
         dict = {}
         script = lambdaResult if isinstance(lambdaResult, str) else lambdaResult[0]
         language = statics.default_lambda_language if isinstance(lambdaResult, str) else lambdaResult[1]
-        dict["value"] = script
+        dict["script"] = script
         dict["language"] = language
         if language == "gremlin-jython" or language == "gremlin-python":
             if not script.strip().startswith("lambda"):
@@ -125,7 +118,7 @@ class LambdaSerializer(GraphSONSerializer):
             dict["arguments"] = eval(dict["value"]).func_code.co_argcount
         else:
             dict["arguments"] = -1
-        return {_TYPE: "lambda", _VALUE: dict}
+        return {_SymbolHelper._TYPE: _SymbolHelper.prefix("lambda"), _SymbolHelper._VALUE: dict}
 
 
 class TraversalSerializer(BytecodeSerializer):
@@ -137,10 +130,17 @@ class _SymbolHelper(object):
     symbolMap = {"_global": "global", "_as": "as", "_in": "in", "_and": "and",
                  "_or": "or", "_is": "is", "_not": "not", "_from": "from"}
 
+    _TYPE = "@type"
+    _VALUE = "@value"
+
     @staticmethod
     def toGremlin(symbol):
         return _SymbolHelper.symbolMap[symbol] if symbol in _SymbolHelper.symbolMap else symbol
 
+    @staticmethod
+    def prefix(type, prefix="gremlin"):
+        return prefix + ":" + type
+
 
 serializers = {
     Bytecode: BytecodeSerializer(),

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e04a652/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
index 9f46bea..7dd8a23 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
@@ -24,7 +24,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
 import org.apache.tinkerpop.gremlin.process.traversal.Translator;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
 import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
 
 import javax.script.Bindings;
@@ -39,7 +41,7 @@ final class PythonGraphSONJavaTranslator<S extends TraversalSource, T extends Tr
 
     private final PythonTranslator pythonTranslator;
     private final JavaTranslator<S, T> javaTranslator;
-    private final GraphSONReader reader = GraphSONReader.build().create();
+    private final GraphSONReader reader = GraphSONReader.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).create()).create();
 
     public PythonGraphSONJavaTranslator(final PythonTranslator pythonTranslator, final JavaTranslator<S, T> javaTranslator) {
         this.pythonTranslator = pythonTranslator;
@@ -65,6 +67,7 @@ final class PythonGraphSONJavaTranslator<S extends TraversalSource, T extends Tr
             bindings.put(this.pythonTranslator.getTraversalSource(), jythonEngine.eval("Graph().traversal()"));
             bindings.putAll(bytecode.getBindings());
             final String graphsonBytecode = jythonEngine.eval("GraphSONWriter.writeObject(" + this.pythonTranslator.translate(bytecode) + ")", bindings).toString();
+            // System.out.println(graphsonBytecode);
             return this.javaTranslator.translate(this.reader.readObject(new ByteArrayInputStream(graphsonBytecode.getBytes()), Bytecode.class));
         } catch (final Exception e) {
             throw new IllegalArgumentException(e.getMessage(), e);