【问题标题】:Bulk upsert in gremlin_python fails with "TypeError: 'GraphTraversal' object is not callable"gremlin_python 中的批量 upsert 失败并出现 \"TypeError: \'GraphTraversal\' object is not callable\"
【发布时间】:2022-10-17 10:18:29
【问题描述】:

我是 Gremlin 的新手,并尝试使用 gremlin_python 在海王星数据库中执行批量 upsert。

我在google groups 找到了这个解决方案

l = [
  [name:'josh',age:29,country:'usa'],
  [name:'bar',age:24,country:'usa']];
 
g.inject(l).
 unfold().as('properties').
 select('name').as('pName').
 coalesce(V().has('name', where(eq('pName'))),
     addV('person')).as('vertex').
 sideEffect(select('properties').
              unfold().as('kv').
              select('vertex').
              property(select('kv').by(Column.keys), select('kv').by(Column.values)))

并尝试像这样将其改编为 gremlin_python :

l = [
  {'name':'josh','age':29,'country':'usa'},
  {'name':'bar','age':24,'country':'usa'}];
 
g.inject(l).\
 unfold().as_('properties').\
 select('name').as_('pName').\
 coalesce(__.V().has('name', __.where(__.eq('pName'))),
     addV('person')).as_('vertex').\
 sideEffect(select('properties').\
              unfold().as_('kv').\
              select('vertex').\
              property(select('kv').by(Column.keys), select('kv').by(Column.values)))

有以下错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-162-c262a63ad82e> in <module>
      8  unfold().as_('properties').\
      9  select('name').as_('pName').\
---> 10  coalesce(__.V().has('name', __.where(__.eq('pName'))),
     11      addV('person')).as_('vertex').\
     12  sideEffect(select('properties').\

TypeError: 'GraphTraversal' object is not callable

我认为代码改编可能是错误的。 谁能给我一个关于这里发生了什么的提示?

【问题讨论】:

    标签: gremlin amazon-neptune gremlinpython


    【解决方案1】:

    __.eq('pName') 部分应该是 statics.eq('pName')。

    from gremlin_python import statics
    statics.load_statics(globals())
    

    部分 __.eq('pName') 可以只是 eq('pName')。

    见:https://tinkerpop.apache.org/docs/current/reference/#gremlin-python-imports

    【讨论】:

    • P.eq 应该可以正常工作。
    【解决方案2】:

    由于我使用的是 AWS Neptune DB,因此我最终应用了 Neptune Python utils 来进行批量更新: 它比我们讨论的解决方案更快,但在使用时要小心数据类型和映射。 (我遇到了 BigInts 的问题)

    这是库和文档: https://github.com/awslabs/amazon-neptune-tools/tree/master/neptune-python-utils

    【讨论】:

      猜你喜欢
      • 2014-11-16
      • 2018-03-31
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      相关资源
      最近更新 更多