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!Solution:Jump to solution
I'm not sure what's wrong there, but I'll point out a few things. I recast your query as though written against the modern graph which makes it easy to test. I used 3.7.3:
```
gremlin> g.V().as('a').both().as('b').
......1> and(select('a').values('age').as('left').
......2> select('b').values('age').as('right')....
2 Replies
Solution
I'm not sure what's wrong there, but I'll point out a few things. I recast your query as though written against the modern graph which makes it easy to test. I used 3.7.3:
i don't seem to get an error like you do. so that's noteworthy. what version are you using?
next, i do note that you're query is a bit complex and not as Gremlin idiomatic as it could be. I think your query would be better written structurally as:
or for your specific traversal:
I'd be curious if that works in your case. As for the specific traversal you supplied, I guess I would see what happens if you remove the
PartitionStrategy
to see if it allows the query to run. If it works without that error, it doesn't mean that the PartitionStrategy
isn't associated with the anonymous traversal, but it does mean that the strategy is likely injecting something into query that is somehow fooling with the as()
labelling to prevent the where()
from finding it.Thank you, the second query you sent worked great! I'm not sure whether it had to do with the partition strategy causing the where to not find the alias.