gremlinpython-从边缘获取ID作为简单列表而不是字典

gremlinpython-从边缘获取ID作为简单列表而不是字典,gremlin,janusgraph,gremlinpython,Gremlin,Janusgraph,Gremlinpython,使用gremlinpython时,是否可以只返回边的ID列表,而不返回这个冗长的字典 因此,当前g.E().limit(10).id().toList()返回以下内容: [{'@type': 'janusgraph:RelationIdentifier', '@value': {'relationId': '4g09-20qw-2dx-1l1c'}}, {'@type': 'janusgraph:RelationIdentifier', '@value': {'relationId':

使用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

JanusGraph将
关系标识符
序列化为
映射
-您可以看到代码。此结果与在Gremlin控制台中得到的结果不同,因为控制台使用一个特殊的“ToString”序列化程序,该序列化程序仅对从服务器发送回它的每个结果项调用
ToString()
方法

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

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

    @classmethod
    def objectify(cls, d, reader):
        return str(d)
下面的测试演示了如何添加自定义序列化程序以及如何重写自定义序列化程序:


JanusGraph将
关系标识符
序列化为
映射
-您可以看到代码。此结果与在Gremlin控制台中得到的结果不同,因为控制台使用一个特殊的“ToString”序列化程序,该序列化程序仅对从服务器发送回它的每个结果项调用
ToString()
方法

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

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

    @classmethod
    def objectify(cls, d, reader):
        return str(d)
下面的测试演示了如何添加自定义序列化程序以及如何重写自定义序列化程序:


我想JanusGraph一定是因为某种原因才这么退的。我用GremlinPython、TinkerGraph/GremlinServer和Amazon Neptune尝试了您的查询,我得到了预期的ID列表。谢谢Kevin,我也确定问题出在JanusGraph上。我想知道他们为什么决定以这种方式返回ID。您使用的是哪种后端存储不确定这是否重要,但使用“inmemory”可能值得一次快速测试,以排除一些后端奇怪之处。奇怪的是,控制台提供了您所期望的东西,但Python没有。我认为JanusGraph一定是出于某种原因以这种方式返回的。我用GremlinPython、TinkerGraph/GremlinServer和Amazon Neptune尝试了您的查询,我得到了预期的ID列表。谢谢Kevin,我也确定问题出在JanusGraph上。我想知道他们为什么决定以这种方式返回ID。您使用的是哪种后端存储不确定这是否重要,但使用“inmemory”可能值得一次快速测试,以排除一些后端奇怪之处。奇怪的是,控制台提供了您所期望的东西,但Python却没有。