UKR
UKR

Reputation: 173

type casting in gremlin query

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

Upvotes: 2

Views: 5130

Answers (3)

Jose Moreno
Jose Moreno

Reputation: 71

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?

Upvotes: 0

UKR
UKR

Reputation: 173

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.

Upvotes: 5

Kelvin Lawrence
Kelvin Lawrence

Reputation: 14371

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

Upvotes: 2

Related Questions