- Newest
- Most votes
- Most comments
You can try removing the g from your individual clause queries. As of TinkerPop 3.5.0, you cannot use a GraphTraversalSource object in a child traversal within a query. Since you're just using strings, you should build your child traversals starting with V().
However, I don't really think what you're doing here is going to perform very well in Neptune. I just tried doing something similar on a 1.4.5.0 cluster and the query was non-optimal.
Instead, you could try doing something like:
g.V().has('{NEPTUNE_PARTITION_KEY}',within({ts1},{ts2},...{tsn})).
group().by('{NEPTUNE_PARTITION_KEY}').
unfold().
select(values).local(unfold().limit(1))
This would work so long as the number of items returned for each timestamp is small. Roughly how many vertices do you have per timestamp?
answered a year ago
Thank you for sharing your code and the issue you're experiencing. I can suggest a few adjustments to improve your batch query approach for Neptune using the Gremlin client.
First, it's important to note that Neptune uses a different query processing engine than standard TinkerPop implementations. As a result, some Groovy-style scripting features are not supported. Your current approach of building a complex script with multiple clauses might be causing the issue.
Instead, I recommend using the Gremlin Language Variant (GLV) client to create a batch programmatically. Here's an adjusted version of your code that should work better:
def get_node_batch_by_timestamps(iso_timestamps): gremlinClient = get_gremlin_client() try: g = gremlinClient.traversal() traversal = g.V() for ts in iso_timestamps: traversal = traversal.union( __.has(NEPTUNE_PARTITION_KEY, ts).limit(1) ) response = traversal.toList() print(f"batch query response: {response}") return response finally: gremlinClient.close()
This approach builds a single traversal using the GLV, which is more efficient and less prone to errors. It uses the union step to combine multiple sub-traversals, each looking for a vertex with a specific timestamp and limiting the result to one vertex per timestamp.
A few key points about this approach:
- It creates a single traversal object and builds upon it, which is more efficient than sending multiple separate queries.
- It uses the
unionstep to combine multiple sub-traversals, allowing for parallel execution of the queries for each timestamp. - The
toList()method at the end executes the traversal and returns the results.
This method should be more reliable and efficient, especially when dealing with a large number of timestamps. It avoids the need to construct a complex Gremlin script as a string, which can be error-prone and less performant.
Remember to ensure that your get_gremlin_client() function is properly configured to connect to your Neptune cluster. Also, make sure you're using the latest version of the Gremlin client library compatible with your Neptune version to take advantage of the most recent improvements and bug fixes.
If you're still encountering issues after trying this approach, it would be helpful to check the specific error message and Neptune server logs for more detailed information about the exception.
Sources
Creating Efficient Multithreaded Gremlin Writes - Amazon Neptune
Gremlin standards compliance in Amazon Neptune - Amazon Neptune
answered a year ago
Relevant content
asked 2 years ago

Thanks for your answer. At the moment, I have between 1-10 vertices per timestamp. Though I plan to increase this number to the thousands.