Search code examples
databasegroovygraphgremlin

Gremlin ignoring store value


I am new to gremlin and trying out a query but as I observe store value is always ignored

I have tried store, aggregate and as as well but all are giving me false values.

g.V().has('__typeName','avro_schema').where(local(out('__avro_record.fields').as('xm').local(out('classifiedAs').has('__typeName', 'DataClassification').count().is(eq(1))).count().is(eq(select('xm').size()))))

this gives size of 'xm' as always 0

I expect the value of size 'xm' to be equal to the number of outgoing edges from each avro_schema with the edge label as '__avro_record.fields'

As pointed,changed the query to :

g.V().has('__typeName','avro_schema').where(local(out('__avro_record.fields').local(out('classifiedAs').has('__typeName', 'DataClassification').count().is(eq(1))).count().is(count(local))))

Now getting empty results.

Edit :

Also I have doubts related to printing of dynamic values as sideEffect

g.V().has('__typeName','avro_schema').where(local(out('__avro_record.fields').local(out('classifiedAs').has('__typeName', 'DataClassification').count().is(eq(1))).count().sideEffect{ println count(local) }.is(count(local))))

Output:

[CountLocalStep]

Where as I expect the actual value of count(local).What is the best practice to debug gremlin query?


Solution

  • There are a few things that won't work in your traversal. First, .size() is not a Gremlin step, you're probably looking for .count(local). Next, eq() does not take dynamic values, it only works with constant values. Read the docs for where() step to learn how to compare against dynamic values.

    UPDATE

    To compare the two count() values you would do something like this:

    g.V().has('__typeName','avro_schema').filter(
        out('__avro_record.fields').fold().as('x').
        map(unfold().
            out('classifiedAs').has('__typeName', 'DataClassification').fold()).as('y').
        where('x', eq('y')).
          by(count(local)))