Search code examples
gremlin

How to rename groupBy labels in Gremlin query?


gremlin> g.V().has('KType', 'ec2.Subnet').groupCount().by('DefaultForAz')
2==>{false=4, true=14}

I need to rename the group by tags, and bring in something logical instead. In this case, it would be replacing true with 'AWS Created' and false with 'Customer Created' tags. Below is the query that I've written and I'm pasting the error stack with it because there aren't many resources available online that help me in debugging it.

gremlin> g.V().has('KType', 'ec2.Subnet').group().by(values('DefaultForAz')).coalesce(is(regex('true')).constant('AWS created'),is(regex('false')).constant('Customer created')).by(count())

No signature of method: org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.regex() is applicable for argument types: (String) values: [true] Possible solutions: reset(), get(java.lang.String), eval(java.lang.String), getAt(java.lang.String), every(), grep()


Solution

  • You can do it like this:

    g.V().groupCount().by('p')
    ==>[false:2,true:3]
    
    g.V().groupCount().by('p').select(values).
       project('key-false', 'key-true').
       by(unfold().limit(1)).
       by(unfold().tail())
    ==>[key-false:2,key-true:3]