我正在运行 JanusGraph 0.3.1 并使用 gremlin python 3.3.4 和 python3.7



作为一种解决方法,当我有超过 64 个 id 需要传入 g.V(list_of_ids) 时,我目前正在传递 64 个 id。



模式和代码插入数据

// schema creation for graph named newg and traversal source g1

mgmt = newg.openManagement()

//make properties
type = mgmt.makePropertyKey('type').dataType(String.class).cardinality(org.janusgraph.core.Cardinality.SINGLE).make()
id_tx = mgmt.makePropertyKey('id_tx').dataType(String.class).cardinality(org.janusgraph.core.Cardinality.SINGLE).make()

// make vertex label
identity = mgmt.makeVertexLabel('identity').make()
mgmt.addProperties(identity, type, id_tx)

mgmt.commit()

// insert 65 vertices of the label identity

g1.addV('identity').property('id_tx','1').property('type','ecn')
g1.addV('identity').property('id_tx','2').property('type','ecn')
g1.addV('identity').property('id_tx','3').property('type','ecn')
g1.addV('identity').property('id_tx','4').property('type','ecn')
g1.addV('identity').property('id_tx','5').property('type','ecn')
g1.addV('identity').property('id_tx','6').property('type','ecn')
g1.addV('identity').property('id_tx','7').property('type','ecn')
g1.addV('identity').property('id_tx','8').property('type','ecn')
g1.addV('identity').property('id_tx','9').property('type','ecn')
g1.addV('identity').property('id_tx','10').property('type','ecn')
g1.addV('identity').property('id_tx','11').property('type','ecn')
g1.addV('identity').property('id_tx','12').property('type','ecn')
g1.addV('identity').property('id_tx','13').property('type','ecn')
g1.addV('identity').property('id_tx','14').property('type','ecn')
g1.addV('identity').property('id_tx','15').property('type','ecn')
g1.addV('identity').property('id_tx','16').property('type','ecn')
g1.addV('identity').property('id_tx','17').property('type','ecn')
g1.addV('identity').property('id_tx','18').property('type','ecn')
g1.addV('identity').property('id_tx','19').property('type','ecn')
g1.addV('identity').property('id_tx','20').property('type','ecn')
g1.addV('identity').property('id_tx','21').property('type','ecn')
g1.addV('identity').property('id_tx','22').property('type','ecn')
g1.addV('identity').property('id_tx','23').property('type','ecn')
g1.addV('identity').property('id_tx','24').property('type','ecn')
g1.addV('identity').property('id_tx','25').property('type','ecn')
g1.addV('identity').property('id_tx','26').property('type','ecn')
g1.addV('identity').property('id_tx','27').property('type','ecn')
g1.addV('identity').property('id_tx','28').property('type','ecn')
g1.addV('identity').property('id_tx','29').property('type','ecn')
g1.addV('identity').property('id_tx','30').property('type','ecn')
g1.addV('identity').property('id_tx','31').property('type','ecn')
g1.addV('identity').property('id_tx','32').property('type','ecn')
g1.addV('identity').property('id_tx','33').property('type','ecn')
g1.addV('identity').property('id_tx','34').property('type','ecn')
g1.addV('identity').property('id_tx','35').property('type','ecn')
g1.addV('identity').property('id_tx','36').property('type','ecn')
g1.addV('identity').property('id_tx','37').property('type','ecn')
g1.addV('identity').property('id_tx','38').property('type','ecn')
g1.addV('identity').property('id_tx','39').property('type','ecn')
g1.addV('identity').property('id_tx','40').property('type','ecn')
g1.addV('identity').property('id_tx','41').property('type','ecn')
g1.addV('identity').property('id_tx','42').property('type','ecn')
g1.addV('identity').property('id_tx','43').property('type','ecn')
g1.addV('identity').property('id_tx','44').property('type','ecn')
g1.addV('identity').property('id_tx','45').property('type','ecn')
g1.addV('identity').property('id_tx','46').property('type','ecn')
g1.addV('identity').property('id_tx','47').property('type','ecn')
g1.addV('identity').property('id_tx','48').property('type','ecn')
g1.addV('identity').property('id_tx','49').property('type','ecn')
g1.addV('identity').property('id_tx','50').property('type','ecn')
g1.addV('identity').property('id_tx','51').property('type','ecn')
g1.addV('identity').property('id_tx','52').property('type','ecn')
g1.addV('identity').property('id_tx','53').property('type','ecn')
g1.addV('identity').property('id_tx','54').property('type','ecn')
g1.addV('identity').property('id_tx','55').property('type','ecn')
g1.addV('identity').property('id_tx','56').property('type','ecn')
g1.addV('identity').property('id_tx','57').property('type','ecn')
g1.addV('identity').property('id_tx','58').property('type','ecn')
g1.addV('identity').property('id_tx','59').property('type','ecn')
g1.addV('identity').property('id_tx','60').property('type','ecn')
g1.addV('identity').property('id_tx','61').property('type','ecn')
g1.addV('identity').property('id_tx','62').property('type','ecn')
g1.addV('identity').property('id_tx','63').property('type','ecn')
g1.addV('identity').property('id_tx','64').property('type','ecn')
g1.addV('identity').property('id_tx','65').property('type','ecn')

