Search code examples
gremlinjanusgraphgremlinpython

How to add properties with a specific type into gremlinpython?


Currently i am trying to import via gremlinpython a large graph from igraph programmatically . I am rather new to gremlin and the endpoints i may use it with. The problem i currently face is that a property in a node/edge can have multiple types. (E.g.: -> Bool or None-type | Int, Long, etc..)

I've noticed no error when importing it into this gremlin-server (is this called Apache TinkerGraph-Server? How should i call this?). It seems that the types of same properties can be arbitrary.

However, when using JanusGraph i receive multiple errors: gremlin_python.driver.protocol.GremlinServerError: 500: Value [XXX] is not an instance of the expected data type for property key [YYY] and cannot be converted. Expected: class <SomeClass>, found: class <SomeOtherClass>

E.g. executing:

conn = DriverRemoteConnection("ws://localhost:8182/gremlin", "g")
remote_graph = traversal().withRemote(conn)

remote_graph.addV().property("test", 10000).next()
remote_graph.addV().property("test", 100000000000000000000000).next()  # <- Causes an error on JanusGraph

It is possible for me to cast some properties into other datatypes (Bool/None-Type-> -1,0,1), so i can avoid this error. But i am not sure how i should handle the above provided example. Is there a way to explicitly set the type (for at least numeric types) of a property, so that the server knows to store it e.g. as a Long/BigInt instead of as a Int? Especially since in python3 there is no distincion between long(/bigint) and int anymore.

So specifically is there something like the following?: E.g. executing:


remote_graph.addV().property("test", 10000).asLong().next()
remote_graph.addV().property("test", 10000, <Type: Long>).next()

Solution

  • Gremlin does have a special class for ensuring a Java Long. You can just do long(10000) given the appropriate import like: from gremlin_python.statics import long