This is an automated email from the ASF dual-hosted git repository. kenhuuu pushed a commit to branch master-http-final in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 3df602bd2ec025afab2b6a64295a9449f041487f Author: Yang Xia <[email protected]> AuthorDate: Thu Oct 31 18:36:29 2024 -0700 CTR remove unsupported types in GraphSONv4 in gremlin-python --- .../gremlin_python/structure/io/graphsonV4.py | 135 +-------------------- .../python/tests/structure/io/test_graphsonV4.py | 59 --------- 2 files changed, 6 insertions(+), 188 deletions(-) diff --git a/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py b/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py index d20d3b4e31..87183d420f 100644 --- a/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py +++ b/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py @@ -147,32 +147,6 @@ class _GraphSONTypeIO(object, metaclass=GraphSONTypeType): raise NotImplementedError() -class _BytecodeSerializer(_GraphSONTypeIO): - @classmethod - def _dictify_instructions(cls, instructions, writer): - out = [] - for instruction in instructions: - inst = [instruction[0]] - inst.extend(writer.to_dict(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.typed_value("Bytecode", out) - - -class TraversalSerializer(_BytecodeSerializer): - python_type = Traversal - - class VertexSerializer(_GraphSONTypeIO): python_type = Vertex graphson_type = "g:Vertex" @@ -222,71 +196,6 @@ class PropertySerializer(_GraphSONTypeIO): "value": writer.to_dict(property.value)}) -class TraversalStrategySerializer(_GraphSONTypeIO): - python_type = TraversalStrategy - - @classmethod - def dictify(cls, strategy, writer): - configuration = {} - for key in strategy.configuration: - configuration[key] = writer.to_dict(strategy.configuration[key]) - return GraphSONUtil.typed_value(strategy.strategy_name, configuration) - - -class TraverserIO(_GraphSONTypeIO): - python_type = Traverser - graphson_type = "g:Traverser" - - @classmethod - def dictify(cls, traverser, writer): - return GraphSONUtil.typed_value("Traverser", {"value": writer.to_dict(traverser.object), - "bulk": writer.to_dict(traverser.bulk)}) - - @classmethod - def objectify(cls, d, reader): - return Traverser(reader.to_object(d["value"]), - reader.to_object(d["bulk"])) - - -class EnumSerializer(_GraphSONTypeIO): - python_type = Enum - - @classmethod - def dictify(cls, enum, _): - return GraphSONUtil.typed_value(SymbolUtil.to_camel_case(type(enum).__name__), - SymbolUtil.to_camel_case(str(enum.name))) - - -class PSerializer(_GraphSONTypeIO): - python_type = P - - @classmethod - def dictify(cls, p, writer): - out = {"predicate": p.operator, - "value": [writer.to_dict(p.value), writer.to_dict(p.other)] if p.other is not None else - writer.to_dict(p.value)} - return GraphSONUtil.typed_value("P", out) - - -class TextPSerializer(_GraphSONTypeIO): - python_type = TextP - - @classmethod - def dictify(cls, p, writer): - out = {"predicate": p.operator, - "value": [writer.to_dict(p.value), writer.to_dict(p.other)] if p.other is not None else - writer.to_dict(p.value)} - return GraphSONUtil.typed_value("TextP", out) - - -class TypeSerializer(_GraphSONTypeIO): - python_type = TypeType - - @classmethod - def dictify(cls, typ, writer): - return writer.to_dict(typ()) - - class UUIDIO(_GraphSONTypeIO): python_type = uuid.UUID graphson_type = "g:UUID" @@ -403,27 +312,6 @@ class MapType(_GraphSONTypeIO): return new_dict -class BulkSetIO(_GraphSONTypeIO): - graphson_type = "g:BulkSet" - - @classmethod - def objectify(cls, l, reader): - new_list = [] - - # this approach basically mimics what currently existed in 3.3.4 and prior versions where BulkSet is - # basically just coerced to list. the limitation here is that if the value of a bulk exceeds the size of - # a list (into the long space) then stuff won't work nice. - if len(l) > 0: - x = 0 - while x < len(l): - obj = reader.to_object(l[x]) - bulk = reader.to_object(l[x + 1]) - for y in range(bulk): - new_list.append(obj) - x = x + 2 - return new_list - - class FloatIO(_NumberIO): python_type = FloatType graphson_type = "g:Float" @@ -664,9 +552,14 @@ class PathDeserializer(_GraphSONTypeIO): return Path(reader.to_object(d["labels"]), reader.to_object(d["objects"])) -class TDeserializer(_GraphSONTypeIO): +class TIO(_GraphSONTypeIO): graphson_type = "g:T" + graphson_base_type = "T" + python_type = T + @classmethod + def dictify(cls, t, writer): + return GraphSONUtil.typed_value(cls.graphson_base_type, t.name, "g") @classmethod def objectify(cls, d, reader): return T[d] @@ -684,19 +577,3 @@ class DirectionIO(_GraphSONTypeIO): @classmethod def objectify(cls, d, reader): return Direction[d] - - -class TraversalMetricsDeserializer(_GraphSONTypeIO): - graphson_type = "g:TraversalMetrics" - - @classmethod - def objectify(cls, d, reader): - return reader.to_object(d) - - -class MetricsDeserializer(_GraphSONTypeIO): - graphson_type = "g:Metrics" - - @classmethod - def objectify(cls, d, reader): - return reader.to_object(d) diff --git a/gremlin-python/src/main/python/tests/structure/io/test_graphsonV4.py b/gremlin-python/src/main/python/tests/structure/io/test_graphsonV4.py index 44b2fa7187..7d88e73782 100644 --- a/gremlin-python/src/main/python/tests/structure/io/test_graphsonV4.py +++ b/gremlin-python/src/main/python/tests/structure/io/test_graphsonV4.py @@ -77,15 +77,6 @@ class TestGraphSONReader: assert x['b'] == "marko" assert len(x) == 2 - # BulkSet gets coerced to a List - both have the same behavior - x = self.graphson_reader.read_object( - json.dumps({"@type": "g:BulkSet", - "@value": ["marko", {"@type": "g:Int64", "@value": 1}, "josh", {"@type": "g:Int64", "@value": 3}]})) - assert isinstance(x, list) - assert len(x) == 4 - assert x.count("marko") == 1 - assert x.count("josh") == 3 - def test_number_input(self): x = self.graphson_reader.read_object(json.dumps({ "@type": "g:Byte", @@ -290,18 +281,6 @@ class TestGraphSONReader: assert isinstance(prop, uuid.UUID) assert str(prop) == '41d2e28a-20a4-4ab0-b379-d810dede3786' - def test_metrics(self): - prop = self.graphson_reader.read_object( - 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()'} - ]}] - def test_binary(self): bb = self.graphson_reader.read_object( json.dumps({"@type": "g:Binary", "@value": "c29tZSBieXRlcyBmb3IgeW91"})) @@ -356,47 +335,9 @@ class TestGraphSONWriter: assert """true""" == self.graphson_writer.write_object(True) def test_enum(self): - assert {"@type": "g:Merge", "@value": "onMatch"} == json.loads(self.graphson_writer.write_object(Merge.on_match)) - assert {"@type": "g:Order", "@value": "shuffle"} == json.loads(self.graphson_writer.write_object(Order.shuffle)) - assert {"@type": "g:Barrier", "@value": "normSack"} == json.loads(self.graphson_writer.write_object(Barrier.norm_sack)) - assert {"@type": "g:Operator", "@value": "sum"} == json.loads(self.graphson_writer.write_object(Operator.sum_)) - assert {"@type": "g:Operator", "@value": "sumLong"} == json.loads(self.graphson_writer.write_object(Operator.sum_long)) assert {"@type": "g:Direction", "@value": "OUT"} == json.loads(self.graphson_writer.write_object(Direction.OUT)) assert {"@type": "g:Direction", "@value": "OUT"} == json.loads(self.graphson_writer.write_object(Direction.from_)) - 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.write_object(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.write_object(P.within([1, 2]))) - assert result == json.loads(self.graphson_writer.write_object(P.within({1, 2}))) - assert result == json.loads(self.graphson_writer.write_object(P.within(1, 2))) - - result = {'@type': 'g:P', '@value': {'predicate': 'within', 'value': {'@type': 'g:List', '@value': [ - {"@type": "g:Int32", "@value": 1}]}}} - assert result == json.loads(self.graphson_writer.write_object(P.within([1]))) - assert result == json.loads(self.graphson_writer.write_object(P.within({1}))) - assert result == json.loads(self.graphson_writer.write_object(P.within(1))) - def test_graph(self): assert {"@type": "g:Vertex", "@value": {"id": {"@type": "g:Int64", "@value": 12}, "label": ["person"]}} == json.loads(