gremlin> g1.tx().commit()
==>null
gremlin> g1.V().count()
==>65

现在我尝试使用 GLV 和 Script 方法从 python 查询。 GLV 方法似乎工作正常。
(py371local) bash-3.2$ python
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
# GLV method
>>> from gremlin_python import statics
>>> from gremlin_python.structure.graph import Graph
>>> from gremlin_python.process.graph_traversal import __
>>> from gremlin_python.process.strategies import *
>>> from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
>>> graph = Graph()
>>> g1 = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin', 'g1', username='<<user_id>>', password='<<password>>'))
>>> id_list = g1.V().id().toList()
>>> len(id_list)
65
>>> result = g1.V(id_list).valueMap(True).toList()
>>> result
[{'type': ['ecn'], <T.id: 1>: 28672, <T.label: 3>: 'identity', 'id_tx': ['31']}, {'type': ['ecn'], <T.id: 1>: 32792, <T.label: 3>: 'identity', 'id_tx': ['57']}, {'type': ['ecn'], <T.id: 1>: 28760, <T.label: 3>: 'identity', 'id_tx': ['52']}, {'type': ['ecn'], <T.id: 1>: 32768, <T.label: 3>: 'identity', 'id_tx': ['35']}, {'type': ['ecn'], <T.id: 1>: 12400, <T.label: 3>: 'identity', 'id_tx': ['41']}, {'type': ['ecn'], <T.id: 1>: 8344, <T.label: 3>: 'identity', 'id_tx': ['44']}, {'type': ['ecn'], <T.id: 1>: 8304, <T.label: 3>: 'identity', 'id_tx': ['19']}, {'type': ['ecn'], <T.id: 1>: 45192, <T.label: 3>: 'identity', 'id_tx': ['49']}, {'type': ['ecn'], <T.id: 1>: 28808, <T.label: 3>: 'identity', 'id_tx': ['32']}, {'type': ['ecn'], <T.id: 1>: 4160, <T.label: 3>: 'identity', 'id_tx': ['25']}, {'type': ['ecn'], <T.id: 1>: 24688, <T.label: 3>: 'identity', 'id_tx': ['51']}, {'type': ['ecn'], <T.id: 1>: 49288, <T.label: 3>: 'identity', 'id_tx': ['56']}, {'type': ['ecn'], <T.id: 1>: 4184, <T.label: 3>: 'identity', 'id_tx': ['8']}, {'type': ['ecn'], <T.id: 1>: 8328, <T.label: 3>: 'identity', 'id_tx': ['6']}, {'type': ['ecn'], <T.id: 1>: 16480, <T.label: 3>: 'identity', 'id_tx': ['30']}, {'type': ['ecn'], <T.id: 1>: 24600, <T.label: 3>: 'identity', 'id_tx': ['33']}, {'type': ['ecn'], <T.id: 1>: 20576, <T.label: 3>: 'identity', 'id_tx': ['34']}, {'type': ['ecn'], <T.id: 1>: 12312, <T.label: 3>: 'identity', 'id_tx': ['7']}, {'type': ['ecn'], <T.id: 1>: 8216, <T.label: 3>: 'identity', 'id_tx': ['5']}, {'type': ['ecn'], <T.id: 1>: 20616, <T.label: 3>: 'identity', 'id_tx': ['27']}, {'type': ['ecn'], <T.id: 1>: 16408, <T.label: 3>: 'identity', 'id_tx': ['10']}, {'type': ['ecn'], <T.id: 1>: 4120, <T.label: 3>: 'identity', 'id_tx': ['3']}, {'type': ['ecn'], <T.id: 1>: 20504, <T.label: 3>: 'identity', 'id_tx': ['18']}, {'type': ['ecn'], <T.id: 1>: 24728, <T.label: 3>: 'identity', 'id_tx': ['17']}, {'type': ['ecn'], <T.id: 1>: 53384, <T.label: 3>: 'identity', 'id_tx': ['59']}, {'type': ['ecn'], <T.id: 1>: 4192, <T.label: 3>: 'identity', 'id_tx': ['2']}, {'type': ['ecn'], <T.id: 1>: 32856, <T.label: 3>: 'identity', 'id_tx': ['61']}, {'type': ['ecn'], <T.id: 1>: 4096, <T.label: 3>: 'identity', 'id_tx': ['9']}, {'type': ['ecn'], <T.id: 1>: 24712, <T.label: 3>: 'identity', 'id_tx': ['29']}, {'type': ['ecn'], <T.id: 1>: 41096, <T.label: 3>: 'identity', 'id_tx': ['46']}, {'type': ['ecn'], <T.id: 1>: 36952, <T.label: 3>: 'identity', 'id_tx': ['64']}, {'type': ['ecn'], <T.id: 1>: 28696, <T.label: 3>: 'identity', 'id_tx': ['48']}, {'type': ['ecn'], <T.id: 1>: 32904, <T.label: 3>: 'identity', 'id_tx': ['36']}, {'type': ['ecn'], <T.id: 1>: 36864, <T.label: 3>: 'identity', 'id_tx': ['37']}, {'type': ['ecn'], <T.id: 1>: 24672, <T.label: 3>: 'identity', 'id_tx': ['45']}, {'type': ['ecn'], <T.id: 1>: 49152, <T.label: 3>: 'identity', 'id_tx': ['50']}, {'type': ['ecn'], <T.id: 1>: 8256, <T.label: 3>: 'identity', 'id_tx': ['38']}, {'type': ['ecn'], <T.id: 1>: 24664, <T.label: 3>: 'identity', 'id_tx': ['28']}, {'type': ['ecn'], <T.id: 1>: 16496, <T.label: 3>: 'identity', 'id_tx': ['43']}, {'type': ['ecn'], <T.id: 1>: 57344, <T.label: 3>: 'identity', 'id_tx': ['65']}, {'type': ['ecn'], <T.id: 1>: 53248, <T.label: 3>: 'identity', 'id_tx': ['58']}, {'type': ['ecn'], <T.id: 1>: 57480, <T.label: 3>: 'identity', 'id_tx': ['62']}, {'type': ['ecn'], <T.id: 1>: 8280, <T.label: 3>: 'identity', 'id_tx': ['16']}, {'type': ['ecn'], <T.id: 1>: 12288, <T.label: 3>: 'identity', 'id_tx': ['13']}, {'type': ['ecn'], <T.id: 1>: 4232, <T.label: 3>: 'identity', 'id_tx': ['1']}, {'type': ['ecn'], <T.id: 1>: 12376, <T.label: 3>: 'identity', 'id_tx': ['20']}, {'type': ['ecn'], <T.id: 1>: 16536, <T.label: 3>: 'identity', 'id_tx': ['55']}, {'type': ['ecn'], <T.id: 1>: 16520, <T.label: 3>: 'identity', 'id_tx': ['21']}, {'type': ['ecn'], <T.id: 1>: 8288, <T.label: 3>: 'identity', 'id_tx': ['12']}, {'type': ['ecn'], <T.id: 1>: 45056, <T.label: 3>: 'identity', 'id_tx': ['42']}, {'type': ['ecn'], <T.id: 1>: 16472, <T.label: 3>: 'identity', 'id_tx': ['23']}, {'type': ['ecn'], <T.id: 1>: 37000, <T.label: 3>: 'identity', 'id_tx': ['40']}, {'type': ['ecn'], <T.id: 1>: 40960, <T.label: 3>: 'identity', 'id_tx': ['39']}, {'type': ['ecn'], <T.id: 1>: 20632, <T.label: 3>: 'identity', 'id_tx': ['60']}, {'type': ['ecn'], <T.id: 1>: 20568, <T.label: 3>: 'identity', 'id_tx': ['26']}, {'type': ['ecn'], <T.id: 1>: 12424, <T.label: 3>: 'identity', 'id_tx': ['15']}, {'type': ['ecn'], <T.id: 1>: 12440, <T.label: 3>: 'identity', 'id_tx': ['53']}, {'type': ['ecn'], <T.id: 1>: 20592, <T.label: 3>: 'identity', 'id_tx': ['47']}, {'type': ['ecn'], <T.id: 1>: 4248, <T.label: 3>: 'identity', 'id_tx': ['14']}, {'type': ['ecn'], <T.id: 1>: 4208, <T.label: 3>: 'identity', 'id_tx': ['4']}, {'type': ['ecn'], <T.id: 1>: 8192, <T.label: 3>: 'identity', 'id_tx': ['11']}, {'type': ['ecn'], <T.id: 1>: 24576, <T.label: 3>: 'identity', 'id_tx': ['24']}, {'type': ['ecn'], <T.id: 1>: 12352, <T.label: 3>: 'identity', 'id_tx': ['63']}, {'type': ['ecn'], <T.id: 1>: 20480, <T.label: 3>: 'identity', 'id_tx': ['22']}, {'type': ['ecn'], <T.id: 1>: 28768, <T.label: 3>: 'identity', 'id_tx': ['54']}]
>>> len(result)
65
>>> query = "g1.V(id_list).valueMap(True).toList()"
>>> query_bindings = {"id_list": id_list}

