diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 1b0f79b4eb3..07d53f9de7e 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima [[release-3-3-6]] === TinkerPop 3.3.6 (Release Date: NOT OFFICIALLY RELEASED YET) +* Add python TraversalMetrics and Metrics deserializers * Masked sensitive configuration options in the logs of `KryoShimServiceLoader`. * Fixed a concurrency issue in `TraverserSet` * Fixed a bug in `InlineFilterStrategy` that mixed up and's and or's when folding merging conditions together. diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py index 18598b7bff1..7eabd60757b 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 @@ -493,3 +493,19 @@ 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) + + +class TraversalMetricsDeserializer(_GraphSONTypeIO): + graphson_type = "g:TraversalMetrics" + + @classmethod + def objectify(cls, d, reader): + return reader.toObject(d) + + +class MetricsDeserializer(_GraphSONTypeIO): + graphson_type = "g:Metrics" + + @classmethod + def objectify(cls, d, reader): + return reader.toObject(d) diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py index 65e01afe96d..b120daf70b5 100644 --- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py +++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py @@ -580,3 +580,18 @@ class TDeserializer(_GraphSONTypeIO): @classmethod def objectify(cls, d, reader): return T[d] + +class TraversalMetricsDeserializer(_GraphSONTypeIO): + graphson_type = "g:TraversalMetrics" + + @classmethod + def objectify(cls, d, reader): + return reader.toObject(d) + + +class MetricsDeserializer(_GraphSONTypeIO): + graphson_type = "g:Metrics" + + @classmethod + def objectify(cls, d, reader): + return reader.toObject(d) 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 fda9808d621..cd8e1a0905a 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 @@ -65,8 +65,11 @@ def test_traversals(self, remote_connection): assert 2 == len(results) assert 'josh' in results assert 'peter' in results - # # todo: need a traversal metrics deserializer - g.V().out().profile().next() + # # + results = g.V().out().profile().toList() + assert 1 == len(results) + assert 'metrics' in results[0] + assert 'dur' in results[0] # # results = g.V().has('name', 'peter').as_('a').out('created').as_('b').select('a', 'b').by( __.valueMap()).toList() diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py index e6ea550a933..cd0905c0288 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 @@ -209,6 +209,18 @@ def test_uuid(self): assert isinstance(prop, uuid.UUID) assert str(prop) == '41d2e28a-20a4-4ab0-b379-d810dede3786' + def test_metrics(self): + prop = self.graphson_reader.readObject( + json.dumps([{'@type': 'g:TraversalMetrics', '@value': {'dur': 1.468594, 'metrics': [ + {'@type': 'g:Metrics', '@value': {'dur': 1.380957, 'counts': {}, 'name': 'GraphStep(__.V())', 'annotations': {'percentDur': 94.03259171697556}, 'id': '4.0.0()'}}, + {'@type': 'g:Metrics', '@value': {'dur': 0.087637, 'counts': {}, 'name': 'ReferenceElementStep', 'annotations': {'percentDur': 5.967408283024444}, 'id': '3.0.0()'}} + ]}}])) + assert isinstance(prop, list) + assert prop == [{'dur': 1.468594, 'metrics': [ + {'dur': 1.380957, 'counts': {}, 'name': 'GraphStep(__.V())', 'annotations': {'percentDur': 94.03259171697556}, 'id': '4.0.0()'}, + {'dur': 0.087637, 'counts': {}, 'name': 'ReferenceElementStep', 'annotations': {'percentDur': 5.967408283024444}, 'id': '3.0.0()'} + ]}] + class TestGraphSONWriter(object): graphson_writer = GraphSONWriter() diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py index f1268bd3df8..467ed2d6fd6 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 @@ -247,6 +247,18 @@ def test_uuid(self): assert isinstance(prop, uuid.UUID) assert str(prop) == '41d2e28a-20a4-4ab0-b379-d810dede3786' + def test_metrics(self): + prop = self.graphson_reader.readObject( + json.dumps([{'@type': 'g:TraversalMetrics', '@value': {'dur': 1.468594, 'metrics': [ + {'@type': 'g:Metrics', '@value': {'dur': 1.380957, 'counts': {}, 'name': 'GraphStep(__.V())', 'annotations': {'percentDur': 94.03259171697556}, 'id': '4.0.0()'}}, + {'@type': 'g:Metrics', '@value': {'dur': 0.087637, 'counts': {}, 'name': 'ReferenceElementStep', 'annotations': {'percentDur': 5.967408283024444}, 'id': '3.0.0()'}} + ]}}])) + assert isinstance(prop, list) + assert prop == [{'dur': 1.468594, 'metrics': [ + {'dur': 1.380957, 'counts': {}, 'name': 'GraphStep(__.V())', 'annotations': {'percentDur': 94.03259171697556}, 'id': '4.0.0()'}, + {'dur': 0.087637, 'counts': {}, 'name': 'ReferenceElementStep', 'annotations': {'percentDur': 5.967408283024444}, 'id': '3.0.0()'} + ]}] + class TestGraphSONWriter(object): graphson_writer = GraphSONWriter()