为什么 运行 tinkergraph 和 janusgraph 的相同查询会产生不同的结果?

Why running same query for tinkergraph and janusgraph, produces different result?

我尝试使用 Gremlin 和 Tinkerpop 进行查询

gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = traversal().withEmbedded(graph)
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> v = g.addV().property('name','marko').property('name','marko a. rodriguez').next()
==>v[0]
gremlin> g.V(v).properties('name').count()
==>2
gremlin>

当我 运行 与 Gremlin-Python 和 Janusgraph 相同时,收到以下内容。

>>> v = g.addV().property('name','marko').property('name','marko a. rodriguez').next()
>>> g.V(v).properties('name').count().next()
1

我的问题是,为什么我收到不同的结果。 在第一种情况下输出为 2,但在第二种情况下输出为 1.

我也尝试 运行 以下查询以进行更多探索,并找到以下结果。

使用 Gremlin 和 TinkerpopGraph

gremlin> g.V(v).values('name')
==>marko
==>marko a. rodriguez
gremlin>

使用 Gremlin-Python 和 JanusGraph

>>> g.V(v).values('name').next()
'marko a. rodriguez'

当我尝试使用 gremlin 和 Janusgraph 进行以下操作时,它有效

gremlin> v = g.addV().property(list,'p_name','marko').property(list,'p_name','marko a. rodriguez').next()
==>v[12344]
gremlin> g.V(v).properties('p_name').count()
==>0

但是 运行在 gremlin-python 中得到相同的结果给了我错误。

>>> v = g.addV().property(list,'p_name','marko').property(list,'p_name','marko a. rodriguez').next()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sumit/.local/lib/python3.9/site-packages/gremlin_python/process/traversal.py", line 88, in next
    return self.__next__()
  File "/home/sumit/.local/lib/python3.9/site-packages/gremlin_python/process/traversal.py", line 47, in __next__
    self.traversal_strategies.apply_strategies(self)
  File "/home/sumit/.local/lib/python3.9/site-packages/gremlin_python/process/traversal.py", line 548, in apply_strategies
    traversal_strategy.apply(traversal)
  File "/home/sumit/.local/lib/python3.9/site-packages/gremlin_python/driver/remote_connection.py", line 63, in apply
    remote_traversal = self.remote_connection.submit(traversal.bytecode)
  File "/home/sumit/.local/lib/python3.9/site-packages/gremlin_python/driver/driver_remote_connection.py", line 60, in submit
    results = result_set.all().result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 440, in result
    return self.__get_result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/home/sumit/.local/lib/python3.9/site-packages/gremlin_python/driver/resultset.py", line 90, in cb
    f.result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 433, in result
    return self.__get_result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/sumit/.local/lib/python3.9/site-packages/gremlin_python/driver/connection.py", line 83, in _receive
    status_code = self._protocol.data_received(data, self._results)
  File "/home/sumit/.local/lib/python3.9/site-packages/gremlin_python/driver/protocol.py", line 131, in data_received
    raise GremlinServerError(message['status'])
gremlin_python.driver.protocol.GremlinServerError: 599: null: .property(ArrayList, String, String)

599: null: .property(ArrayList, String, String)

我相信您看到的是 TinkerGraph 的一种特殊情况,如果您在创建顶点的同时使用相同的键创建两个属性,则会假定列表基数。如果您要在一个已经存在的顶点上执行相同的 属性 加法,将假定单一基数并且一个将替换另一个。例如:

gremlin> g.addV('xyz')
==>v[3]

gremlin> 
g.V().hasLabel('xyz').property('name','me').property('name','me2').valueMap()
==>[name:[me2]]  

关于您的 Python 错误,list 是一个 Python 保留字。尝试使用 Cardinality.list

一般来说,如果您打算创建一个列表或集合,请明确使用基数值以确保您获得预期的结果。