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 2017/07/24 20:27:47 UTC
[1/7] tinkerpop git commit: added AddEdgeTest that leverages
side-effect data to ensure Attachables are respected. Exposed PropertyTests
that were OPT_OUT in RemoteGraph,
but didn't need to be. Added a Python test to verify the specific ticket test
passe
Repository: tinkerpop
Updated Branches:
refs/heads/master 957ed09f1 -> fcd623ce3
added AddEdgeTest that leverages side-effect data to ensure Attachables are respected. Exposed PropertyTests that were OPT_OUT in RemoteGraph, but didn't need to be. Added a Python test to verify the specific ticket test passes (though tested in ProcessTestSuite). The real problem is that Python does not have Serializers for Graph elements. It only has deserializers. I added serializers of the ReferenceXXX form. This way, elements can be passed in as parameters. Added read/write graphson tests in Python to verify serialization/deserialization behavior.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/1f823983
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/1f823983
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/1f823983
Branch: refs/heads/master
Commit: 1f8239834b0c911f7d53d25a37cbee0ef26a66fc
Parents: 3f06a6a
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Jul 20 14:44:02 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Jul 20 14:44:02 2017 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../gremlin/process/remote/RemoteGraph.java | 8 ---
.../traversal/step/map/GroovyAddEdgeTest.groovy | 8 +++
.../gremlin_python/structure/io/graphson.py | 51 +++++++++++++--
.../driver/test_driver_remote_connection.py | 19 +++++-
.../jython/tests/structure/io/test_graphson.py | 69 +++++++++++++-------
.../process/traversal/step/map/AddEdgeTest.java | 25 +++++++
7 files changed, 141 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f823983/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 3a0627d..ab44755 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -28,6 +28,7 @@ TinkerPop 3.2.6 (Release Date: NOT OFFICIALLY RELEASED YET)
This release also includes changes from <<release-3-1-8, 3.1.8>>.
+* Added graph element GraphSON serializers in Gremlin-Python.
* Initialization scripts for Gremlin Server will not timeout.
* Added Gremlin.Net.
* `ProfileTest` is now less stringent about assertions which will reduce burdens on providers.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f823983/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java
index 2bc310a..d69e12e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java
@@ -65,14 +65,6 @@ import java.util.Iterator;
method = "*",
reason = "hmmmm")
@Graph.OptOut(
- test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.ProjectTest",
- method = "g_V_hasLabelXpersonX_projectXa_bX_byXoutE_countX_byXageX",
- reason = "Not happy in OLAP.")
-@Graph.OptOut(
- test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.ProjectTest",
- method = "g_V_outXcreatedX_projectXa_bX_byXnameX_byXinXcreatedX_countX_order_byXselectXbX__decrX_selectXaX",
- reason = "Not happy in OLAP.")
-@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.CoreTraversalTest",
method = "*",
reason = "The test suite does not support profiling or lambdas and for groovy tests: 'Could not locate method: GraphTraversalSource.withStrategies([{traversalCategory=interface org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy$DecorationStrategy}])'")
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f823983/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyAddEdgeTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyAddEdgeTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyAddEdgeTest.groovy
index 13d3e0a..35823a1 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyAddEdgeTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyAddEdgeTest.groovy
@@ -86,5 +86,13 @@ public abstract class GroovyAddEdgeTest {
public Traversal<Vertex, Edge> get_g_addV_asXfirstX_repeatXaddEXnextX_toXaddVX_inVX_timesX5X_addEXnextX_toXselectXfirstXX() {
new ScriptTraversal<>(g, "gremlin-groovy", "g.addV().as('first').repeat(addE('next').to(addV()).inV).times(5).addE('next').to(select('first'))")
}
+
+ @Override
+ public Traversal<Vertex, Edge> get_g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X() {
+ final Vertex a = g.V().has("name", "marko").next();
+ final Vertex b = g.V().has("name", "peter").next();
+ return new ScriptTraversal<>(g, "gremlin-groovy", "g.withSideEffect('b', b).V(a).addE('knows').to('b').property('weight', 0.5d)", "a", a, "b", b)
+ }
+
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f823983/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index 8102ee8..0daeffa 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -26,7 +26,6 @@ from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, T
from gremlin_python.process.traversal import Binding, Bytecode, P, Traversal, Traverser, TraversalStrategy
from gremlin_python.structure.graph import Edge, Property, Vertex, VertexProperty, Path
-
# When we fall back to a superclass's serializer, we iterate over this map.
# We want that iteration order to be consistent, so we use an OrderedDict,
# not a dict.
@@ -60,9 +59,9 @@ class GraphSONUtil(object):
def formatType(cls, prefix, type_name):
return "%s:%s" % (prefix, type_name)
+
# Read/Write classes split to follow precedence of the Java API
class GraphSONWriter(object):
-
def __init__(self, serializer_map=None):
"""
:param serializer_map: map from Python type to serializer instance implementing `dictify`
@@ -96,7 +95,6 @@ class GraphSONWriter(object):
class GraphSONReader(object):
-
def __init__(self, deserializer_map=None):
"""
:param deserializer_map: map from GraphSON type tag to deserializer instance implementing `objectify`
@@ -147,7 +145,6 @@ class _GraphSONTypeIO(object):
class _BytecodeSerializer(_GraphSONTypeIO):
-
@classmethod
def _dictify_instructions(cls, instructions, writer):
out = []
@@ -169,6 +166,49 @@ class _BytecodeSerializer(_GraphSONTypeIO):
return GraphSONUtil.typedValue("Bytecode", out)
+class VertexSerializer(_GraphSONTypeIO):
+ python_type = Vertex
+
+ @classmethod
+ def dictify(cls, vertex, writer):
+ v = {"id": writer.toDict(vertex.id),
+ "label": vertex.label}
+ return GraphSONUtil.typedValue("Vertex", v)
+
+
+class EdgeSerializer(_GraphSONTypeIO):
+ python_type = Edge
+
+ @classmethod
+ def dictify(cls, edge, writer):
+ e = {"id": edge.id,
+ "label": edge.label,
+ "inV": writer.toDict(edge.inV.id),
+ "outV": writer.toDict(edge.outV.id)}
+ return GraphSONUtil.typedValue("Edge", e)
+
+
+class VertexPropertySerializer(_GraphSONTypeIO):
+ python_type = VertexProperty
+
+ @classmethod
+ def dictify(cls, vertex_property, writer):
+ vp = {"id": vertex_property.id,
+ "label": vertex_property.label,
+ "value": writer.toDict(vertex_property.value)}
+ return GraphSONUtil.typedValue("VertexProperty", vp)
+
+
+class PropertySerializer(_GraphSONTypeIO):
+ python_type = Property
+
+ @classmethod
+ def dictify(cls, property, writer):
+ p = {"key": writer.toDict(property.key),
+ "value": writer.toDict(property.value)}
+ return GraphSONUtil.typedValue("Property", p)
+
+
class TraversalSerializer(_BytecodeSerializer):
python_type = Traversal
@@ -216,7 +256,7 @@ class PSerializer(_GraphSONTypeIO):
def dictify(cls, p, writer):
out = {"predicate": p.operator,
"value": [writer.toDict(p.value), writer.toDict(p.other)] if p.other is not None else
- writer.toDict(p.value)}
+ writer.toDict(p.value)}
return GraphSONUtil.typedValue("P", out)
@@ -259,7 +299,6 @@ class TypeSerializer(_GraphSONTypeIO):
class _NumberIO(_GraphSONTypeIO):
-
@classmethod
def dictify(cls, n, writer):
if isinstance(n, bool): # because isinstance(False, int) and isinstance(True, int)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f823983/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
index 71cebf0..9bbccfb 100644
--- a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
@@ -59,7 +59,8 @@ class TestDriverRemoteConnection(object):
assert 4 == g.V()[2:].count().next()
assert 2 == g.V()[:2].count().next()
# #
- results = g.withSideEffect('a',['josh','peter']).V(1).out('created').in_('created').values('name').where(within('a')).toList()
+ results = g.withSideEffect('a', ['josh', 'peter']).V(1).out('created').in_('created').values('name').where(
+ within('a')).toList()
assert 2 == len(results)
assert 'josh' in results
assert 'peter' in results
@@ -153,6 +154,20 @@ class TestDriverRemoteConnection(object):
with pytest.raises(Exception):
x = t.side_effects["x"]
+ a = g.V().has("name", "marko").next()
+ b = g.V().has("name", "peter").next()
+ edge = g.withSideEffect("b", b).V(a).addE("knows").to("b").next()
+ assert "knows" == edge.label
+ assert a == edge.outV
+ assert b == edge.inV
+ g.V().has("name","marko").outE("knows").where(__.inV().has("name","peter")).drop().iterate()
+ ##
+ edge = g.withSideEffect("a", a).withSideEffect("b", b).V().limit(1).addE("knows").from_("a").to("b").next()
+ assert "knows" == edge.label
+ assert a == edge.outV
+ assert b == edge.inV
+ g.V().has("name","marko").outE("knows").where(__.inV().has("name","peter")).drop().iterate()
+
def test_side_effect_close(self, remote_connection):
g = Graph().traversal().withRemote(remote_connection)
t = g.V().aggregate('a').aggregate('b')
@@ -191,7 +206,7 @@ class TestDriverRemoteConnection(object):
t = future.result()
assert len(t.toList()) == 6
a, = t.side_effects.keys()
- assert a == 'a'
+ assert a == 'a'
results = t.side_effects.get('a')
assert results
results = t.side_effects.close()
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f823983/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
index 07381bf..d80d045 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
@@ -25,7 +25,7 @@ from mock import Mock
import six
from gremlin_python.statics import *
-from gremlin_python.structure.graph import Vertex
+from gremlin_python.structure.graph import Vertex, Edge, VertexProperty, Property
from gremlin_python.structure.graph import Path
from gremlin_python.structure.io.graphson import GraphSONWriter, GraphSONReader, GraphSONUtil
import gremlin_python.structure.io.graphson
@@ -123,13 +123,13 @@ class TestGraphSONReader(object):
class TestGraphSONWriter(object):
-
graphson_writer = GraphSONWriter()
+ graphson_reader = GraphSONReader()
def test_number_output(self):
- assert {"@type":"g:Int64","@value":2} == json.loads(self.graphson_writer.writeObject(long(2)))
- assert {"@type":"g:Int32","@value":1} == json.loads(self.graphson_writer.writeObject(1))
- assert {"@type":"g:Double","@value":3.2} == json.loads(self.graphson_writer.writeObject(3.2))
+ assert {"@type": "g:Int64", "@value": 2} == json.loads(self.graphson_writer.writeObject(long(2)))
+ assert {"@type": "g:Int32", "@value": 1} == json.loads(self.graphson_writer.writeObject(1))
+ assert {"@type": "g:Double", "@value": 3.2} == json.loads(self.graphson_writer.writeObject(3.2))
assert """true""" == self.graphson_writer.writeObject(True)
def test_numbers(self):
@@ -141,33 +141,33 @@ class TestGraphSONWriter(object):
def test_P(self):
result = {'@type': 'g:P',
'@value': {
- 'predicate': 'and',
- 'value': [{
- '@type': 'g:P',
- '@value': {
- 'predicate': 'or',
- 'value': [{
- '@type': 'g:P',
- '@value': {'predicate': 'lt', 'value': 'b'}
- },
- {'@type': 'g:P', '@value': {'predicate': 'gt', 'value': 'c'}}
- ]
- }
- },
- {'@type': 'g:P', '@value': {'predicate': 'neq', 'value': 'd'}}]}}
-
- assert result == json.loads(
+ 'predicate': 'and',
+ 'value': [{
+ '@type': 'g:P',
+ '@value': {
+ 'predicate': 'or',
+ 'value': [{
+ '@type': 'g:P',
+ '@value': {'predicate': 'lt', 'value': 'b'}
+ },
+ {'@type': 'g:P', '@value': {'predicate': 'gt', 'value': 'c'}}
+ ]
+ }
+ },
+ {'@type': 'g:P', '@value': {'predicate': 'neq', 'value': 'd'}}]}}
+
+ assert result == json.loads(
self.graphson_writer.writeObject(P.lt("b").or_(P.gt("c")).and_(P.neq("d"))))
def test_strategies(self):
# we have a proxy model for now given that we don't want to have to have g:XXX all registered on the Gremlin traversal machine (yet)
- assert {"@type": "g:SubgraphStrategy", "@value": {}} == json.loads(self.graphson_writer.writeObject(SubgraphStrategy))
+ assert {"@type": "g:SubgraphStrategy", "@value": {}} == json.loads(
+ self.graphson_writer.writeObject(SubgraphStrategy))
assert {"@type": "g:SubgraphStrategy", "@value": {
"vertices": {"@type": "g:Bytecode", "@value": {"step": [["has", "name", "marko"]]}}}} == json.loads(
self.graphson_writer.writeObject(SubgraphStrategy(vertices=__.has("name", "marko"))))
def test_custom_mapping(self):
-
# extended mapping
class X(object):
pass
@@ -195,7 +195,6 @@ class TestGraphSONWriter(object):
assert d is serdes.dictify()
def test_write_long(self):
-
mapping = self.graphson_writer.toDict(1)
assert mapping['@type'] == 'g:Int32'
assert mapping['@value'] == 1
@@ -203,3 +202,25 @@ class TestGraphSONWriter(object):
mapping = self.graphson_writer.toDict(long(1))
assert mapping['@type'] == 'g:Int64'
assert mapping['@value'] == 1
+
+ def test_graph(self):
+ vertex = self.graphson_reader.readObject(self.graphson_writer.writeObject(Vertex(1, "person")))
+ assert 1 == vertex.id
+ assert "person" == vertex.label
+
+ edge = self.graphson_reader.readObject(
+ self.graphson_writer.writeObject(Edge(3, Vertex(1, "person"), "knows", Vertex(2, "dog"))))
+ assert "knows" == edge.label
+ assert 3 == edge.id
+ assert 1 == edge.outV.id
+ assert 2 == edge.inV.id
+
+ vertex_property = self.graphson_reader.readObject(
+ self.graphson_writer.writeObject(VertexProperty(1, "age", 32)))
+ assert 1 == vertex_property.id
+ assert "age" == vertex_property.key
+ assert 32 == vertex_property.value
+
+ property = self.graphson_reader.readObject(self.graphson_writer.writeObject(Property("age", 32.2)))
+ assert "age" == property.key
+ assert 32.2 == property.value
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f823983/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
index d418944..b45dfbb 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
@@ -63,6 +63,8 @@ public abstract class AddEdgeTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Edge> get_g_addV_asXfirstX_repeatXaddEXnextX_toXaddVX_inVX_timesX5X_addEXnextX_toXselectXfirstXX();
+ public abstract Traversal<Vertex, Edge> get_g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X();
+
///////
@Deprecated
@@ -262,6 +264,22 @@ public abstract class AddEdgeTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
+ @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+ public void g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X() {
+ final Traversal<Vertex, Edge> traversal = get_g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X();
+ final Edge edge = traversal.next();
+ assertFalse(traversal.hasNext());
+ assertEquals(edge.outVertex(), convertToVertex(graph, "marko"));
+ assertEquals(edge.inVertex(), convertToVertex(graph, "peter"));
+ assertEquals("knows", edge.label());
+ assertEquals(1, IteratorUtils.count(edge.properties()));
+ assertEquals(0.5d, edge.value("weight"), 0.1d);
+ assertEquals(6, IteratorUtils.count(graph.vertices()));
+ assertEquals(7, IteratorUtils.count(graph.edges()));
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
@Deprecated
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
public void g_V_asXaX_inXcreatedX_addInEXcreatedBy_a_year_2009_acl_publicX() {
@@ -354,6 +372,13 @@ public abstract class AddEdgeTest extends AbstractGremlinProcessTest {
return g.V().as("a").in("created").addE("createdBy").from("a").property("year", 2009).property("acl", "public");
}
+ @Override
+ public Traversal<Vertex, Edge> get_g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X() {
+ final Vertex a = g.V().has("name", "marko").next();
+ final Vertex b = g.V().has("name", "peter").next();
+ return g.withSideEffect("b", b).V(a).addE("knows").to("b").property("weight", 0.5d);
+ }
+
///////
@Override
[2/7] tinkerpop git commit: added an auto-attachment feature to
AddEdgeStep. Forgot to commit this in the last push.
Posted by ok...@apache.org.
added an auto-attachment feature to AddEdgeStep. Forgot to commit this in the last push.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/bc6eccba
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/bc6eccba
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/bc6eccba
Branch: refs/heads/master
Commit: bc6eccba78a34a431bd21dc256538f23c8a78c2f
Parents: 1f82398
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Jul 20 15:15:19 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Jul 20 15:15:19 2017 -0600
----------------------------------------------------------------------
.../process/traversal/step/map/AddEdgeStep.java | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bc6eccba/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
index 03a2fa7..c64f455 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
@@ -34,11 +34,10 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -81,19 +80,26 @@ public final class AddEdgeStep<S> extends MapStep<S, Edge>
}
@Override
- public void addTo(final Traversal.Admin<?,?> toObject) {
+ public void addTo(final Traversal.Admin<?, ?> toObject) {
this.parameters.set(this, TO, toObject);
}
@Override
- public void addFrom(final Traversal.Admin<?,?> fromObject) {
+ public void addFrom(final Traversal.Admin<?, ?> fromObject) {
this.parameters.set(this, FROM, fromObject);
}
@Override
protected Edge map(final Traverser.Admin<S> traverser) {
- final Vertex toVertex = this.parameters.get(traverser, TO, () -> (Vertex) traverser.get()).get(0);
- final Vertex fromVertex = this.parameters.get(traverser, FROM, () -> (Vertex) traverser.get()).get(0);
+ Vertex toVertex = this.parameters.get(traverser, TO, () -> (Vertex) traverser.get()).get(0);
+ Vertex fromVertex = this.parameters.get(traverser, FROM, () -> (Vertex) traverser.get()).get(0);
+ if (this.getTraversal().getGraph().isPresent()) {
+ final Graph graph = this.getTraversal().getGraph().get();
+ if (toVertex instanceof Attachable)
+ toVertex = ((Attachable<Vertex>) toVertex).attach(Attachable.Method.get(graph));
+ if (fromVertex instanceof Attachable)
+ fromVertex = ((Attachable<Vertex>) fromVertex).attach(Attachable.Method.get(graph));
+ }
final String edgeLabel = this.parameters.get(traverser, T.label, () -> Edge.DEFAULT_LABEL).get(0);
final Edge edge = fromVertex.addEdge(edgeLabel, toVertex, this.parameters.getKeyValues(traverser, TO, FROM, T.label));
[5/7] tinkerpop git commit: dah.....I'm a tard.
Posted by ok...@apache.org.
dah.....I'm a tard.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2e11e99c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2e11e99c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2e11e99c
Branch: refs/heads/master
Commit: 2e11e99c441f64048f125dbd2aa7d626667b9531
Parents: 894e0e8
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Jul 20 17:10:34 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Jul 20 17:10:34 2017 -0600
----------------------------------------------------------------------
.../tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2e11e99c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
index 5a083cb..efe5906 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
@@ -95,7 +95,7 @@ public final class AddEdgeStep<S> extends MapStep<S, Edge>
Vertex toVertex = this.parameters.get(traverser, TO, () -> (Vertex) traverser.get()).get(0);
Vertex fromVertex = this.parameters.get(traverser, FROM, () -> (Vertex) traverser.get()).get(0);
if (toVertex instanceof Attachable)
- toVertex = ((Attachable<Vertex>) fromVertex)
+ toVertex = ((Attachable<Vertex>) toVertex)
.attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
if (fromVertex instanceof Attachable)
fromVertex = ((Attachable<Vertex>) fromVertex)
[7/7] tinkerpop git commit: had to organize the tp32 changes to work
with how we re-org'd Gremlin-Python in 3.3.0. A little painful, but got it.
Posted by ok...@apache.org.
had to organize the tp32 changes to work with how we re-org'd Gremlin-Python in 3.3.0. A little painful, but got it.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/fcd623ce
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fcd623ce
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fcd623ce
Branch: refs/heads/master
Commit: fcd623ce3f725245e9a77ca5ed09173b706a88f7
Parents: 957ed09 9a33651
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Jul 24 14:27:42 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Jul 24 14:27:42 2017 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 2 +
.../gremlin/process/remote/RemoteGraph.java | 8 ---
.../process/traversal/step/map/AddEdgeStep.java | 18 ++++--
.../gremlin_python/structure/io/graphsonV2d0.py | 1 -
.../driver/test_driver_remote_connection.py | 19 ++++++-
.../tests/structure/io/test_graphsonV2d0.py | 59 +++++++++++++-------
.../tests/structure/io/test_graphsonV3d0.py | 22 ++++++++
.../process/traversal/step/map/AddEdgeTest.java | 27 +++++++++
8 files changed, 120 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fcd623ce/CHANGELOG.asciidoc
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fcd623ce/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fcd623ce/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py
----------------------------------------------------------------------
diff --cc gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py
index 395bdef,0000000..eedc4bc
mode 100644,000000..100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py
@@@ -1,404 -1,0 +1,403 @@@
+'''
+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.
+'''
+from aenum import Enum
+import json
+import six
+from collections import OrderedDict
+
+from gremlin_python import statics
+from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, TypeType
+from gremlin_python.process.traversal import Binding, Bytecode, P, Traversal, Traverser, TraversalStrategy
+from gremlin_python.structure.graph import Edge, Property, Vertex, VertexProperty, Path
+
+# When we fall back to a superclass's serializer, we iterate over this map.
+# We want that iteration order to be consistent, so we use an OrderedDict,
+# not a dict.
+_serializers = OrderedDict()
+_deserializers = {}
+
+
+class GraphSONTypeType(type):
+ def __new__(mcs, name, bases, dct):
+ cls = super(GraphSONTypeType, mcs).__new__(mcs, name, bases, dct)
+ if not name.startswith('_'):
+ if cls.python_type:
+ _serializers[cls.python_type] = cls
+ if cls.graphson_type:
+ _deserializers[cls.graphson_type] = cls
+ return cls
+
+
+class GraphSONUtil(object):
+ TYPE_KEY = "@type"
+ VALUE_KEY = "@value"
+
+ @classmethod
+ def typedValue(cls, type_name, value, prefix="g"):
+ out = {cls.TYPE_KEY: cls.formatType(prefix, type_name)}
+ if value is not None:
+ out[cls.VALUE_KEY] = value
+ return out
+
+ @classmethod
+ def formatType(cls, prefix, type_name):
+ return "%s:%s" % (prefix, type_name)
+
+
+# Read/Write classes split to follow precedence of the Java API
+class GraphSONWriter(object):
+ def __init__(self, serializer_map=None):
+ """
+ :param serializer_map: map from Python type to serializer instance implementing `dictify`
+ """
+ self.serializers = _serializers.copy()
+ if serializer_map:
+ self.serializers.update(serializer_map)
+
+ def writeObject(self, objectData):
+ # to JSON
+ return json.dumps(self.toDict(objectData), separators=(',', ':'))
+
+ def toDict(self, obj):
+ """
+ Encodes python objects in GraphSON type-tagged dict values
+ """
+ try:
+ return self.serializers[type(obj)].dictify(obj, self)
+ except KeyError:
+ for key, serializer in self.serializers.items():
+ if isinstance(obj, key):
+ return serializer.dictify(obj, self)
+
+ # list and map are treated as normal json objs (could be isolated serializers)
+ if isinstance(obj, (list, set)):
+ return [self.toDict(o) for o in obj]
+ elif isinstance(obj, dict):
+ return dict((self.toDict(k), self.toDict(v)) for k, v in obj.items())
+ else:
+ return obj
+
+
+class GraphSONReader(object):
+ def __init__(self, deserializer_map=None):
+ """
+ :param deserializer_map: map from GraphSON type tag to deserializer instance implementing `objectify`
+ """
+ self.deserializers = _deserializers.copy()
+ if deserializer_map:
+ self.deserializers.update(deserializer_map)
+
+ def readObject(self, jsonData):
+ # from JSON
+ return self.toObject(json.loads(jsonData))
+
+ def toObject(self, obj):
+ """
+ Unpacks GraphSON type-tagged dict values into objects mapped in self.deserializers
+ """
+ if isinstance(obj, dict):
+ try:
+ return self.deserializers[obj[GraphSONUtil.TYPE_KEY]].objectify(obj[GraphSONUtil.VALUE_KEY], self)
+ except KeyError:
+ pass
+ # list and map are treated as normal json objs (could be isolated deserializers)
+ return dict((self.toObject(k), self.toObject(v)) for k, v in obj.items())
+ elif isinstance(obj, list):
+ return [self.toObject(o) for o in obj]
+ else:
+ return obj
+
+
+@six.add_metaclass(GraphSONTypeType)
+class _GraphSONTypeIO(object):
+ python_type = None
+ graphson_type = None
+
+ symbolMap = {"global_": "global", "as_": "as", "in_": "in", "and_": "and",
+ "or_": "or", "is_": "is", "not_": "not", "from_": "from",
+ "set_": "set", "list_": "list", "all_": "all"}
+
+ @classmethod
+ def unmangleKeyword(cls, symbol):
+ return cls.symbolMap.get(symbol, symbol)
+
+ def dictify(self, obj, writer):
+ raise NotImplementedError()
+
+ def objectify(self, d, reader):
+ raise NotImplementedError()
+
+
+class _BytecodeSerializer(_GraphSONTypeIO):
+ @classmethod
+ def _dictify_instructions(cls, instructions, writer):
+ out = []
+ for instruction in instructions:
+ inst = [instruction[0]]
+ inst.extend(writer.toDict(arg) for arg in instruction[1:])
+ out.append(inst)
+ return out
+
+ @classmethod
+ def dictify(cls, bytecode, writer):
+ if isinstance(bytecode, Traversal):
+ bytecode = bytecode.bytecode
+ out = {}
+ if bytecode.source_instructions:
+ out["source"] = cls._dictify_instructions(bytecode.source_instructions, writer)
+ if bytecode.step_instructions:
+ out["step"] = cls._dictify_instructions(bytecode.step_instructions, writer)
+ return GraphSONUtil.typedValue("Bytecode", out)
+
-
+class TraversalSerializer(_BytecodeSerializer):
+ python_type = Traversal
+
+
+class BytecodeSerializer(_BytecodeSerializer):
+ python_type = Bytecode
+
+
+class VertexSerializer(_GraphSONTypeIO):
+ python_type = Vertex
+ graphson_type = "g:Vertex"
+
+ @classmethod
+ def dictify(cls, vertex, writer):
+ return GraphSONUtil.typedValue("Vertex", {"id": writer.toDict(vertex.id),
+ "label": writer.toDict(vertex.label)})
+
+
+class EdgeSerializer(_GraphSONTypeIO):
+ python_type = Edge
+ graphson_type = "g:Edge"
+
+ @classmethod
+ def dictify(cls, edge, writer):
+ return GraphSONUtil.typedValue("Edge", {"id": writer.toDict(edge.id),
+ "outV": writer.toDict(edge.outV.id),
+ "outVLabel": writer.toDict(edge.outV.label),
+ "label": writer.toDict(edge.label),
+ "inV": writer.toDict(edge.inV.id),
+ "inVLabel": writer.toDict(edge.inV.label)})
+
+
+class VertexPropertySerializer(_GraphSONTypeIO):
+ python_type = VertexProperty
+ graphson_type = "g:VertexProperty"
+
+ @classmethod
+ def dictify(cls, vertex_property, writer):
+ return GraphSONUtil.typedValue("VertexProperty", {"id": writer.toDict(vertex_property.id),
+ "label": writer.toDict(vertex_property.label),
+ "value": writer.toDict(vertex_property.value),
+ "vertex": writer.toDict(vertex_property.vertex.id)})
+
+
+class PropertySerializer(_GraphSONTypeIO):
+ python_type = Property
+ graphson_type = "g:Property"
+
+ @classmethod
+ def dictify(cls, property, writer):
+ elementDict = writer.toDict(property.element)
+ if elementDict is not None:
+ valueDict = elementDict["@value"]
+ if "outVLabel" in valueDict:
+ del valueDict["outVLabel"]
+ if "inVLabel" in valueDict:
+ del valueDict["inVLabel"]
+ if "properties" in valueDict:
+ del valueDict["properties"]
+ if "value" in valueDict:
+ del valueDict["value"]
+ return GraphSONUtil.typedValue("Property", {"key": writer.toDict(property.key),
+ "value": writer.toDict(property.value),
+ "element": elementDict})
+
+
+class TraversalStrategySerializer(_GraphSONTypeIO):
+ python_type = TraversalStrategy
+
+ @classmethod
+ def dictify(cls, strategy, writer):
+ return GraphSONUtil.typedValue(strategy.strategy_name, writer.toDict(strategy.configuration))
+
+
+class TraverserIO(_GraphSONTypeIO):
+ python_type = Traverser
+ graphson_type = "g:Traverser"
+
+ @classmethod
+ def dictify(cls, traverser, writer):
+ return GraphSONUtil.typedValue("Traverser", {"value": writer.toDict(traverser.object),
+ "bulk": writer.toDict(traverser.bulk)})
+
+ @classmethod
+ def objectify(cls, d, reader):
+ return Traverser(reader.toObject(d["value"]),
+ reader.toObject(d["bulk"]))
+
+
+class EnumSerializer(_GraphSONTypeIO):
+ python_type = Enum
+
+ @classmethod
+ def dictify(cls, enum, _):
+ return GraphSONUtil.typedValue(cls.unmangleKeyword(type(enum).__name__),
+ cls.unmangleKeyword(str(enum.name)))
+
+
+class PSerializer(_GraphSONTypeIO):
+ python_type = P
+
+ @classmethod
+ def dictify(cls, p, writer):
+ out = {"predicate": p.operator,
+ "value": [writer.toDict(p.value), writer.toDict(p.other)] if p.other is not None else
+ writer.toDict(p.value)}
+ return GraphSONUtil.typedValue("P", out)
+
+
+class BindingSerializer(_GraphSONTypeIO):
+ python_type = Binding
+
+ @classmethod
+ def dictify(cls, binding, writer):
+ out = {"key": binding.key,
+ "value": writer.toDict(binding.value)}
+ return GraphSONUtil.typedValue("Binding", out)
+
+
+class LambdaSerializer(_GraphSONTypeIO):
+ python_type = FunctionType
+
+ @classmethod
+ def dictify(cls, lambda_object, writer):
+ lambda_result = lambda_object()
+ script = lambda_result if isinstance(lambda_result, str) else lambda_result[0]
+ language = statics.default_lambda_language if isinstance(lambda_result, str) else lambda_result[1]
+ out = {"script": script,
+ "language": language}
+ if language == "gremlin-jython" or language == "gremlin-python":
+ if not script.strip().startswith("lambda"):
+ script = "lambda " + script
+ out["script"] = script
+ out["arguments"] = six.get_function_code(eval(out["script"])).co_argcount
+ else:
+ out["arguments"] = -1
+ return GraphSONUtil.typedValue("Lambda", out)
+
+
+class TypeSerializer(_GraphSONTypeIO):
+ python_type = TypeType
+
+ @classmethod
+ def dictify(cls, typ, writer):
+ return writer.toDict(typ())
+
+
+class _NumberIO(_GraphSONTypeIO):
+ @classmethod
+ def dictify(cls, n, writer):
+ if isinstance(n, bool): # because isinstance(False, int) and isinstance(True, int)
+ return n
+ return GraphSONUtil.typedValue(cls.graphson_base_type, n)
+
+ @classmethod
+ def objectify(cls, v, _):
+ return cls.python_type(v)
+
+
+class FloatIO(_NumberIO):
+ python_type = FloatType
+ graphson_type = "g:Float"
+ graphson_base_type = "Float"
+
+
+class DoubleIO(FloatIO):
+ graphson_type = "g:Double"
+ graphson_base_type = "Double"
+
+
+class Int64IO(_NumberIO):
+ python_type = LongType
+ graphson_type = "g:Int64"
+ graphson_base_type = "Int64"
+
+
+class Int32IO(_NumberIO):
+ python_type = IntType
+ graphson_type = "g:Int32"
+ graphson_base_type = "Int32"
+
+ @classmethod
+ def dictify(cls, n, writer):
+ if isinstance(n, bool):
+ return n
+ return GraphSONUtil.typedValue(cls.graphson_base_type, n)
+
+
+class VertexDeserializer(_GraphSONTypeIO):
+ graphson_type = "g:Vertex"
+
+ @classmethod
+ def objectify(cls, d, reader):
+ return Vertex(reader.toObject(d["id"]), d.get("label", "vertex"))
+
+
+class EdgeDeserializer(_GraphSONTypeIO):
+ graphson_type = "g:Edge"
+
+ @classmethod
+ def objectify(cls, d, reader):
+ return Edge(reader.toObject(d["id"]),
+ Vertex(reader.toObject(d["outV"]), d.get("outVLabel", "vertex")),
+ d.get("label", "edge"),
+ Vertex(reader.toObject(d["inV"]), d.get("inVLabel", "vertex")))
+
+
+class VertexPropertyDeserializer(_GraphSONTypeIO):
+ graphson_type = "g:VertexProperty"
+
+ @classmethod
+ def objectify(cls, d, reader):
+ vertex = Vertex(reader.toObject(d.get("vertex"))) if "vertex" in d else None
+ return VertexProperty(reader.toObject(d["id"]),
+ d["label"],
+ reader.toObject(d["value"]),
+ vertex)
+
+
+class PropertyDeserializer(_GraphSONTypeIO):
+ graphson_type = "g:Property"
+
+ @classmethod
+ def objectify(cls, d, reader):
+ element = reader.toObject(d["element"]) if "element" in d else None
+ return Property(d["key"], reader.toObject(d["value"]), element)
+
+
+class PathDeserializer(_GraphSONTypeIO):
+ graphson_type = "g:Path"
+
+ @classmethod
+ def objectify(cls, d, reader):
+ labels = [set(label) for label in d["labels"]]
+ objects = [reader.toObject(o) for o in d["objects"]]
+ return Path(labels, objects)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fcd623ce/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fcd623ce/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py
----------------------------------------------------------------------
diff --cc gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py
index 6bc5097,0000000..8f6285f
mode 100644,000000..100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py
@@@ -1,273 -1,0 +1,294 @@@
+'''
+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.
+'''
+
+__author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
+
+import sys
+import json
+from mock import Mock
+
+import six
+
+from gremlin_python.statics import *
+from gremlin_python.structure.graph import Vertex, Edge, Property, VertexProperty
+from gremlin_python.structure.graph import Path
+from gremlin_python.structure.io.graphsonV2d0 import GraphSONWriter, GraphSONReader, GraphSONUtil
+import gremlin_python.structure.io.graphsonV2d0
+from gremlin_python.process.traversal import P
+from gremlin_python.process.strategies import SubgraphStrategy
+from gremlin_python.process.graph_traversal import __
+
+
+class TestGraphSONReader(object):
+ graphson_reader = GraphSONReader()
+
+ def test_number_input(self):
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Int32",
+ "@value": 31
+ }))
+ assert isinstance(x, int)
+ assert 31 == x
+ ##
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Int64",
+ "@value": 31
+ }))
+ assert isinstance(x, long)
+ assert long(31) == x
+ ##
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Float",
+ "@value": 31.3
+ }))
+ assert isinstance(x, float)
+ assert 31.3 == x
+ ##
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Double",
+ "@value": 31.2
+ }))
+ assert isinstance(x, float)
+ assert 31.2 == x
+
+ def test_graph(self):
+ vertex = self.graphson_reader.readObject("""
+ {"@type":"g:Vertex", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","outE":{"created":[{"id":{"@type":"g:Int32","@value":9},"inV":{"@type":"g:Int32","@value":3},"properties":{"weight":{"@type":"g:Double","@value":0.4}}}],"knows":[{"id":{"@type":"g:Int32","@value":7},"inV":{"@type":"g:Int32","@value":2},"properties":{"weight":{"@type":"g:Double","@value":0.5}}},{"id":{"@type":"g:Int32","@value":8},"inV":{"@type":"g:Int32","@value":4},"properties":{"weight":{"@type":"g:Double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":0},"value":"marko"}],"age":[{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29}}]}}}""")
+ assert isinstance(vertex, Vertex)
+ assert "person" == vertex.label
+ assert 1 == vertex.id
+ assert isinstance(vertex.id, int)
+ assert vertex == Vertex(1)
+ ##
+ vertex = self.graphson_reader.readObject("""
+ {"@type":"g:Vertex", "@value":{"id":{"@type":"g:Float","@value":45.23}}}""")
+ assert isinstance(vertex, Vertex)
+ assert 45.23 == vertex.id
+ assert isinstance(vertex.id, FloatType)
+ assert "vertex" == vertex.label
+ assert vertex == Vertex(45.23)
+ ##
+ vertex_property = self.graphson_reader.readObject("""
+ {"@type":"g:VertexProperty", "@value":{"id":"anId","label":"aKey","value":true,"vertex":{"@type":"g:Int32","@value":9}}}""")
+ assert isinstance(vertex_property, VertexProperty)
+ assert "anId" == vertex_property.id
+ assert "aKey" == vertex_property.label
+ assert vertex_property.value
+ assert vertex_property.vertex == Vertex(9)
+ ##
+ vertex_property = self.graphson_reader.readObject("""
+ {"@type":"g:VertexProperty", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"name","value":"marko"}}""")
+ assert isinstance(vertex_property, VertexProperty)
+ assert 1 == vertex_property.id
+ assert "name" == vertex_property.label
+ assert "marko" == vertex_property.value
+ assert vertex_property.vertex is None
+ ##
+ edge = self.graphson_reader.readObject("""
+ {"@type":"g:Edge", "@value":{"id":{"@type":"g:Int64","@value":17},"label":"knows","inV":"x","outV":"y","inVLabel":"xLab","properties":{"aKey":"aValue","bKey":true}}}""")
+ # print edge
+ assert isinstance(edge, Edge)
+ assert 17 == edge.id
+ assert "knows" == edge.label
+ assert edge.inV == Vertex("x", "xLabel")
+ assert edge.outV == Vertex("y", "vertex")
+ ##
+ property = self.graphson_reader.readObject("""
+ {"@type":"g:Property", "@value":{"key":"aKey","value":{"@type":"g:Int64","@value":17},"element":{"@type":"g:Edge","@value":{"id":{"@type":"g:Int64","@value":122},"label":"knows","inV":"x","outV":"y","inVLabel":"xLab"}}}}""")
+ # print property
+ assert isinstance(property, Property)
+ assert "aKey" == property.key
+ assert 17 == property.value
+ assert Edge(122, Vertex("x"), "knows", Vertex("y")) == property.element
+
+ def test_path(self):
+ path = self.graphson_reader.readObject(
+ """{"@type":"g:Path","@value":{"labels":[["a"],["b","c"],[]],"objects":[{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0},"value":"marko","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29},"label":"age"}}]}}},{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":3},"label":"software","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":4},"value":"lop","label":"name"}}],"lang":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":5},"value":"java","label":"lang"}}]}}},"lop"]}}"""
+ )
+ assert isinstance(path, Path)
+ if six.PY3:
+ assert "[v[1], v[3], 'lop']" == str(path)
+ else:
+ assert "[v[1], v[3], u'lop']" == str(path)
+ assert Vertex(1) == path[0]
+ assert Vertex(1) == path["a"]
+ assert "lop" == path[2]
+ assert 3 == len(path)
+
+ def test_custom_mapping(self):
+
+ # extended mapping
+ class X(object):
+ pass
+
+ type_string = "test:Xtype"
+ override_string = "g:Int64"
+ serdes = Mock()
+
+ reader = GraphSONReader(deserializer_map={type_string: serdes})
+ assert type_string in reader.deserializers
+
+ # base dicts are not modified
+ assert type_string not in gremlin_python.structure.io.graphsonV2d0._deserializers
+
+ x = X()
+ o = reader.toObject({GraphSONUtil.TYPE_KEY: type_string, GraphSONUtil.VALUE_KEY: x})
+ serdes.objectify.assert_called_once_with(x, reader)
+ assert o is serdes.objectify()
+
+ # overridden mapping
+ type_string = "g:Int64"
+ serdes = Mock()
+ reader = GraphSONReader(deserializer_map={type_string: serdes, override_string: serdes})
+ assert gremlin_python.structure.io.graphsonV2d0._deserializers[type_string] is not reader.deserializers[type_string]
+
+ value = 3
+ o = reader.toObject({GraphSONUtil.TYPE_KEY: type_string, GraphSONUtil.VALUE_KEY: value})
+ serdes.objectify.assert_called_once_with(value, reader)
+ assert o is serdes.objectify()
+
+class TestGraphSONWriter(object):
-
+ graphson_writer = GraphSONWriter()
++ graphson_reader = GraphSONReader()
+
+ def test_number_output(self):
+ assert {"@type": "g:Int64", "@value": 2} == json.loads(self.graphson_writer.writeObject(long(2)))
+ assert {"@type": "g:Int32", "@value": 1} == json.loads(self.graphson_writer.writeObject(1))
+ assert {"@type": "g:Double", "@value": 3.2} == json.loads(self.graphson_writer.writeObject(3.2))
+ assert """true""" == self.graphson_writer.writeObject(True)
+
+ def test_numbers(self):
+ assert {"@type": "g:Int64", "@value": 2} == json.loads(self.graphson_writer.writeObject(long(2)))
+ assert {"@type": "g:Int32", "@value": 1} == json.loads(self.graphson_writer.writeObject(1))
+ assert {"@type": "g:Double", "@value": 3.2} == json.loads(self.graphson_writer.writeObject(3.2))
+ assert """true""" == self.graphson_writer.writeObject(True)
+
+ def test_P(self):
+ result = {'@type': 'g:P',
+ '@value': {
- 'predicate': 'and',
- 'value': [{
- '@type': 'g:P',
- '@value': {
- 'predicate': 'or',
- 'value': [{
- '@type': 'g:P',
- '@value': {'predicate': 'lt', 'value': 'b'}
- },
- {'@type': 'g:P', '@value': {'predicate': 'gt', 'value': 'c'}}
- ]
- }
- },
- {'@type': 'g:P', '@value': {'predicate': 'neq', 'value': 'd'}}]}}
-
- assert result == json.loads(
++ 'predicate': 'and',
++ 'value': [{
++ '@type': 'g:P',
++ '@value': {
++ 'predicate': 'or',
++ 'value': [{
++ '@type': 'g:P',
++ '@value': {'predicate': 'lt', 'value': 'b'}
++ },
++ {'@type': 'g:P', '@value': {'predicate': 'gt', 'value': 'c'}}
++ ]
++ }
++ },
++ {'@type': 'g:P', '@value': {'predicate': 'neq', 'value': 'd'}}]}}
++
++ assert result == json.loads(
+ self.graphson_writer.writeObject(P.lt("b").or_(P.gt("c")).and_(P.neq("d"))))
+
+ result = {'@type': 'g:P', '@value': {'predicate':'within','value': [{"@type": "g:Int32", "@value": 1},{"@type": "g:Int32", "@value": 2}]}}
+ assert result == json.loads(self.graphson_writer.writeObject(P.within([1,2])))
+
+ def test_strategies(self):
+ # we have a proxy model for now given that we don't want to have to have g:XXX all registered on the Gremlin traversal machine (yet)
+ assert {"@type": "g:SubgraphStrategy", "@value": {}} == json.loads(
+ self.graphson_writer.writeObject(SubgraphStrategy))
+ assert {"@type": "g:SubgraphStrategy", "@value": {
+ "vertices": {"@type": "g:Bytecode", "@value": {"step": [["has", "name", "marko"]]}}}} == json.loads(
+ self.graphson_writer.writeObject(SubgraphStrategy(vertices=__.has("name", "marko"))))
+
+ def test_graph(self):
+ # TODO: this assert is not compatible with python 3 and now that we test with both 2 and 3 it fails
+ assert {"@type": "g:Vertex", "@value": {"id": {"@type": "g:Int64", "@value": 12}, "label": "person"}} == json.loads(self.graphson_writer.writeObject(Vertex(long(12), "person")))
+
+ assert {"@type": "g:Edge", "@value": {"id": {"@type": "g:Int32", "@value": 7},
+ "outV": {"@type": "g:Int32", "@value": 0},
+ "outVLabel": "person",
+ "label": "knows",
+ "inV": {"@type": "g:Int32", "@value": 1},
+ "inVLabel": "dog"}} == json.loads(
+ self.graphson_writer.writeObject(Edge(7, Vertex(0, "person"), "knows", Vertex(1, "dog"))))
+ assert {"@type": "g:VertexProperty", "@value": {"id": "blah", "label": "keyA", "value": True,
+ "vertex": "stephen"}} == json.loads(
+ self.graphson_writer.writeObject(VertexProperty("blah", "keyA", True, Vertex("stephen"))))
+
+ assert {"@type": "g:Property",
+ "@value": {"key": "name", "value": "marko", "element": {"@type": "g:VertexProperty",
+ "@value": {
+ "vertex": "vertexId",
+ "id": {"@type": "g:Int32", "@value": 1234},
+ "label": "aKey"}}}} == json.loads(
+ self.graphson_writer.writeObject(
+ Property("name", "marko", VertexProperty(1234, "aKey", 21345, Vertex("vertexId")))))
+
++ vertex = self.graphson_reader.readObject(self.graphson_writer.writeObject(Vertex(1, "person")))
++ assert 1 == vertex.id
++ assert "person" == vertex.label
++
++ edge = self.graphson_reader.readObject(
++ self.graphson_writer.writeObject(Edge(3, Vertex(1, "person"), "knows", Vertex(2, "dog"))))
++ assert "knows" == edge.label
++ assert 3 == edge.id
++ assert 1 == edge.outV.id
++ assert 2 == edge.inV.id
++
++ vertex_property = self.graphson_reader.readObject(
++ self.graphson_writer.writeObject(VertexProperty(1, "age", 32, Vertex(1))))
++ assert 1 == vertex_property.id
++ assert "age" == vertex_property.key
++ assert 32 == vertex_property.value
++
++ property = self.graphson_reader.readObject(self.graphson_writer.writeObject(Property("age", 32.2, Edge(1,Vertex(2),"knows",Vertex(3)))))
++ assert "age" == property.key
++ assert 32.2 == property.value
++
+ def test_custom_mapping(self):
+ # extended mapping
+ class X(object):
+ pass
+
+ serdes = Mock()
+ writer = GraphSONWriter(serializer_map={X: serdes})
+ assert X in writer.serializers
+
+ # base dicts are not modified
+ assert X not in gremlin_python.structure.io.graphsonV2d0._serializers
+
+ obj = X()
+ d = writer.toDict(obj)
+ serdes.dictify.assert_called_once_with(obj, writer)
+ assert d is serdes.dictify()
+
+ # overridden mapping
+ serdes = Mock()
+ writer = GraphSONWriter(serializer_map={int: serdes})
+ assert gremlin_python.structure.io.graphsonV2d0._serializers[int] is not writer.serializers[int]
+
+ value = 3
+ d = writer.toDict(value)
+ serdes.dictify.assert_called_once_with(value, writer)
+ assert d is serdes.dictify()
+
+ def test_write_long(self):
-
+ mapping = self.graphson_writer.toDict(1)
+ assert mapping['@type'] == 'g:Int32'
+ assert mapping['@value'] == 1
+
+ mapping = self.graphson_writer.toDict(long(1))
+ assert mapping['@type'] == 'g:Int64'
- assert mapping['@value'] == 1
++ assert mapping['@value'] == 1
++
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fcd623ce/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
----------------------------------------------------------------------
diff --cc gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
index 78798b3,0000000..b4dfcac
mode 100644,000000..100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
@@@ -1,313 -1,0 +1,335 @@@
+'''
+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.
+'''
+
+__author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
+
+import json
+from mock import Mock
+
+import six
+
+from gremlin_python.statics import *
+from gremlin_python.structure.graph import Vertex, Edge, Property, VertexProperty
+from gremlin_python.structure.graph import Path
+from gremlin_python.structure.io.graphsonV3d0 import GraphSONWriter, GraphSONReader, GraphSONUtil
+import gremlin_python.structure.io.graphsonV3d0
+from gremlin_python.process.traversal import P
+from gremlin_python.process.strategies import SubgraphStrategy
+from gremlin_python.process.graph_traversal import __
+
+
+class TestGraphSONReader(object):
+ graphson_reader = GraphSONReader()
+
+ def test_collections(self):
+ x = self.graphson_reader.readObject(
+ json.dumps({"@type": "g:List", "@value": [{"@type": "g:Int32", "@value": 1},
+ {"@type": "g:Int32", "@value": 2},
+ "3"]}))
+ assert isinstance(x, list)
+ assert x[0] == 1
+ assert x[1] == 2
+ assert x[2] == "3"
+ ##
+ x = self.graphson_reader.readObject(
+ json.dumps({"@type": "g:Set", "@value": [{"@type": "g:Int32", "@value": 1},
+ {"@type": "g:Int32", "@value": 2},
+ "3"]}))
+ assert isinstance(x, set)
+ assert x == set([1, 2, "3"])
+ ##
+ x = self.graphson_reader.readObject(
+ json.dumps({"@type": "g:Map",
+ "@value": ['a', {"@type": "g:Int32", "@value": 1}, 'b', "marko"]}))
+ assert isinstance(x, dict)
+ assert x['a'] == 1
+ assert x['b'] == "marko"
+ assert len(x) == 2
+
+ def test_number_input(self):
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Int32",
+ "@value": 31
+ }))
+ assert isinstance(x, int)
+ assert 31 == x
+ ##
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Int64",
+ "@value": 31
+ }))
+ assert isinstance(x, long)
+ assert long(31) == x
+ ##
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Float",
+ "@value": 31.3
+ }))
+ assert isinstance(x, float)
+ assert 31.3 == x
+ ##
+ x = self.graphson_reader.readObject(json.dumps({
+ "@type": "g:Double",
+ "@value": 31.2
+ }))
+ assert isinstance(x, float)
+ assert 31.2 == x
+
+ def test_graph(self):
+ vertex = self.graphson_reader.readObject("""
+ {"@type":"g:Vertex", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","outE":{"created":[{"id":{"@type":"g:Int32","@value":9},"inV":{"@type":"g:Int32","@value":3},"properties":{"weight":{"@type":"g:Double","@value":0.4}}}],"knows":[{"id":{"@type":"g:Int32","@value":7},"inV":{"@type":"g:Int32","@value":2},"properties":{"weight":{"@type":"g:Double","@value":0.5}}},{"id":{"@type":"g:Int32","@value":8},"inV":{"@type":"g:Int32","@value":4},"properties":{"weight":{"@type":"g:Double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":0},"value":"marko"}],"age":[{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29}}]}}}""")
+ assert isinstance(vertex, Vertex)
+ assert "person" == vertex.label
+ assert 1 == vertex.id
+ assert isinstance(vertex.id, int)
+ assert vertex == Vertex(1)
+ ##
+ vertex = self.graphson_reader.readObject("""
+ {"@type":"g:Vertex", "@value":{"id":{"@type":"g:Float","@value":45.23}}}""")
+ assert isinstance(vertex, Vertex)
+ assert 45.23 == vertex.id
+ assert isinstance(vertex.id, FloatType)
+ assert "vertex" == vertex.label
+ assert vertex == Vertex(45.23)
+ ##
+ vertex_property = self.graphson_reader.readObject("""
+ {"@type":"g:VertexProperty", "@value":{"id":"anId","label":"aKey","value":true,"vertex":{"@type":"g:Int32","@value":9}}}""")
+ assert isinstance(vertex_property, VertexProperty)
+ assert "anId" == vertex_property.id
+ assert "aKey" == vertex_property.label
+ assert vertex_property.value
+ assert vertex_property.vertex == Vertex(9)
+ ##
+ vertex_property = self.graphson_reader.readObject("""
+ {"@type":"g:VertexProperty", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"name","value":"marko"}}""")
+ assert isinstance(vertex_property, VertexProperty)
+ assert 1 == vertex_property.id
+ assert "name" == vertex_property.label
+ assert "marko" == vertex_property.value
+ assert vertex_property.vertex is None
+ ##
+ edge = self.graphson_reader.readObject("""
+ {"@type":"g:Edge", "@value":{"id":{"@type":"g:Int64","@value":17},"label":"knows","inV":"x","outV":"y","inVLabel":"xLab","properties":{"aKey":"aValue","bKey":true}}}""")
+ # print edge
+ assert isinstance(edge, Edge)
+ assert 17 == edge.id
+ assert "knows" == edge.label
+ assert edge.inV == Vertex("x", "xLabel")
+ assert edge.outV == Vertex("y", "vertex")
+ ##
+ property = self.graphson_reader.readObject("""
+ {"@type":"g:Property", "@value":{"key":"aKey","value":{"@type":"g:Int64","@value":17},"element":{"@type":"g:Edge","@value":{"id":{"@type":"g:Int64","@value":122},"label":"knows","inV":"x","outV":"y","inVLabel":"xLab"}}}}""")
+ # print property
+ assert isinstance(property, Property)
+ assert "aKey" == property.key
+ assert 17 == property.value
+ assert Edge(122, Vertex("x"), "knows", Vertex("y")) == property.element
+
+ def test_path(self):
+ path = self.graphson_reader.readObject(
+ """{"@type":"g:Path","@value":{"labels":[["a"],["b","c"],[]],"objects":[{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0},"value":"marko","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29},"label":"age"}}]}}},{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":3},"label":"software","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":4},"value":"lop","label":"name"}}],"lang":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":5},"value":"java","label":"lang"}}]}}},"lop"]}}"""
+ )
+ assert isinstance(path, Path)
+ if six.PY3:
+ assert "[v[1], v[3], 'lop']" == str(path)
+ else:
+ assert "[v[1], v[3], u'lop']" == str(path)
+ assert Vertex(1) == path[0]
+ assert Vertex(1) == path["a"]
+ assert "lop" == path[2]
+ assert 3 == len(path)
+
+ def test_custom_mapping(self):
+
+ # extended mapping
+ class X(object):
+ pass
+
+ type_string = "test:Xtype"
+ override_string = "g:Int64"
+ serdes = Mock()
+
+ reader = GraphSONReader(deserializer_map={type_string: serdes})
+ assert type_string in reader.deserializers
+
+ # base dicts are not modified
+ assert type_string not in gremlin_python.structure.io.graphsonV3d0._deserializers
+
+ x = X()
+ o = reader.toObject({GraphSONUtil.TYPE_KEY: type_string, GraphSONUtil.VALUE_KEY: x})
+ serdes.objectify.assert_called_once_with(x, reader)
+ assert o is serdes.objectify()
+
+ # overridden mapping
+ type_string = "g:Int64"
+ serdes = Mock()
+ reader = GraphSONReader(deserializer_map={type_string: serdes, override_string: serdes})
+ assert gremlin_python.structure.io.graphsonV3d0._deserializers[type_string] is not reader.deserializers[
+ type_string]
+
+ value = 3
+ o = reader.toObject({GraphSONUtil.TYPE_KEY: type_string, GraphSONUtil.VALUE_KEY: value})
+ serdes.objectify.assert_called_once_with(value, reader)
+ assert o is serdes.objectify()
+
+
+class TestGraphSONWriter(object):
+ graphson_writer = GraphSONWriter()
++ graphson_reader = GraphSONReader()
+
+ def test_collections(self):
+ assert {"@type": "g:List", "@value": [{"@type": "g:Int32", "@value": 1},
+ {"@type": "g:Int32", "@value": 2},
+ {"@type": "g:Int32", "@value": 3}]} == json.loads(
+ self.graphson_writer.writeObject([1, 2, 3]))
+ assert {"@type": "g:Set", "@value": [{"@type": "g:Int32", "@value": 1},
+ {"@type": "g:Int32", "@value": 2},
+ {"@type": "g:Int32", "@value": 3}]} == json.loads(
+ self.graphson_writer.writeObject(set([1, 2, 3, 3])))
+ assert {"@type": "g:Map",
+ "@value": ['a', {"@type": "g:Int32", "@value": 1}]} == json.loads(
+ self.graphson_writer.writeObject({'a': 1}))
+
+ def test_number_output(self):
+ assert {"@type": "g:Int64", "@value": 2} == json.loads(self.graphson_writer.writeObject(long(2)))
+ assert {"@type": "g:Int32", "@value": 1} == json.loads(self.graphson_writer.writeObject(1))
+ assert {"@type": "g:Double", "@value": 3.2} == json.loads(self.graphson_writer.writeObject(3.2))
+ assert """true""" == self.graphson_writer.writeObject(True)
+
+ def test_numbers(self):
+ assert {"@type": "g:Int64", "@value": 2} == json.loads(self.graphson_writer.writeObject(long(2)))
+ assert {"@type": "g:Int32", "@value": 1} == json.loads(self.graphson_writer.writeObject(1))
+ assert {"@type": "g:Double", "@value": 3.2} == json.loads(self.graphson_writer.writeObject(3.2))
+ assert """true""" == self.graphson_writer.writeObject(True)
+
+ def test_P(self):
+ result = {'@type': 'g:P',
+ '@value': {
+ 'predicate': 'and',
+ 'value': [{
+ '@type': 'g:P',
+ '@value': {
+ 'predicate': 'or',
+ 'value': [{
+ '@type': 'g:P',
+ '@value': {'predicate': 'lt', 'value': 'b'}
+ },
+ {'@type': 'g:P', '@value': {'predicate': 'gt', 'value': 'c'}}
+ ]
+ }
+ },
+ {'@type': 'g:P', '@value': {'predicate': 'neq', 'value': 'd'}}]}}
+
+ assert result == json.loads(
+ self.graphson_writer.writeObject(P.lt("b").or_(P.gt("c")).and_(P.neq("d"))))
+
+ result = {'@type': 'g:P', '@value': {'predicate': 'within', 'value': {'@type': 'g:List', '@value': [
+ {"@type": "g:Int32", "@value": 1}, {"@type": "g:Int32", "@value": 2}]}}}
+ assert result == json.loads(self.graphson_writer.writeObject(P.within([1, 2])))
+
+ def test_strategies(self):
+ # we have a proxy model for now given that we don't want to have to have g:XXX all registered on the Gremlin traversal machine (yet)
+ assert {"@type": "g:SubgraphStrategy", "@value": {}} == json.loads(
+ self.graphson_writer.writeObject(SubgraphStrategy))
+ assert {"@type": "g:SubgraphStrategy", "@value": {
+ "vertices": {"@type": "g:Bytecode", "@value": {"step": [["has", "name", "marko"]]}}}} == json.loads(
+ self.graphson_writer.writeObject(SubgraphStrategy(vertices=__.has("name", "marko"))))
+
+ def test_graph(self):
+ # TODO: this assert is not compatible with python 3 and now that we test with both 2 and 3 it fails
+ assert {"@type": "g:Vertex",
+ "@value": {"id": {"@type": "g:Int64", "@value": 12}, "label": "person"}} == json.loads(
+ self.graphson_writer.writeObject(Vertex(long(12), "person")))
+
+ assert {"@type": "g:Edge", "@value": {"id": {"@type": "g:Int32", "@value": 7},
+ "outV": {"@type": "g:Int32", "@value": 0},
+ "outVLabel": "person",
+ "label": "knows",
+ "inV": {"@type": "g:Int32", "@value": 1},
+ "inVLabel": "dog"}} == json.loads(
+ self.graphson_writer.writeObject(Edge(7, Vertex(0, "person"), "knows", Vertex(1, "dog"))))
+ assert {"@type": "g:VertexProperty", "@value": {"id": "blah", "label": "keyA", "value": True,
+ "vertex": "stephen"}} == json.loads(
+ self.graphson_writer.writeObject(VertexProperty("blah", "keyA", True, Vertex("stephen"))))
+
+ assert {"@type": "g:Property",
+ "@value": {"key": "name", "value": "marko", "element": {"@type": "g:VertexProperty",
+ "@value": {
+ "vertex": "vertexId",
+ "id": {"@type": "g:Int32", "@value": 1234},
+ "label": "aKey"}}}} == json.loads(
+ self.graphson_writer.writeObject(
+ Property("name", "marko", VertexProperty(1234, "aKey", 21345, Vertex("vertexId")))))
+
++ vertex = self.graphson_reader.readObject(self.graphson_writer.writeObject(Vertex(1, "person")))
++ assert 1 == vertex.id
++ assert "person" == vertex.label
++
++ edge = self.graphson_reader.readObject(
++ self.graphson_writer.writeObject(Edge(3, Vertex(1, "person"), "knows", Vertex(2, "dog"))))
++ assert "knows" == edge.label
++ assert 3 == edge.id
++ assert 1 == edge.outV.id
++ assert 2 == edge.inV.id
++
++ vertex_property = self.graphson_reader.readObject(
++ self.graphson_writer.writeObject(VertexProperty(1, "age", 32, Vertex(1))))
++ assert 1 == vertex_property.id
++ assert "age" == vertex_property.key
++ assert 32 == vertex_property.value
++
++ property = self.graphson_reader.readObject(self.graphson_writer.writeObject(Property("age", 32.2, Edge(1,Vertex(2),"knows",Vertex(3)))))
++ assert "age" == property.key
++ assert 32.2 == property.value
++
+ def test_custom_mapping(self):
+ # extended mapping
+ class X(object):
+ pass
+
+ serdes = Mock()
+ writer = GraphSONWriter(serializer_map={X: serdes})
+ assert X in writer.serializers
+
+ # base dicts are not modified
+ assert X not in gremlin_python.structure.io.graphsonV3d0._serializers
+
+ obj = X()
+ d = writer.toDict(obj)
+ serdes.dictify.assert_called_once_with(obj, writer)
+ assert d is serdes.dictify()
+
+ # overridden mapping
+ serdes = Mock()
+ writer = GraphSONWriter(serializer_map={int: serdes})
+ assert gremlin_python.structure.io.graphsonV3d0._serializers[int] is not writer.serializers[int]
+
+ value = 3
+ d = writer.toDict(value)
+ serdes.dictify.assert_called_once_with(value, writer)
+ assert d is serdes.dictify()
+
+ def test_write_long(self):
+ mapping = self.graphson_writer.toDict(1)
+ assert mapping['@type'] == 'g:Int32'
+ assert mapping['@value'] == 1
+
+ mapping = self.graphson_writer.toDict(long(1))
+ assert mapping['@type'] == 'g:Int64'
+ assert mapping['@value'] == 1
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fcd623ce/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
----------------------------------------------------------------------
diff --cc gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
index c6e76d8,0e5fca2..46d1766
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
@@@ -63,6 -63,45 +63,10 @@@ public abstract class AddEdgeTest exten
public abstract Traversal<Vertex, Edge> get_g_addV_asXfirstX_repeatXaddEXnextX_toXaddVX_inVX_timesX5X_addEXnextX_toXselectXfirstXX();
+ public abstract Traversal<Vertex, Edge> get_g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X();
+
+ ///////
+
- @Deprecated
- public abstract Traversal<Vertex, Edge> get_g_VX1X_asXaX_outXcreatedX_addOutEXcreatedBy_aX(final Object v1Id);
-
- @Deprecated
- public abstract Traversal<Vertex, Edge> get_g_VX1X_asXaX_outXcreatedX_addOutEXcreatedBy_a_weight_2X(final Object v1Id);
-
- @Deprecated
- public abstract Traversal<Vertex, Edge> get_g_withSideEffectXx__g_V_toListX_addOutEXexistsWith_x_time_nowX();
-
- @Deprecated
- public abstract Traversal<Vertex, Edge> get_g_V_asXaX_outXcreatedX_inXcreatedX_whereXneqXaXX_asXbX_selectXa_bX_addInEXa_codeveloper_b_year_2009X();
-
- @Deprecated
- public abstract Traversal<Vertex, Edge> get_g_V_asXaX_inXcreatedX_addInEXcreatedBy_a_year_2009_acl_publicX();
-
- @Test
- @LoadGraphWith(MODERN)
- @Deprecated
- @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
- public void g_VX1X_asXaX_outXcreatedX_addOutEXcreatedBy_aX() {
- final Traversal<Vertex, Edge> traversal = get_g_VX1X_asXaX_outXcreatedX_addOutEXcreatedBy_aX(convertToVertexId("marko"));
- printTraversalForm(traversal);
- int count = 0;
- while (traversal.hasNext()) {
- final Edge edge = traversal.next();
- assertEquals("createdBy", edge.label());
- assertEquals(0, IteratorUtils.count(edge.properties()));
- count++;
-
- }
- assertEquals(1, count);
- assertEquals(7, IteratorUtils.count(g.E()));
- assertEquals(6, IteratorUtils.count(g.V()));
- }
-
@Test
@LoadGraphWith(MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@@@ -154,6 -265,48 +158,22 @@@
@Test
@LoadGraphWith(MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+ public void g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X() {
+ final Traversal<Vertex, Edge> traversal = get_g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X();
+ final Edge edge = traversal.next();
+ assertFalse(traversal.hasNext());
+ assertEquals(edge.outVertex(), convertToVertex(graph, "marko"));
+ assertEquals(edge.inVertex(), convertToVertex(graph, "peter"));
+ assertEquals("knows", edge.label());
+ assertEquals(1, IteratorUtils.count(edge.properties()));
+ assertEquals(0.5d, edge.value("weight"), 0.1d);
+ assertEquals(6L, g.V().count().next().longValue());
+ assertEquals(7L, g.E().count().next().longValue());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
- @Deprecated
- @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
- public void g_V_asXaX_inXcreatedX_addInEXcreatedBy_a_year_2009_acl_publicX() {
- final Traversal<Vertex, Edge> traversal = get_g_V_asXaX_inXcreatedX_addInEXcreatedBy_a_year_2009_acl_publicX();
- printTraversalForm(traversal);
- int count = 0;
- while (traversal.hasNext()) {
- final Edge edge = traversal.next();
- assertEquals("createdBy", edge.label());
- assertEquals(2009, (int) edge.value("year"));
- assertEquals("public", edge.value("acl"));
- assertEquals(2, IteratorUtils.count(edge.properties()));
- assertEquals("person", edge.inVertex().label());
- assertEquals("software", edge.outVertex().label());
- if (edge.outVertex().value("name").equals("ripple"))
- assertEquals("josh", edge.inVertex().value("name"));
- count++;
-
- }
- assertEquals(4, count);
- assertEquals(10, IteratorUtils.count(g.E()));
- assertEquals(6, IteratorUtils.count(g.V()));
- }
-
- @Test
- @LoadGraphWith(MODERN)
+ @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
public void g_V_asXaX_inXcreatedX_addEXcreatedByX_fromXaX_propertyXyear_2009X_propertyXacl_publicX() {
final Traversal<Vertex, Edge> traversal = get_g_V_asXaX_inXcreatedX_addEXcreatedByX_fromXaX_propertyXyear_2009X_propertyXacl_publicX();
printTraversalForm(traversal);
@@@ -220,6 -373,40 +240,13 @@@
}
@Override
+ public Traversal<Vertex, Edge> get_g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X() {
+ final Vertex a = g.V().has("name", "marko").next();
+ final Vertex b = g.V().has("name", "peter").next();
+ return g.withSideEffect("b", b).V(a).addE("knows").to("b").property("weight", 0.5d);
+ }
+
- ///////
-
- @Override
- public Traversal<Vertex, Edge> get_g_VX1X_asXaX_outXcreatedX_addOutEXcreatedBy_aX(final Object v1Id) {
- return g.V(v1Id).as("a").out("created").addOutE("createdBy", "a");
- }
-
- @Override
- public Traversal<Vertex, Edge> get_g_VX1X_asXaX_outXcreatedX_addOutEXcreatedBy_a_weight_2X(final Object v1Id) {
- return g.V(v1Id).as("a").out("created").addOutE("createdBy", "a", "weight", 2.0d);
- }
-
- @Override
- public Traversal<Vertex, Edge> get_g_withSideEffectXx__g_V_toListX_addOutEXexistsWith_x_time_nowX() {
- return g.withSideEffect("x", g.V().toList()).V().addOutE("existsWith", "x", "time", "now");
- }
-
- @Override
- public Traversal<Vertex, Edge> get_g_V_asXaX_outXcreatedX_inXcreatedX_whereXneqXaXX_asXbX_selectXa_bX_addInEXa_codeveloper_b_year_2009X() {
- return g.V().as("a").out("created").in("created").where(P.neq("a")).as("b").select("a", "b").addInE("a", "codeveloper", "b", "year", 2009);
- }
-
- @Override
- public Traversal<Vertex, Edge> get_g_V_asXaX_inXcreatedX_addInEXcreatedBy_a_year_2009_acl_publicX() {
- return g.V().as("a").in("created").addInE("createdBy", "a", "year", 2009, "acl", "public");
- }
-
+ @Override
public Traversal<Vertex, Edge> get_g_addV_asXfirstX_repeatXaddEXnextX_toXaddVX_inVX_timesX5X_addEXnextX_toXselectXfirstXX() {
return g.addV().as("first").repeat(__.addE("next").to(__.addV()).inV()).times(5).addE("next").to(select("first"));
}
[4/7] tinkerpop git commit: updated CHANGELOG and optimized
AddEdgeStep attachment a bit.
Posted by ok...@apache.org.
updated CHANGELOG and optimized AddEdgeStep attachment a bit.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/894e0e81
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/894e0e81
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/894e0e81
Branch: refs/heads/master
Commit: 894e0e815bb213528fe659ede87177a4111bc78b
Parents: 6bfc1fa
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Jul 20 16:22:10 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Jul 20 16:22:10 2017 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../process/traversal/step/map/AddEdgeStep.java | 14 +++++++-------
2 files changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/894e0e81/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index ab44755..d2d1447 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -28,6 +28,7 @@ TinkerPop 3.2.6 (Release Date: NOT OFFICIALLY RELEASED YET)
This release also includes changes from <<release-3-1-8, 3.1.8>>.
+* `AddEdgeStep` attaches detached vertices prior to edge creation.
* Added graph element GraphSON serializers in Gremlin-Python.
* Initialization scripts for Gremlin Server will not timeout.
* Added Gremlin.Net.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/894e0e81/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
index c64f455..5a083cb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
@@ -37,6 +37,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import java.util.List;
import java.util.Set;
@@ -93,13 +94,12 @@ public final class AddEdgeStep<S> extends MapStep<S, Edge>
protected Edge map(final Traverser.Admin<S> traverser) {
Vertex toVertex = this.parameters.get(traverser, TO, () -> (Vertex) traverser.get()).get(0);
Vertex fromVertex = this.parameters.get(traverser, FROM, () -> (Vertex) traverser.get()).get(0);
- if (this.getTraversal().getGraph().isPresent()) {
- final Graph graph = this.getTraversal().getGraph().get();
- if (toVertex instanceof Attachable)
- toVertex = ((Attachable<Vertex>) toVertex).attach(Attachable.Method.get(graph));
- if (fromVertex instanceof Attachable)
- fromVertex = ((Attachable<Vertex>) fromVertex).attach(Attachable.Method.get(graph));
- }
+ if (toVertex instanceof Attachable)
+ toVertex = ((Attachable<Vertex>) fromVertex)
+ .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
+ if (fromVertex instanceof Attachable)
+ fromVertex = ((Attachable<Vertex>) fromVertex)
+ .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
final String edgeLabel = this.parameters.get(traverser, T.label, () -> Edge.DEFAULT_LABEL).get(0);
final Edge edge = fromVertex.addEdge(edgeLabel, toVertex, this.parameters.getKeyValues(traverser, TO, FROM, T.label));
[3/7] tinkerpop git commit: dah. RemoteGraph test failure cause of a
stupid addition I made last minute to AddEdgeTest. Fixed.
Posted by ok...@apache.org.
dah. RemoteGraph test failure cause of a stupid addition I made last minute to AddEdgeTest. Fixed.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6bfc1fa4
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6bfc1fa4
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6bfc1fa4
Branch: refs/heads/master
Commit: 6bfc1fa478ea10c62892505bd79245fbcb5d58df
Parents: bc6eccb
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Jul 20 15:50:04 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Jul 20 15:50:04 2017 -0600
----------------------------------------------------------------------
.../gremlin/process/traversal/step/map/AddEdgeTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6bfc1fa4/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
index b45dfbb..0e5fca2 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeTest.java
@@ -274,8 +274,8 @@ public abstract class AddEdgeTest extends AbstractGremlinProcessTest {
assertEquals("knows", edge.label());
assertEquals(1, IteratorUtils.count(edge.properties()));
assertEquals(0.5d, edge.value("weight"), 0.1d);
- assertEquals(6, IteratorUtils.count(graph.vertices()));
- assertEquals(7, IteratorUtils.count(graph.edges()));
+ assertEquals(6L, g.V().count().next().longValue());
+ assertEquals(7L, g.E().count().next().longValue());
}
@Test
[6/7] tinkerpop git commit: Merge branch 'TINKERPOP-1679' into tp32
Posted by ok...@apache.org.
Merge branch 'TINKERPOP-1679' into tp32
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9a33651a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9a33651a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9a33651a
Branch: refs/heads/master
Commit: 9a33651a7e65cb22ec0cb3775ef6419d4336b509
Parents: a7e0e0f 2e11e99
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Jul 24 13:35:25 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Jul 24 13:35:25 2017 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 2 +
.../gremlin/process/remote/RemoteGraph.java | 8 ---
.../process/traversal/step/map/AddEdgeStep.java | 18 +++--
.../traversal/step/map/GroovyAddEdgeTest.groovy | 8 +++
.../gremlin_python/structure/io/graphson.py | 51 +++++++++++++--
.../driver/test_driver_remote_connection.py | 19 +++++-
.../jython/tests/structure/io/test_graphson.py | 69 +++++++++++++-------
.../process/traversal/step/map/AddEdgeTest.java | 25 +++++++
8 files changed, 154 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9a33651a/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --cc CHANGELOG.asciidoc
index 9039d9f,d2d1447..62f4fe8
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@@ -28,7 -28,8 +28,9 @@@ TinkerPop 3.2.6 (Release Date: NOT OFFI
This release also includes changes from <<release-3-1-8, 3.1.8>>.
+* Exceptions that occur during result iteration in Gremlin Server will now return `SCRIPT_EVALUATION_EXCEPTION` rather than `SERVER_ERROR`.
+ * `AddEdgeStep` attaches detached vertices prior to edge creation.
+ * Added graph element GraphSON serializers in Gremlin-Python.
* Initialization scripts for Gremlin Server will not timeout.
* Added Gremlin.Net.
* `ProfileTest` is now less stringent about assertions which will reduce burdens on providers.