#  Now Try using the script method
>>> from gremlin_python.driver import client
>>> from gremlin_python.driver.serializer import GraphSONSerializersV3d0
>>> db_session = client.Client('ws://localhost:8182/gremlin', 'g1', message_serializer=GraphSONSerializersV3d0(), username="<<user_id>>", password="<<password>>")
>>> query = "g1.V(id_list).valueMap(true).toList()"
>>> result = db_session.submit(query, query_bindings).all().result()
>>> result
[{'type': ['ecn'], <T.id: 1>: 28672, <T.label: 3>: 'identity', 'id_tx': ['31']}, {'type': ['ecn'], <T.id: 1>: 32792, <T.label: 3>: 'identity', 'id_tx': ['57']}, {'type': ['ecn'], <T.id: 1>: 28760, <T.label: 3>: 'identity', 'id_tx': ['52']}, {'type': ['ecn'], <T.id: 1>: 32768, <T.label: 3>: 'identity', 'id_tx': ['35']}, {'type': ['ecn'], <T.id: 1>: 12400, <T.label: 3>: 'identity', 'id_tx': ['41']}, {'type': ['ecn'], <T.id: 1>: 8344, <T.label: 3>: 'identity', 'id_tx': ['44']}, {'type': ['ecn'], <T.id: 1>: 8304, <T.label: 3>: 'identity', 'id_tx': ['19']}, {'type': ['ecn'], <T.id: 1>: 45192, <T.label: 3>: 'identity', 'id_tx': ['49']}, {'type': ['ecn'], <T.id: 1>: 28808, <T.label: 3>: 'identity', 'id_tx': ['32']}, {'type': ['ecn'], <T.id: 1>: 4160, <T.label: 3>: 'identity', 'id_tx': ['25']}, {'type': ['ecn'], <T.id: 1>: 24688, <T.label: 3>: 'identity', 'id_tx': ['51']}, {'type': ['ecn'], <T.id: 1>: 49288, <T.label: 3>: 'identity', 'id_tx': ['56']}, {'type': ['ecn'], <T.id: 1>: 4184, <T.label: 3>: 'identity', 'id_tx': ['8']}, {'type': ['ecn'], <T.id: 1>: 8328, <T.label: 3>: 'identity', 'id_tx': ['6']}, {'type': ['ecn'], <T.id: 1>: 16480, <T.label: 3>: 'identity', 'id_tx': ['30']}, {'type': ['ecn'], <T.id: 1>: 24600, <T.label: 3>: 'identity', 'id_tx': ['33']}, {'type': ['ecn'], <T.id: 1>: 20576, <T.label: 3>: 'identity', 'id_tx': ['34']}, {'type': ['ecn'], <T.id: 1>: 12312, <T.label: 3>: 'identity', 'id_tx': ['7']}, {'type': ['ecn'], <T.id: 1>: 8216, <T.label: 3>: 'identity', 'id_tx': ['5']}, {'type': ['ecn'], <T.id: 1>: 20616, <T.label: 3>: 'identity', 'id_tx': ['27']}, {'type': ['ecn'], <T.id: 1>: 16408, <T.label: 3>: 'identity', 'id_tx': ['10']}, {'type': ['ecn'], <T.id: 1>: 4120, <T.label: 3>: 'identity', 'id_tx': ['3']}, {'type': ['ecn'], <T.id: 1>: 20504, <T.label: 3>: 'identity', 'id_tx': ['18']}, {'type': ['ecn'], <T.id: 1>: 24728, <T.label: 3>: 'identity', 'id_tx': ['17']}, {'type': ['ecn'], <T.id: 1>: 53384, <T.label: 3>: 'identity', 'id_tx': ['59']}, {'type': ['ecn'], <T.id: 1>: 4192, <T.label: 3>: 'identity', 'id_tx': ['2']}, {'type': ['ecn'], <T.id: 1>: 32856, <T.label: 3>: 'identity', 'id_tx': ['61']}, {'type': ['ecn'], <T.id: 1>: 4096, <T.label: 3>: 'identity', 'id_tx': ['9']}, {'type': ['ecn'], <T.id: 1>: 24712, <T.label: 3>: 'identity', 'id_tx': ['29']}, {'type': ['ecn'], <T.id: 1>: 41096, <T.label: 3>: 'identity', 'id_tx': ['46']}, {'type': ['ecn'], <T.id: 1>: 36952, <T.label: 3>: 'identity', 'id_tx': ['64']}, {'type': ['ecn'], <T.id: 1>: 28696, <T.label: 3>: 'identity', 'id_tx': ['48']}, {'type': ['ecn'], <T.id: 1>: 32904, <T.label: 3>: 'identity', 'id_tx': ['36']}, {'type': ['ecn'], <T.id: 1>: 36864, <T.label: 3>: 'identity', 'id_tx': ['37']}, {'type': ['ecn'], <T.id: 1>: 24672, <T.label: 3>: 'identity', 'id_tx': ['45']}, {'type': ['ecn'], <T.id: 1>: 49152, <T.label: 3>: 'identity', 'id_tx': ['50']}, {'type': ['ecn'], <T.id: 1>: 8256, <T.label: 3>: 'identity', 'id_tx': ['38']}, {'type': ['ecn'], <T.id: 1>: 24664, <T.label: 3>: 'identity', 'id_tx': ['28']}, {'type': ['ecn'], <T.id: 1>: 16496, <T.label: 3>: 'identity', 'id_tx': ['43']}, {'type': ['ecn'], <T.id: 1>: 57344, <T.label: 3>: 'identity', 'id_tx': ['65']}, {'type': ['ecn'], <T.id: 1>: 53248, <T.label: 3>: 'identity', 'id_tx': ['58']}, {'type': ['ecn'], <T.id: 1>: 57480, <T.label: 3>: 'identity', 'id_tx': ['62']}, {'type': ['ecn'], <T.id: 1>: 8280, <T.label: 3>: 'identity', 'id_tx': ['16']}, {'type': ['ecn'], <T.id: 1>: 12288, <T.label: 3>: 'identity', 'id_tx': ['13']}, {'type': ['ecn'], <T.id: 1>: 4232, <T.label: 3>: 'identity', 'id_tx': ['1']}, {'type': ['ecn'], <T.id: 1>: 12376, <T.label: 3>: 'identity', 'id_tx': ['20']}, {'type': ['ecn'], <T.id: 1>: 16536, <T.label: 3>: 'identity', 'id_tx': ['55']}, {'type': ['ecn'], <T.id: 1>: 16520, <T.label: 3>: 'identity', 'id_tx': ['21']}, {'type': ['ecn'], <T.id: 1>: 8288, <T.label: 3>: 'identity', 'id_tx': ['12']}, {'type': ['ecn'], <T.id: 1>: 45056, <T.label: 3>: 'identity', 'id_tx': ['42']}, {'type': ['ecn'], <T.id: 1>: 16472, <T.label: 3>: 'identity', 'id_tx': ['23']}, {'type': ['ecn'], <T.id: 1>: 37000, <T.label: 3>: 'identity', 'id_tx': ['40']}, {'type': ['ecn'], <T.id: 1>: 40960, <T.label: 3>: 'identity', 'id_tx': ['39']}, {'type': ['ecn'], <T.id: 1>: 20632, <T.label: 3>: 'identity', 'id_tx': ['60']}, {'type': ['ecn'], <T.id: 1>: 20568, <T.label: 3>: 'identity', 'id_tx': ['26']}, {'type': ['ecn'], <T.id: 1>: 12424, <T.label: 3>: 'identity', 'id_tx': ['15']}, {'type': ['ecn'], <T.id: 1>: 12440, <T.label: 3>: 'identity', 'id_tx': ['53']}, {'type': ['ecn'], <T.id: 1>: 20592, <T.label: 3>: 'identity', 'id_tx': ['47']}, {'type': ['ecn'], <T.id: 1>: 4248, <T.label: 3>: 'identity', 'id_tx': ['14']}, {'type': ['ecn'], <T.id: 1>: 4208, <T.label: 3>: 'identity', 'id_tx': ['4']}, {'type': ['ecn'], <T.id: 1>: 8192, <T.label: 3>: 'identity', 'id_tx': ['11']}, {'type': ['ecn'], <T.id: 1>: 24576, <T.label: 3>: 'identity', 'id_tx': ['24']}, {'type': ['ecn'], <T.id: 1>: 12352, <T.label: 3>: 'identity', 'id_tx': ['63']}, {'type': ['ecn'], <T.id: 1>: 20480, <T.label: 3>: 'identity', 'id_tx': ['22']}]
>>> len(result)
64
>>>
# We see only 64 returned instead of 65

最佳答案

数字 64 很有趣,因为这是默认的批量迭代大小 defined by the server : resultIterationBatchSize 。我会尝试将该数字提高到 100,然后重新启动服务器并查看是否获得了全部 65 个结果。

也就是说,您不需要这样做 - 如果您的结果超过 resultIterationBatchSize,服务器应自动继续生成下一批并将其流式传输到您的客户端。我似乎记得很久以前的一个问题。我无法确定代码中的更改,但我记得添加了这个测试:

https://github.com/apache/tinkerpop/commit/425bcd032adc9967a6b575da8042df3806671825

它处理需要流式传输的大型结果。请考虑使用 gremlinpython 3.3.5 以查看是否能解决问题。如果这不起作用,请尝试使用 TinkerGraph 在 Gremlin Server 中重新创建问题,一旦您有良好的重现步骤,请将问题提交给 JIRA

关于python - Gremlin Python - 基于脚本的方法不返回所有 - JanusGraph,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55173654/

10-13 02:11