Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tinkerpop & Python - Setting an array property via gremlin

I'm using JanusGraph with the standard python gremlin binding, and I'd like to set a float[] property on a vertex/edge. However, the Tinkerpop driver for Python doesn't seem able to do so.

For example, here is an example with a script running directly in Groovy:

val = [1.2, 3.4, 5.6]
_client.submit("g.V(4200).property('a', %s as float[])" % val).all().result()

And here is the code that fails when using the gremlin python library:

val = [1.2, 3.4, 5.6]
g.V(4200).property('a', val).next()

Where the error is:

GremlinServerError: 500: Property value [[1.2, 3.4, 5.6]] is of type class java.util.ArrayList is not supported

The error is probably since requests are serialized in GraphSON by the python driver - and GraphSON supports arrays with elements of varying types, thus the Java code behind the scene reads the value as a java.util.ArrayList which indeed cannot be cast to float[].

The question is - is there any sane way to do this, other than writing explicit query strings?

like image 432
Barak Itkin Avatar asked Nov 07 '22 23:11

Barak Itkin


1 Answers

This issue has been discussed a few times and JanusGraph is not the only graph database to have type coercion issues. From TinkerPop's perspective, graphs should either (1) attempt to coerce TinkerPop types to the appropriate type defined in the graph schema or otherwise accepted by the graph or (2) provide additional serialization or other library support to allow for those types to be exposed to their users.

As far as I know, there is no workaround for this other than to use scripts as you have already discovered. Note that JanusGraph already has an open issue for resolving this problem.

like image 64
stephen mallette Avatar answered Nov 15 '22 04:11

stephen mallette