1
votes

How to cast String value to Integer type in gremlin console with AWS Neptune GDB. I'm having the property 'age' with the string value, which needs to be converted to Integer type for math operations in the query. all suggestions are appreciated.

I tried below queries suggested by kelvin.But got these exceptions.

    gremlin> g.V(1).values('age').map{(String)it}.next()
    Script336735.groovy: 1: [Static type checking] - Inconvertible types:cannot cast org.apache.tinkerpop.gremlin.process.traversal.Traverser <E2 extends java.lang.Object> to java.lang.String
    gremlin> g.V(1).values('age').map{(Integer)it}.next()
    Script336963.groovy: 1: [Static type checking] - Inconvertible types: cannot cast org.apache.tinkerpop.gremlin.process.traversal.Traverser <E2 extends java.lang.Object> to java.lang.Integer

My requirement is to cast String value to Integer/long

3

3 Answers

3
votes

Thanks Kelvin. Finally, This query works with AWS-Neptune GraphDB.

gremlin> g.V(1).values('age').map{(''+it).toInteger()}
==>25

instead of toInteger(), we can use some other java methods similar to that.

2
votes

I am curious why you are storing an age as a String to start with, but that said, if you are able to use a Lambda, you can do a cast inside of a map step. Here is an example from my air-routes graph (runways is an integer type):

gremlin> g.V(3).values('runways').map {(String)it}.next().class
==>class java.lang.String

Cheers Kelvin

0
votes

According to https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html#w3aac12c22c10c15c47

Neptune does not support Lambda Steps.

If I try the queries above I get:

Failed to interpret Gremlin query: Query parsing failed...

Is this something that was supported in the past?