Help with a gremlin query..

Hi folks,

I have a graph where:

Customer vertices connect to Order vertices via hasOrder edges.

Each Customer has a customerId

Each Order has:
• orderId
• orderDate

Rules for output:

•I will pass multiple customer IDs as input.

•For each customer, fetch their orders.

•A customer may have multiple entries for the same orderId. In that case:
Keep only the one with the latest orderDate.

The selection of orders for one customer must not interfere with another customer’s selection — even if they share the same orderId.

I cannot use group() or any other grouping/aggregation step — only order(), limit(), dedup(), etc.

Example scenario:

customerId | orderId | orderDate
C1 | O1 | 2024-01-01
C1 | O1 | 2024-01-02
C1 | O2 | 2024-01-03
C2 | O1 | 2024-01-01
C2 | O1 | 2024-01-02
C2 | O3 | 2024-01-04
C3 | O4 | 2024-01-02


Expected output:


{c=C1, o={orderId=[O1], orderDate=[2024-01-02]}}
{c=C1, o={orderId=[O2], orderDate=[2024-01-03]}}
{c=C2, o={orderId=[O1], orderDate=[2024-01-02]}}
{c=C2, o={orderId=[O3], orderDate=[2024-01-04]}}
{c=C3, o={orderId=[O4], orderDate=[2024-01-02]}}


Need help: How can I write a Gremlin query that achieves this with only order(), limit(), and dedup(), without using group() or similar, while ensuring that each customer is processed independently?

QUERY TO SAMPLE DATA IN CHATS..
Was this page helpful?