Search code examples
gremlinamazon-neptune

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


Solution

  • 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.