Setting cardinality in gremlin-python

1,260 views
Skip to first unread message

Tharidu Fernando

unread,
May 28, 2017, 3:24:35 AM5/28/17
to Gremlin-users
Hi all,

I'm trying to set a list vertex property using Cardinality.

This is possible in gremlin console using,
v.property(list, 'name', 'm. a. rodriguez')
v.property(list, 'name', 'marko')

I cannot figure out how to do this using gremling-python library. Any help will be appreciated!

Thanks

David Brown

unread,
May 28, 2017, 11:44:43 AM5/28/17
to Gremlin-users
Hi Tharidu,

Here is an example interpreter session:

[1]: from gremlin_python.structure import graph

[2]: from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

[3]: from gremlin_python.process.traversal import Cardinality

[4]: driver = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')

[5]: g = graph.Graph().traversal().withRemote(driver)

[6]: g.addV('person').property(Cardinality.list_, 'name', 'm. a. rodriguez').property(Cardinality.list_, 'name', 'marko').next()
Out[6]: v[0]

[7]: g.V(0).properties('name').toList()
Out[7]: [vp[name->m. a. rodriguez], vp[name->marko]]

Hope that helps.

Best,

Dave

Tharidu Fernando

unread,
May 29, 2017, 6:31:18 AM5/29/17
to Gremlin-users
Hi Dave,

Thanks for the help. Unfortunately, Gremlin server does not support saving lists as a property in Neo4j implementation (which I'm using), so I have to rethink on a better way of storing it.
But this works for in-memory Tinkerpop graph implementation.

Thank you,
Best regards,
Tharidu

Tharidu Fernando

unread,
May 29, 2017, 7:27:51 AM5/29/17
to Gremlin-users
An update on Neo4j. I've somehow missed that multi-properties should be enabled manually for Neo4j. Reference
After enabling multi-properties, now it's working as intended.

Dirk Reiners

unread,
Feb 26, 2019, 6:38:12 PM2/26/19
to Gremlin-users
Sorry for reviving an old thread, but I'm running into the same problem...

Does this solution still work for anybody? When I try it I get "gremlin_python.driver.protocol.GremlinServerError: 500: Key is defined for SINGLE cardinality which conflicts with specified: list", which is unfortunately the same that I get in my own code...

Is there an alternative to create a property with multiple values in gremlin-python? I tried .property(Cardinality.list_, 'name', 'm. a. rodriguez', 'name', 'marko'), but that doesn't work either.

Any input welcome!

  Dirk

Stephen Mallette

unread,
Feb 27, 2019, 6:49:20 AM2/27/19
to gremli...@googlegroups.com
I'm pretty sure that the error message comes from JanusGraph:


and it's simply related to your schema definition. I think you just need to be sure that the property you are setting is configured to allow for list.


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/28a126bd-9b8a-4d0b-95b2-d27c3171fbbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dirk Reiners

unread,
Feb 27, 2019, 9:30:50 AM2/27/19
to Gremlin-users
Good point, thanks for pointing that out! So far I've only used the automatic schema. 

Now I need to figure out how to do that in a reproducible manner, and why my gremlin shell complains about 'gremlin-groovy is not an available GremlinScriptEngine'. But those are different threads...

Thanks!
Reply all
Reply to author
Forward
0 new messages