2

I am new to Gremlin and trying to perform bulk upsert in neptune db with gremlin_python.

I found this solution in 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)))

And tried to adapt it for gremlin_python like this:

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)))

having following error:

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

I assume the code adaptation might be wrong. Can anyone give me a hint about what is going on here?

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
Yury Lvov
  • 21
  • 2

2 Answers2

2

The part __.eq('pName') should be statics.eq('pName').

After

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

The part __.eq('pName') can be just eq('pName').

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

HadoopMarc
  • 1,356
  • 3
  • 11
0

Since I use the AWS Neptune DB, I ended up applying Neptune Python utils to make bulk upsert: It is faster, than the solution we were discussing, but be careful about data types and mappings, when you use it. (I had an issue with BigInts)

Here is the library and documentation: https://github.com/awslabs/amazon-neptune-tools/tree/master/neptune-python-utils

Yury Lvov
  • 21
  • 2