I'm trying to write a Tinkerpop Gremlin query that returns data about each path between a particular root node and all of its leaves. In particular, I'd like to know:
Ideally this data would be grouped by the name of the leaf node, as doing so allows me to paginate the results by leaf node.
I've managed to write a query that works well enough against the tinkerpop/gremlin-server:3.6.5 Docker container (the result is not nearly as succinct as would be ideal, but it was something I could at least work with). My problem is that I'm ultimately writing this query to run against an AWS Neptune instance, and the query does not work when running against Neptune. I'm quite new to Gremlin and was hoping someone might be able to assist me in updating this query so that it works against Neptune (and making the result more succinct would be an awesome added bonus).
The following diagram is a basic example:
In this example, an ideal result would be something similar to:
==> x1: {"leafNode": {result of running elementMap on the leaf node x1}, "paths": [{"edgeCount": 1, "minVal": null}]}The query that I've written is (assuming 4 is the ID of the root node):
g.V(4).repeat(__.inE('member').outV()).until(hasLabel('X')).emit().filter(hasLabel('X')).order().by('name').which yields, for the example diagram above:
==>X1=[{name=X1, leafNode={id=1, label=X, name=X1}, minEVal=null, edgeCount=1}] ==>X2=[{name=X2, leafNode={id=2, label=X, name=X2}, minEVal=20, edgeCount=1}] ==>X3=[{name=X3, leafNode={id=3, label=X, name=X3}, minEVal=16, edgeCount=2}, {name=X3, leafNode={id=3, label=X, name=X3}, minEVal=17, edgeCount=3}]As I mentioned above, this result is a bit repetitive because it duplicates the leaf node details for leaf nodes that have multiple paths between themselves and the root node, but it was workable.
AWS Neptune does not like the last line group().by('name').unfold() and returns the error:
"code":"UnsupportedOperationException","message":"java.util.LinkedHashMap cannot be cast to org.apache.tinkerpop.gremlin.structure.Element"If I don't include the group by line, the result of the query looks like:
==>[name:X1,leafNode:[id:1,label:X,name:X1],minEVal:null,edgeCount:1]which complicates performing pagination.
Setup code to replicate the example graph in Gremlin:
g.addV('X').property(id,1).property('name', 'X1').as('X1').Hello Laura,
Thanks for the detailed question and steps to reproduce. I just have a few follow up questions.
Did you use the same gremlin query to insert the sample data into both the gremlin-server and AWS Neptune db?
How were you querying Neptune? Was it using gremlin-console or one of the drivers such as the python or java driver? Or possibly the Neptune notebook?
I would like to help you troubleshoot this issue and hope to have some capacity next week.
Thanks,
Andrea
From:
'Laura Poss' via Gremlin-users <gremli...@googlegroups.com>
Date: Friday, January 17, 2025 at 10:40 AM
To: Gremlin-users <gremli...@googlegroups.com>
Subject: [TinkerPop] Gremlin Query for Root-to-Leaf Paths Fails in AWS Neptune: How to Fix Grouping Issue?
I'm trying to write a Tinkerpop Gremlin query that returns data about each path between a particular root node and all of its leaves. In particular, I'd like to know:
· details about the leaf node
· the minimum value of an edge property across all edges in the path between leaf node and root (if there is no such value along a path, report null)
· how many edges are in the path
Ideally this data would be grouped by the name of the leaf node, as doing so allows me to paginate the results by leaf node.
I've managed to write a query that works well enough against the tinkerpop/gremlin-server:3.6.5 Docker container (the result is not nearly as succinct as would be ideal, but it was something I could at least work with). My problem is that I'm ultimately writing this query to run against an AWS Neptune instance, and the query does not work when running against Neptune. I'm quite new to Gremlin and was hoping someone might be able to assist me in updating this query so that it works against Neptune (and making the result more succinct would be an awesome added bonus).
The following diagram is a basic example:
--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
gremlin-user...@googlegroups.com.
To view this discussion visit
https://groups.google.com/d/msgid/gremlin-users/7ab486fb-c348-43c2-965f-58401efe1fd1n%40googlegroups.com.
Good to hear you received a potential solution from AWS. Hope it works out!
To view this discussion visit https://groups.google.com/d/msgid/gremlin-users/8a91c277-b32e-4e31-a002-78ba89aeea62n%40googlegroups.com.