当使用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
发布于 2020-05-12 11:50:45
JanusGraph将RelationIdentifier序列化为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://stackoverflow.com/questions/61700938
复制相似问题