0

使用 gremlinpython 时,是否可以返回边的 ID 列表,而不是返回这个冗长的字典?

所以,目前g.E().limit(10).id().toList()返回这个:

[{'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': '4g09-20qw-2dx-1l1c'}},
 {'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': '5hxx-9x9k-2dx-4qo8'}},
 {'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': 'cljk-qikg-2dx-pzls'}},
 {'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': '4vth-1xns-2dx-8940'}},
 {'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': '5f61-bex4-2dx-sgw'}},
 {'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': '5xc3-ag48-2dx-a6og'}},
 {'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': '5xc6-4awg-2dx-f6v4'}},
 {'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': 'bwnk-k0ow-2dx-7dio'}},
 {'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': '5lhi-pbk-2dx-2wfc'}},
 {'@type': 'janusgraph:RelationIdentifier',
  '@value': {'relationId': '5d6x-avyg-2dx-7gns'}}]

但相反,我希望它返回这个:

['4g09-20qw-2dx-1l1c', '5hxx-9x9k-2dx-4qo8', 'cljk-qikg-2dx-pzls', '4vth-1xns-2dx-8940', '5f61-bex4-2dx-sgw', '5xc3-ag48-2dx-a6og', '5xc6-4awg-2dx-f6v4', 'bwnk-k0ow-2dx-7dio', '5lhi-pbk-2dx-2wfc', '5d6x-avyg-2dx-7gns']

这在 gremlin 控制台中按预期工作。

Python3.7、gremlinpython==3.4.2

4

1 回答 1

2

JanusGraph 将 序列化为RelationIdentifiera Map- 您可以在此处查看代码。此结果与您在 Gremlin 控制台中获得的结果不同,因为控制台使用了一个特殊的“ToString”序列化程序,该序列化程序仅调用toString()从服务器发送回它的每个结果项的方法。

我能想到的最简单的解决方法是在 Python 中为“janusgraph:RelationIdentifier”编写自己的反序列化器,然后将其添加到您正在使用的 GraphSON 版本的反序列化器列表中。我没有对此进行测试,但我想代码看起来像:

class RelationIdentifierJanusDeserializer(_GraphSONTypeIO):
    graphson_type = "janusgraph:RelationIdentifier"

    @classmethod
    def objectify(cls, d, reader):
        return str(d)

这是一个演示如何添加自定义序列化程序以及如何覆盖的测试:

https://github.com/apache/tinkerpop/blob/5c91324afeedf7e233c93181423fea285a76d1d1/gremlin-python/src/main/python/tests/structure/io/test_graphsonV3d0.py#L255-L286

于 2020-05-12T11:50:45.800 回答