Reputation: 21
On gremlin version 3.4.0 with step is
, the predicates are not working as expected.
if I do the following it is returning me true
gremlin>3.is(3)
==>true
gremlin>[3].getAt(0).is(3)
==>true
While the same comparisons with using predicates are not working and returns false
gremlin>3.is(eq(3))
==>false
gremlin>[3].getAt(0).is(eq(3))
==>false
Precisely I want to check the length of the node property value and validate based on a max length.
gremlin>g.V(0).values('name').next().length().is(lte(20))
==>false
The above code always return false is the name is equal to test_name
(with length 9). While if I do direct comparison (like shown below) it returns true
gremlin>g.V(0).values('name').next().length().is(9)
==>true
What am I doing wrong here?
Upvotes: 0
Views: 198
Reputation: 46216
You are mixing Groovy and Gremlin. When you do this:
gremlin>3.is(3)
==>true
gremlin>[3].getAt(0).is(3)
==>true
you are not using Gremlin and that is therefore not the is()
step. In that case you are doing a reference equality check using Groovy's is()
method. That further explains your results as you go further down in your question as in:
gremlin>g.V(0).values('name').next().length().is(lte(20))
==>false
because as soon as you do next()
you are no longer doing Gremlin. Nothing following that represent Gremlin steps, it's just Groovy code. You are calling the String.length()
method and then the Groovy is()
operator and comparing the int
returned from length()
to lte(20)
which is an instance of P
thus:
gremlin> "xyz".length().is(lte(20))
==>false
If you want to use Gremlin to check the length of a string then I'm not sure that there is a way to do so outside of using a lambda:
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().values('name').filter{it.get().length()<=4}
==>lop
==>josh
Upvotes: 1