Gremlin comparison between one node's own properties

I'm trying to have a query that will compare one node's properties without necessarily having to assign an alias to the node and was wondering whether this is possible in gremlin? As an example, I'd like to something like: g.V().hasLabel("person").where(__.values("age"), lt(__.values("dayofBirth"))) or g.V().hasLabel("person").where(__.values("name"), neq(__.values("birthdayMonth"))) , but this doesn't seem to work in gremlin. I know that something like this works instead: g.V().hasLabel("person").as("v").where(lt("v")).by("age").by("dayofBirth") , but it assigns an alias to the node before comparison. Is it necessary to assign an alias to a node in order to compare its own properties in gremlin? As an extension to this question, my goal would be to have a way to compare one node's properties in gremlin without having to assign an alias on that node, and also be able to do a comparison on different nodes with only one alias assigned to the node that is not directly adjacent to this query (something like this): g.V().hasLabel("person").as("a") .outE("isFriendsWith").inV() .hasLabel("dog") .filter(__.values("age").where(neq(__.select("a").values("age")))) but this doesn't seem to work in gremlin either. Do both aliases always have to be assigned to do a comparison on two different nodes and their properties?
6 Replies
Andrea
Andrea2mo ago
Looking through code examples and documentation I can't seem to find examples of same node property comparison without the usage of alias. Just curious why usage of alias is looking to be avoided in your scenario?
Andrea
Andrea2mo ago
Did you obtain your alias workaround by referencing this stack overflow ? Unfortunately it is still the case that predicates still cannot take traversals.
Stack Overflow
Gremlin comparing two properties of a single node
Given below mentioned dataset, how do I check TotalPay of the employee where totalPay is variablePay + FixedPay What percentage variable pay is to TotalPay If totalPay is less than 100,000 g.addV('
marti.sant
marti.santOP2mo ago
Yep! I was looking for alternatives because I was hoping to simplify some of the querying I do that involves comparisons between node properties for a personal project. I could only really find that stack overflow post and wasn't sure if there's an alternative that doesn't include aliasing.
Andrea
Andrea2mo ago
Unfortunately not for now
marti.sant
marti.santOP2mo ago
I see, thanks for the help!
spmallette
spmallette2mo ago
it's been a fairly long standing ask to allow that kind of syntax. while it looks simple to sort of just add it in there, it's actually relatively complicated. Hopefully, a solution with present itself in 4.x.

Did you find this page helpful?