marti.sant
ATApache TinkerPop
•Created by marti.sant on 3/11/2025 in #questions
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
ATApache TinkerPop
•Created by marti.sant on 3/5/2025 in #questions
Partition strategy with an anonymous graph traversal and aliasing
I'm trying to query for a path that contains vertices filtered by a query that compares two node's property values. I have applied a partition strategy to my main graph traversal source, and all the vertices/edges I've seeded into my gremlin server contain the partitionKey and value (through the partition strategy). I'm trying to query within this partition, but because I need to use an anonymous graph traversal as part of an And step in my query, I'm not sure if anonymous traversals in Gremlin inherit the partition strategy set by the original graph traversal source. When I try and run this query
g.V().
HasLabel("Person").
As("a").
InE("Owns").
OutV().
HasLabel("Cat").
As("b").
And( gremlingo.T__.Select("b").Values("activity_level").As("left").
Select("a").Values("lazyness_level").As("right").Where("left", gremlingo.P.Gt("right")))
I receive an error stating:
code:244 message:Neither the map, sideEffects, nor path has a left-key: WherePredicateStep(left,lt(right)) attributes:map[exceptions:[org.apache.tinkerpop.gremlin.process.traversal.step.Scoping$KeyNotFoundException]
. This makes me think that maybe the anonymous traversal doesn't inherit the partition strategy associated, does anyone know if this is the case? I'm not sure if this is an issue with anonymous traversals not querying inside the partition or if partition strategies don't support aliasing? Any help would be really appreciated!5 replies